public Enemy(EnemyType type) { Width = 64; Height = 64; ZIndex = 1; switch (type) { case EnemyType.BALLOOM: Sprite = new Sprite(AssetManager.Textures["balloom"], 64, 64, 0, 6); speed = 80; points = 100; wallpass = false; break; } Tile tile; do { tile = LevelManager.CurrentLevel.GetTile(Blackboard.Random.Next(1, 30), Blackboard.Random.Next(1, 12)); } while (tile.Solid); destination = tile; Position = tile.Position; EntityManager.Spawn(this); }
public override void Update() { if (!moving) { lastDestination = destination; var surrounding = new List<Tile>(); Tile tile; // Left if (lastDestination.TileX> 1 && !(tile = LevelManager.CurrentLevel.GetTileRelative(lastDestination, -1, 0)).Solid) surrounding.Add(tile); // Right if (lastDestination.TileX < 29 && !(tile = LevelManager.CurrentLevel.GetTileRelative(lastDestination, 1, 0)).Solid) surrounding.Add(tile); // Up if (lastDestination.TileY > 1 && !(tile = LevelManager.CurrentLevel.GetTileRelative(lastDestination, 0, -1)).Solid) surrounding.Add(tile); // Down if (lastDestination.TileY < 11 && !(tile = LevelManager.CurrentLevel.GetTileRelative(lastDestination, 0, 1)).Solid) surrounding.Add(tile); if (surrounding.Count == 0) return; destination = surrounding[Blackboard.Random.Next(surrounding.Count)]; moving = true; } timer--; Position = destination.Position - ((destination.Position - lastDestination.Position) * ((float)timer / speed)); if (timer < 0) { timer = speed; moving = false; } }
public Level() { tiles = new Tile[13, 31]; for (var i = 0; i < tiles.GetLength(0); i++) { for (var j = 0; j < tiles.GetLength(1); j++) { if (!((i == 1 && j == 1) || (i == 1 && j == 2) || (i == 2 && j == 1)) && template[i, j] == 0 && Blackboard.Random.Next(0, 100) <= density) template[i, j] = 2; tiles[i, j] = new Tile((TileType)template[i, j], j, i); } } enemies = new List<Enemy>(); bombs = new List<Bomb>(); explosions = new List<Explosion>(); //test Blackboard.BombRadius = 4; EventManager.AddListener(GameEvent.BOMB_DETONATED, this); }
public override void Update() { if (keys.Count == 0) { Sprite.Playing = false; } else { Sprite.Playing = true; if (walkSound.State == SoundState.Stopped) walkSound.Play(); var d = 0.2f * Blackboard.Delta; var r = 0.13f * Blackboard.Delta; int roundRange = 24; var tiles = new Tile[2]; tiles[0] = LevelManager.CurrentLevel.GetTileAt(Position); tiles[1] = LevelManager.CurrentLevel.GetTileAt(Position + new Vector2(Width, Height)); if (Position.X == tiles[0].Position.X) tiles[1] = LevelManager.CurrentLevel.GetTileRelative(tiles[1], -1, 0); if (Position.Y == tiles[0].Position.Y) tiles[1] = LevelManager.CurrentLevel.GetTileRelative(tiles[1], 0, -1); switch (keys.Last()) { case Keys.Up: if (!Plint) { Sprite.Index = 1; } Position -= new Vector2(0, d); if (LevelManager.CurrentLevel.GetTileRelative(tiles[0], 0, -1).Solid || LevelManager.CurrentLevel.GetTileRelative(tiles[1], 0, -1).Solid) { Position = new Vector2(Position.X, Math.Max(Position.Y, tiles[0].Position.Y)); if (LevelManager.CurrentLevel.GetTileRelative(tiles[0], 0, -1).Solid && !LevelManager.CurrentLevel.GetTileRelative(tiles[1], 0, -1).Solid && tiles[1].Position.X - Position.X <= roundRange) { Position += new Vector2(r, 0); } else if (!LevelManager.CurrentLevel.GetTileRelative(tiles[0], 0, -1).Solid && LevelManager.CurrentLevel.GetTileRelative(tiles[1], 0, -1).Solid && Position.X - tiles[0].Position.X <= roundRange) { Position -= new Vector2(r, 0); } } break; case Keys.Down: if (!Plint) { Sprite.Index = 0; } Position += new Vector2(0, d); if (LevelManager.CurrentLevel.GetTileRelative(tiles[0], 0, 1).Solid || LevelManager.CurrentLevel.GetTileRelative(tiles[1], 0, 1).Solid) { Position = new Vector2(Position.X, Math.Min(Position.Y, tiles[1].Position.Y)); if (LevelManager.CurrentLevel.GetTileRelative(tiles[0], 0, 1).Solid && !LevelManager.CurrentLevel.GetTileRelative(tiles[1], 0, 1).Solid && tiles[1].Position.X - Position.X <= roundRange) { Position += new Vector2(r, 0); } else if (!LevelManager.CurrentLevel.GetTileRelative(tiles[0], 0, 1).Solid && LevelManager.CurrentLevel.GetTileRelative(tiles[1], 0, 1).Solid && Position.X - tiles[0].Position.X <= roundRange) { Position -= new Vector2(r, 0); } } break; case Keys.Left: if (!Plint) { Sprite.Index = 2; } Position -= new Vector2(d, 0); if (LevelManager.CurrentLevel.GetTileRelative(tiles[0], -1, 0).Solid || LevelManager.CurrentLevel.GetTileRelative(tiles[1], -1, 0).Solid) { Position = new Vector2(Math.Max(Position.X, tiles[0].Position.X), Position.Y); if (LevelManager.CurrentLevel.GetTileRelative(tiles[0], -1, 0).Solid && !LevelManager.CurrentLevel.GetTileRelative(tiles[1], -1, 0).Solid && tiles[1].Position.Y - Position.Y <= roundRange) { Position += new Vector2(0,r); } else if (!LevelManager.CurrentLevel.GetTileRelative(tiles[0], -1, 0).Solid && LevelManager.CurrentLevel.GetTileRelative(tiles[1], -1, 0).Solid && Position.Y - tiles[0].Position.Y <= roundRange) { Position -= new Vector2(0,r); } } break; case Keys.Right: if (!Plint) { Sprite.Index = 3; } Position += new Vector2(d, 0); if (LevelManager.CurrentLevel.GetTileRelative(tiles[0], 1, 0).Solid || LevelManager.CurrentLevel.GetTileRelative(tiles[1], 1, 0).Solid) { Position = new Vector2(Math.Min(Position.X, tiles[1].Position.X), Position.Y); if (LevelManager.CurrentLevel.GetTileRelative(tiles[0], 1, 0).Solid && !LevelManager.CurrentLevel.GetTileRelative(tiles[1], 1, 0).Solid && tiles[1].Position.Y - Position.Y <= roundRange) { Position += new Vector2(0,r); } else if (!LevelManager.CurrentLevel.GetTileRelative(tiles[0], 1, 0).Solid && LevelManager.CurrentLevel.GetTileRelative(tiles[1], 1, 0).Solid && Position.Y - tiles[0].Position.Y <= roundRange) { Position -= new Vector2(0,r); } } break; } if (Math.Abs(Position.X - Math.Round(Position.X / 64.0) * 64) < 0.7 * d) Position = new Vector2((float)(Math.Round(Position.X / 64.0) * 64.0), Position.Y); if (Math.Abs(Position.Y - Math.Round(Position.Y / 64.0) * 64) < 0.7 * d) Position = new Vector2(Position.X, (float)(Math.Round(Position.Y / 64) * 64.0)); } }
public Tile GetTileRelative(Tile tile, int deltaX, int deltaY) { return tiles[tile.TileY + deltaY, tile.TileX + deltaX]; }