public Ghost(SpriteSheet spriteSheet, SpriteSheet runSpriteSheet, Level level, Pacman pacman, GhostBehaviour behaviour) : base(spriteSheet, level) { this.pacman = pacman; this.direction = new Vector2(0, -1); this.behaviour = behaviour; this.behaviour.Ghost = this; this.runBehaviour = new GhostRunAwayBehaviour(pacman, level); this.runBehaviour.Ghost = this; this.speed = 2; this.defaultSpriteSheet = spriteSheet; this.runSpriteSheet = runSpriteSheet; }
public void SetLevel(Level level) { currentLevel = level; hud.CurrentLevel = level; int oldScore = 0; if (pacman != null) { oldScore = pacman.Score; } SpriteSheet pacmanSheet = new SpriteSheet(characterSheet.Texture, Vector2.Zero, new Vector2(80, 16), new Vector2(16, 16)); pacman = new Pacman(pacmanSheet, level, 5); pacman.Score = oldScore; Tile pacmanSpawnTile = level.GetTile(1, 1); if (level.PacmanSpawn != null) { pacmanSpawnTile = level.PacmanSpawn; } pacman.Position = pacmanSpawnTile.Position + new Vector2(level.TileSize / 2); hud.Pacman = pacman; this.levelPosition = new Vector2((window.ClientBounds.Width / 2) - (level.PixelWidth / 2), (window.ClientBounds.Height / 2) - (level.PixelHeight / 2)); ghosts.Clear(); int ghostBehaviourIndex = 0; foreach (Tile spawn in level.GhostSpawns) { SpriteSheet redGhostSheet = new SpriteSheet(characterSheet.Texture, new Vector2(0, 16), new Vector2(128, 16), new Vector2(16, 16)); SpriteSheet pinkGhostSheet = new SpriteSheet(characterSheet.Texture, new Vector2(0, 32), new Vector2(128, 16), new Vector2(16, 16)); SpriteSheet blueGhostSheet = new SpriteSheet(characterSheet.Texture, new Vector2(0, 48), new Vector2(128, 16), new Vector2(16, 16)); SpriteSheet orangeGhostSheet = new SpriteSheet(characterSheet.Texture, new Vector2(0, 64), new Vector2(128, 16), new Vector2(16, 16)); SpriteSheet runGhostSheet = new SpriteSheet(characterSheet.Texture, new Vector2(0, 80), new Vector2(64, 16), new Vector2(16, 16)); GhostBehaviour behaviour = null; SpriteSheet ghostSpritesheet = null; switch (ghostBehaviourIndex) { case 0: behaviour = new GhostPatrolling(pacman, level); ghostSpritesheet = blueGhostSheet; break; case 1: behaviour = new GhostPathfinding(pacman, level); ghostSpritesheet = orangeGhostSheet; break; default: behaviour = new GhostFullyRandom(pacman, level); ghostSpritesheet = redGhostSheet; break; } Ghost ghost = new Ghost(ghostSpritesheet, runGhostSheet, level, pacman, behaviour); ghost.Position = spawn.Position + new Vector2(level.TileSize / 2); ghosts.Add(ghost); ghostBehaviourIndex++; ghostBehaviourIndex %= 3; } }