home *** CD-ROM | disk | FTP | other *** search
- class CheckPointGeneratorTargetTracker
- {
- var mcCheckPoint;
- var player;
- var playField;
- var checkPointPos;
- var humanPlayer;
- var DECAL = 25;
- var PRECISION = 10;
- function CheckPointGeneratorTargetTracker(mcCheckPoint, playField, player)
- {
- this.mcCheckPoint = mcCheckPoint;
- this.player = player;
- this.playField = playField;
- this.checkPointPos = new Point2D(-1,-1);
- this.moveCheckPointRandom();
- }
- function setHumanPlayer(humanPlayer)
- {
- this.humanPlayer = humanPlayer;
- }
- 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 moveCheckPointRandom()
- {
- this.generatePosition();
- this.mcCheckPoint._x = this.checkPointPos.getX();
- this.mcCheckPoint._y = this.checkPointPos.getY();
- }
- function moveCheckPointAt(x, y)
- {
- this.checkPointPos.setX(x);
- this.checkPointPos.setY(y);
- this.mcCheckPoint._x = x;
- this.mcCheckPoint._y = y;
- }
- function manage()
- {
- var _loc2_ = Math.floor(this.player.getX());
- var _loc3_ = Math.floor(this.player.getY());
- if(_loc2_ >= this.mcCheckPoint._x - this.PRECISION && _loc2_ <= this.mcCheckPoint._x + this.PRECISION)
- {
- if(_loc3_ >= this.mcCheckPoint._y - this.PRECISION && _loc3_ <= this.mcCheckPoint._y + this.PRECISION)
- {
- this.moveCheckPointRandom();
- return true;
- }
- }
- return false;
- }
- function manageWithHumanPlayer()
- {
- if(this.humanPlayer == undefined)
- {
- trace("CheckPointGeneratorTargetTracker - Human Player not initialized !");
- return false;
- }
- var _loc2_ = new Vector2D(new Point2D(this.player.getX(),this.player.getY()),new Point2D(this.humanPlayer.getX(),this.humanPlayer.getY()));
- if(_loc2_.getNorme() > 150)
- {
- this.moveCheckPointAt(this.humanPlayer.getX(),this.humanPlayer.getY());
- return true;
- }
- if(this.manage() == true)
- {
- return true;
- }
- return false;
- }
- }
-