public void ExplodeBomb(DynBomb b) { int power = b.explosionSize; int[] Erange = { 0, 0, 0, 0 }; // explosion range in each direction : //up,down,left,right bool[] Dir = { false, false, false, false }; // already hit wall in each direction Vector2 center = DynUtils.GetTileCoords(b.position); SetTile((int)center.X, (int)center.Y, TileType.EMPTY); for (int k = 1; k <= power; ++k) { Vector2[] vectors = { new Vector2(center.X, center.Y-k), new Vector2(center.X, center.Y + k), new Vector2(center.X - k, center.Y), new Vector2(center.X + k, center.Y) }; int index = 0; foreach (Vector2 v in vectors) { if (!Dir[index] && v.X >= 0 && v.Y >= 0 && v.X <= sizeX - 1 && v.Y <= sizeY - 1) { if (Tiles[(int)v.X, (int)v.Y] == TileType.EMPTY) Erange[index]++; else { Dir[index] = true; if (Tiles[(int)v.X, (int)v.Y] != TileType.IMMOVABLE) { DynCAnimation wallExplosion = new DynCAnimation(); int frameTime = (DynUtils.explosionTime) / 7; wallExplosion.Initialize(wallExplosionTexture, new Vector2(v.X * 16 + 8, v.Y * 16 + 8), 16, 16, 7, frameTime, false); wallExplosionList.Add(wallExplosion); Erange[index]++; } } } index++; } } DynExplosion explosion = new DynExplosion(); explosion.Initialize(b.position, Erange[0], Erange[1], Erange[2], Erange[3], explosionTexture, b.explosionTexture); explosionList.Add(explosion); }
public void Update(GameTime gameTime, KeyboardState prevKState, KeyboardState curKState) { //Updating bombs int j = bombs.Count; for (int i = 0; i < j; ++i) { DynBomb b = bombs[i]; b.Update(gameTime); if (!b.active) { players[b.OwnerId].bombsLeft += 1; bombs.RemoveAt(i); --j; --i; } if (b.running) { board.ExplodeBomb(b); b.running = false; } } //Updating players foreach (DynPlayer p in players) { if (p.alive) p.Move(curKState, board.CollisionList, bombs); p.Update(gameTime); Vector2 coords = DynUtils.GetTileCoords(p.position); //Placing bomb if (p.alive && curKState.IsKeyDown(p.playerKeys.KeyBomb) && (board.GetTile((int)coords.X, (int)coords.Y) != DynBoard.TileType.BOMB)) { if (p.bombsLeft > 0) { DynBomb bomb = new DynBomb(); bomb.Initialize(p.playerID, p.bombPower, DynUtils.GetTileCenter(p.position), bombTexture, bombExplosionTexture); bombs.Add(bomb); board.SetTile((int)coords.X, (int)coords.Y, DynBoard.TileType.BOMB); --p.bombsLeft; } } } foreach (DynMonster m in monsters) { if (m.alive) m.Move(board.CollisionList); m.Update(gameTime); } //Collisions checks //player <-> () foreach (DynPlayer p in players) { foreach (DynExplosion d in board.explosionList) //Player <-> Bomb if (d.Collides(p)) { bool is_wall = false; foreach (DynCAnimation we in board.wallExplosionList) if (p.Collides(we)) is_wall = true; if (!is_wall) p.OnCollision(DynUtils.ObjectType.Explosion); } foreach (DynMonster m in monsters) // Player <-> Monster if (m.alive && m.animation.CollisionRect().Intersects(p.CollisionRect())) p.OnCollision(DynUtils.ObjectType.Explosion); foreach (DynBonus b in board.bonuses) //Player <-> Bonus if (b.Collides(p) && b.active) { p.OnCollision(b.type); b.OnCollision(DynUtils.ObjectType.Player); } } foreach (DynMonster m1 in monsters) foreach (DynMonster m2 in monsters) if (m1.monsterID != m2.monsterID && m1.Collides(m2)) { m1.OnCollision(DynUtils.ObjectType.Monster); m2.OnCollision(DynUtils.ObjectType.Monster); } //explosion <-> () foreach (DynExplosion e in board.explosionList) { foreach (DynBomb b in bombs) if (e.Collides(b)) b.OnCollision(DynUtils.ObjectType.Explosion); foreach (DynMonster m in monsters) if (e.Collides(m)) m.OnCollision(DynUtils.ObjectType.Explosion); foreach (DynBonus b in board.bonuses) if (e.Collides(b)) b.OnCollision(DynUtils.ObjectType.Explosion); } board.Update(gameTime); }