protected int MoveObjects(Map map, Player[] players, List<Enemy> enemies) { int score = 0; foreach (Weapon weapon in weapons) { weapon.Update(); } Vector2 collisionCheck = new Vector2(-1, -1); //check if vessel has hit any bounding tiles Tile[,] tileSet = map.GetSurroundingTiles(map.SpriteOverTile(this), GetBoundaryCheck(map.tileSize)+1); for(int x=0; x<tileSet.GetLength(0); x++) { for (int y = 0; y < tileSet.GetLength(1); y++) { if (tileSet[x, y] != null) { Tile tile = tileSet[x, y]; //had the vessel hit the collidable tile? if (BoundingCollision(tile)) { ResolveBounding(tile); //bounce off tile acceleration = ReflectVector((acceleration)); setEnergy(tile); CheckEnergy(explosionCount); score += tile.CheckEnergy(); //If you've died on a tile then stop the movement if (currentEnergy == 0) acceleration = 0.0f; if (this.GetType().Name.Equals("Player")) rumbleTimer = 40; } } } } //If type is player then //check if vessel has hit any alive enemies if (this.GetType().Name.Equals("Player")) { foreach (Enemy enemy in enemies) { if (BoundingCollision(enemy)) { if (TextureCollision(enemy)) { rumbleTimer = 20; setEnergy(enemy); CheckEnergy(); score += enemy.CheckEnergy(); //check to see if the collision has any effects on the player, like powerup enemy.CollisionEffects(this); } } } } UpdatePosition(); return score; }
public int Update(Map map, Player[] players, List<Enemy> enemies) { List<Projectile> deleted = new List<Projectile>(); int score = 0; //loop through projectiles but then i need to access the checkcollision routine, how?! //calculate the current vector of the projectile foreach (Projectile projectile in liveProjectiles) { if (projectile.alive) { Vessel orignalFirer = (Vessel)projectile.originiator; //Check to see if the projectile has hit any bounding tiles Tile[,] tileSet = map.GetSurroundingTiles(map.SpriteOverTile(projectile), 2); //check each tile in set to see if it has collided Vector2 resetPoint = new Vector2(-1,-1); for (int x = 0; x < tileSet.GetLength(0); x++) { for (int y = 0; y < tileSet.GetLength(1); y++) { if (tileSet[x, y] != null) { Tile tile = tileSet[x, y]; if (tile.collidable && projectile.BoundingCollision(tile)) { projectile.lastSideCollided = FindLastSideTouched(map, projectile, tile.coordinates, -1, ref resetPoint); if (projectile.lastSideCollided > -1) { orignalFirer.score += CheckProjectileCollisions(tile, projectile); if (projectile.collided) { projectile.collided = false; break; } } } } } } if(resetPoint.X>-1) { projectile.position = resetPoint - projectile.velocity; projectile.safePosition = resetPoint - projectile.velocity; } //Check to see if the projectile has hit any enemies //Only check enemy hit if the projectile has come from a player if (projectile.originiator.GetType().Name.Equals("Player")) { //check projectiles for hitting enemies foreach (Enemy enemy in enemies) { orignalFirer.score += CheckProjectileCollisions(enemy, projectile); } } //Check to see if the projectile has hit any players foreach (Player player in players) { //can players shoot each other? // if no then use ! projectile.originiator.GetType().Name.Equals("Player") // if yes then use player != orignalFirer if (! projectile.originiator.GetType().Name.Equals("Player")) { int checkScore = CheckProjectileCollisions(player, projectile); orignalFirer.score += checkScore; } } //expand draw area to check to see if enemy has left area map.drawArea.Inflate(map.tileSize.X, map.tileSize.Y); if (!map.drawArea.Contains(projectile.GetBounds())) projectile.alive = false; //return map to original size map.drawArea.Inflate(-map.tileSize.X, -map.tileSize.Y); projectile.CalculateNextVector(); projectile.UpdatePosition(); } if (!projectile.alive) deleted.Add(projectile); } //remove dead projectiles foreach (Projectile projectile in deleted) liveProjectiles.Remove(projectile); return score; }