home *** CD-ROM | disk | FTP | other *** search
- class CheckPointGenerator
- {
- var mc;
- var player;
- var playField;
- var checkPointPos;
- var DECAL = 25;
- var PRECISION = 10;
- function CheckPointGenerator(mc, playField, player)
- {
- this.mc = mc;
- this.player = player;
- this.playField = playField;
- this.checkPointPos = new Point2D(-1,-1);
- this.moveCheckPoint();
- }
- function generatePosition()
- {
- var _loc3_ = random(this.playField.getMaxX());
- var _loc2_ = random(this.playField.getMaxY());
- if(_loc3_ <= this.playField.getMinX())
- {
- _loc3_ = this.playField.getMinX() + this.DECAL;
- }
- if(_loc3_ >= this.playField.getMaxX())
- {
- _loc3_ = this.playField.getMaxX() - this.DECAL;
- }
- if(_loc2_ <= this.playField.getMinY())
- {
- _loc2_ = this.playField.getMinY() + this.DECAL;
- }
- if(_loc2_ >= this.playField.getMaxY())
- {
- _loc2_ = this.playField.getMaxY() - this.DECAL;
- }
- this.checkPointPos.setX(_loc3_);
- this.checkPointPos.setY(_loc2_);
- }
- function moveCheckPoint()
- {
- this.generatePosition();
- this.mc._x = this.checkPointPos.getX();
- this.mc._y = this.checkPointPos.getY();
- }
- function manage()
- {
- var _loc2_ = Math.floor(this.player.getX());
- var _loc3_ = Math.floor(this.player.getY());
- if(_loc2_ >= this.mc._x - this.PRECISION && _loc2_ <= this.mc._x + this.PRECISION)
- {
- if(_loc3_ >= this.mc._y - this.PRECISION && _loc3_ <= this.mc._y + this.PRECISION)
- {
- this.moveCheckPoint();
- return true;
- }
- }
- return false;
- }
- function trace()
- {
- trace("CheckPointGenerator - MC : " + this.mc);
- trace("CheckPointGenerator - checkPointPos : ");
- this.checkPointPos.trace();
- }
- }
-