public override bool Shoot(PointF playerLocation, BattleField form) { if (IsDead == false) { form.AddProjectile(new Projectile(Location, playerLocation, _projectileSpeed)); //return true after creating return(true); } //ai lost, cannot shoot projectile else { //return false return(false); } }
public void Explode(BattleField world) { //check tiles in a nine block radius //TTT T - Tile, M - Mine //TMT //TTT int col = (int)Math.Round(Location.X / world.TileSize.Height); int row = (int)Math.Round(Location.Y / world.TileSize.Width); col -= 1; row -= 1; //loop through maptile radius for (int j = row; j < row + 3; j++) { for (int i = col; i < col + 3; i++) { //check if theres a tile that can be destroyed if (world.BattlefieldMap[i, j] == MapTile.DestructableWall) { world.BattlefieldMap[i, j] = MapTile.Blank; } //Round player and enemy x and y to match maptile int pCol = (int)Math.Round(world.Player.Location.X / world.TileSize.Width); int pRow = (int)Math.Round(world.Player.Location.Y / world.TileSize.Height); //Loop through enemies, check if they're in the vicinity of the mine //if so blow them up and set their isDead variable to true for (int k = 0; k < world.AiTank.Count(); k++) { //the Col and Row of the grid int eCol = (int)(world.AiTank[k].Location.X / world.TileSize.Width); int eRow = (int)(world.AiTank[k].Location.Y / world.TileSize.Height); //check if enemy is radius if (eCol == i && eRow == j) { world.AiTank[k].IsDead = true; } } //check for enemy or player in radius if (pCol == i && pRow == j) { world.Player.IsDead = true; } } } }
private void Setup() { //Create battlefield map and the player and enemies //loop through all possible enemies and create them battlefield = new BattleField(_startLevel); player = battlefield.Player; enemies = new AITanks[battlefield.AiTank.Count]; for (int i = 0; i < battlefield.AiTank.Count; i++) { enemies[i] = battlefield.AiTank[i]; } //enable the timer to start game tmrGameTimer.Enabled = true; //Brush colour = new Brush(cboColour.ToString()); //cboColour }
/// <summary> /// Move Enemy /// </summary> /// <param name="playerLocation"></param> /// <param name="world"></param> /// <returns></returns> public virtual bool Move(PointF playerLocation, BattleField world) { //Random variable, if tank cannot move because of obstacle, use a random direction to get the tank moving Random rngDirection = new Random(); //Use Rotate Subprogram before Move, since it is assumed that enemy //faces the player before moving in that direction //Check if enemy is dead //If so enemy cannot move if (_isDead == false) { int tileX, tileY = 0; //tile size is tilesize + 5 because tank is 5 units smaller than tile int tileSize = world.TileSize.Height + 5; //If playerLocation.X is less than enemy's X Location (player is left of enemy) if (playerLocation.X < this.Location.X) { //get the x and y tile to check battlefield maptile array //subtract tilesize to check tile left of ai tileX = (int)((this.Location.X - tileSize) / world.TileSize.Width); tileY = (int)(this.Location.Y / world.TileSize.Height); //check tile to see if ai can move if (world.BattlefieldMap[tileX, tileY] == MapTile.Border || world.BattlefieldMap[tileX, tileY] == MapTile.Wall || world.BattlefieldMap[tileX, tileY] == MapTile.DestructableWall) { PointF direction = new PointF(rngDirection.Next(0, Form.ActiveForm.Size.Width), rngDirection.Next(0, Form.ActiveForm.Size.Height)); return(Move(direction, world)); } //if ai can move safely, move to next tile else { Location = new PointF(Location.X - AI_SPEED, Location.Y); //Set hitbox _botHitbox = new RectangleF(_botLocation, _aiSize); return(true); } } //If playerLocation.X is more than enemy's X Location (player is right of enemy) else if (playerLocation.X > this.Location.X) { //get the x and y tile to check battlefield maptile array //add tilesize to check tile right of ai tileX = (int)((this.Location.X + tileSize) / world.TileSize.Height); tileY = (int)(this.Location.Y / world.TileSize.Height); //check tile to see if ai can move if (world.BattlefieldMap[tileX, tileY] == MapTile.Border || world.BattlefieldMap[tileX, tileY] == MapTile.Wall || world.BattlefieldMap[tileX, tileY] == MapTile.DestructableWall) { PointF direction = new PointF(rngDirection.Next(0, Form.ActiveForm.Size.Width), rngDirection.Next(0, Form.ActiveForm.Size.Height)); return(Move(direction, world)); } //if ai can move safely, move to next tile else { Location = new PointF(Location.X + AI_SPEED, Location.Y); //Set hitbox _botHitbox = new RectangleF(_botLocation, _aiSize); return(true); } } //If playerLocation.Y is less than enemy's Y Location (player is above enemy) else if (playerLocation.Y < this.Location.Y) { //get the x and y tile to check battlefield maptile array //subtract tilesize to check tile on top of ai tileX = (int)(this.Location.X / world.TileSize.Width); tileY = (int)((this.Location.Y - tileSize) / world.TileSize.Height); //check tile to see if ai can move if (world.BattlefieldMap[tileX, tileY] == MapTile.Border || world.BattlefieldMap[tileX, tileY] == MapTile.Wall || world.BattlefieldMap[tileX, tileY] == MapTile.DestructableWall) { PointF direction = new PointF(rngDirection.Next(0, Form.ActiveForm.Size.Width), rngDirection.Next(0, Form.ActiveForm.Size.Height)); return(Move(direction, world)); } //if ai can move safely, move to next tile else { Location = new PointF(Location.X, Location.Y - AI_SPEED); //Set hitbox _botHitbox = new RectangleF(_botLocation, _aiSize); return(true); } } //If playerLocation.Y is more than enemy's Y Location (player is below enemy) else if (playerLocation.Y > this.Location.Y) { //get the x and y tile to check battlefield maptile array //add tilesize to check tile below of ai tileX = (int)(this.Location.X / world.TileSize.Width); tileY = (int)((this.Location.Y + tileSize) / world.TileSize.Height); //check tile to see if ai can move if (world.BattlefieldMap[tileX, tileY] == MapTile.Border || world.BattlefieldMap[tileX, tileY] == MapTile.Wall || world.BattlefieldMap[tileX, tileY] == MapTile.DestructableWall) { PointF direction = new PointF(rngDirection.Next(0, Form.ActiveForm.Size.Width), rngDirection.Next(0, Form.ActiveForm.Size.Height)); return(Move(direction, world)); } // if ai can move safely, move to next tile else { Location = new PointF(Location.X, Location.Y + AI_SPEED); //Set hitbox _botHitbox = new RectangleF(_botLocation, _aiSize); return(true); } } else { return(false); } } else { return(false); } }
public override bool Move(PointF playerLocation, BattleField world) { return(false); }