private void Form1_Load(object sender, EventArgs e) { Tbox = new TextBox(); Tbox.Text = "Points: " + points; Tbox.Parent = this; Tbox.Top = 200; Tbox.Left = 750; Tbox.Enabled = false; Tbox.BackColor = Color.Black; Tbox.BorderStyle = BorderStyle.None; Tbox.Width = 150; Tbox.Font = new Font(Tbox.Font.FontFamily, 16); pole = new Maze(); pacman = new PacMan(this); Blinky = new Ghost(this, 1, 1, Image.FromFile("red_right.png"), Image.FromFile("red_down.png"), Image.FromFile("red_left.png"), Image.FromFile("red_up.png")); Pinky = new Ghost(this, 26, 1, Image.FromFile("pink_right.png"), Image.FromFile("pink_down.png"), Image.FromFile("pink_left.png"), Image.FromFile("pink_up.png")); Inky = new Ghost(this, 1, 29, Image.FromFile("blue_right.png"), Image.FromFile("blue_down.png"), Image.FromFile("blue_left.png"), Image.FromFile("blue_up.png")); Clyde = new Ghost(this, 26, 29, Image.FromFile("orange_right.png"), Image.FromFile("orange_down.png"), Image.FromFile("orange_left.png"), Image.FromFile("orange_up.png")); System.IO.StreamReader pacfile = new System.IO.StreamReader("pac.txt"); pole.GetBored(pacfile, this); timer = new Timer(); timer.Interval = 450; timer.Tick += Movement; timer.Enabled = true; }
public override void Initialize(CameraGameObject puppet) { base.Initialize(puppet); this.forcePuppetToBePacMan(); this.me = (PacMan)puppet; }
public virtual void Initialize() { // Create the list objects this.Ghosts = new List <Ghost>(); this.PickupObjects = new List <PickupObject>(); // Spawn all gameobjects this.maxPickUpCounter = 0; for (int y = 0; y < this.Height; y++) { for (int x = 0; x < this.Width; x++) { Vector2 pos = this.GridToWorld(x, y); if (this.UnsafeIsPacManSpawn(x, y)) { this.PacMan = new PacMan(pos, this); this.PacMan.AI = this.setAI(0, this.PacMan); } else if (this.UnsafeIsGhostSpawn(x, y)) { int i = this.Ghosts.Count; if (Ais[i + 2] != null) { this.Ghosts.Add(new Ghost(pos, this, i)); this.Ghosts[i].AI = this.setAI(i + 2, this.Ghosts[i]); } else { this.Ghosts.Add(null); } } else if (this.UnsafeIsOrb(x, y)) { this.PickupObjects.Add(new PickupObject(ORB, pos, this)); this.maxPickUpCounter++; } else if (this.UnsafeIsSuperOrb(x, y)) { this.PickupObjects.Add(new PickupObject(SUPERORB, pos, this)); this.maxPickUpCounter++; } else if (this.UnsafeIsPickupSpawn(x, y)) { this.maxPickUpCounter++; } } } // Some default settings this.Start(); this.LastDirectionKey = DirectionKeys.None; this.setPreferredCameraFocus(); this.Graphics.SetDefaultCamera(); this.Player.UpdateCamera(); }
public override void Initialize(CameraGameObject puppet) { base.Initialize(puppet); this.forcePuppetToBePacMan(); this.me = (PacMan)puppet; this.forbiddenDir = Vector2.Zero; this.LastStates = new Ghost.States[this.Level.Ghosts.Count]; this.updateGhostStates(); this.aGhostCanSeeMe = false; this.aGhostCouldSeeMeLastUpdate = false; }
static void Main(string[] args) { PacMan PacMan = new PacMan(5000, 3, 0); while (PacMan.Lives > 0) { PacMan.Pellet(11); PacMan.InvincibleGhost(); PacMan.CheckScore(); PacMan.Melon(); PacMan.CheckScore(); PacMan.Galaxian(); PacMan.CheckScore(); PacMan.VulnerableGhost(); PacMan.CheckScore(); PacMan.VulnerableGhost2(); PacMan.CheckScore(); PacMan.Pellet(10); PacMan.Bell(); PacMan.CheckScore(); PacMan.Cherry(); PacMan.CheckScore(); PacMan.Strawberry(); PacMan.CheckScore(); PacMan.InvincibleGhost(); PacMan.CheckScore(); PacMan.Pellet(40); PacMan.Orange(); PacMan.CheckScore(); PacMan.Apple(); PacMan.CheckScore(); PacMan.InvincibleGhost(); PacMan.CheckScore(); PacMan.VulnerableGhost(); PacMan.CheckScore(); PacMan.Key(); PacMan.CheckScore(); PacMan.InvincibleGhost(); PacMan.CheckScore(); PacMan.Pellet(5); PacMan.VulnerableGhost(); PacMan.CheckScore(); PacMan.InvincibleGhost(); PacMan.CheckScore(); PacMan.EndGame(); PacMan.EndGame(); } Console.WriteLine("YOU ARE DEAD!"); PacMan.EndGame(); Console.ReadLine(); }
public GameEngine(Grid dataGrid, Random rand, int tickInterval) { this.dataGrid = dataGrid; this.rand = rand; dataGrid.Paint += new PaintEventHandler(dataGrid_Paint); pacman = new PacMan(); ghost = new Ghost[4]; ghost[0] = new Ghost("Purple"); ghost[1] = new Ghost("Red"); ghost[2] = new Ghost("Blue"); ghost[3] = new Ghost("Green"); gameOver = false; }
public Game(int currentLevel) { this._currentLevel = currentLevel; this._numberLevels = ConsiderNumberLevels(); Level.Level LevelInfo = new Level.Level(); LevelInfo = ReadNewLevelOnFile(); _pacMan = new PacMan(LevelInfo.pacMan); Wall levelWall = new Wall(); levelWall.WallCordinate = LevelInfo.wall; this._map = new Map(levelWall, LevelInfo.numberColumns, LevelInfo.numberLines); this._pacMan = new PacMan(LevelInfo.pacMan); EnemyArtificialIntelligence _enemyAI = new EnemyArtificialIntelligence(_map.LevelFood.FoodCoordinates); this._enemys = new Enemys(LevelInfo.enemys, _enemyAI); _enemyTimer = new Timer(MakeMoveEnemy, null, 0, GameSettings.EnemySpeed); }
//LINE OF SIGHT public bool HasLineOfSight(PacMan pacMan) { bool result = true; Point ghostPoint = _ghost.TileLocation; Point pacManPoint = pacMan.TileLocation; if (ghostPoint.X == pacManPoint.X) { int x = ghostPoint.X; int minY = Math.Min(ghostPoint.Y, pacManPoint.Y); int maxY = Math.Max(ghostPoint.Y, pacManPoint.Y); for (int i = minY; i < maxY; i++) { if (gameField[x, i] == (int)Pathfinder.PathFindObject.Wall) { result = false; break; } } } else if (ghostPoint.Y == pacManPoint.Y) { int y = ghostPoint.Y; int minX = Math.Min(ghostPoint.X, pacManPoint.X); int maxX = Math.Max(ghostPoint.X, pacManPoint.X); for (int i = minX; i < maxX; i++) { if (gameField[i, y] == (int)Pathfinder.PathFindObject.Wall) { result = false; break; } } } else { result = false; } return(result); }
//Start a new game. Початок нової гри public void NewGame() { pacman = new PacMan(this); items = new Items(this); player = new Player(); levels = new Levels(this); board = new Board(this); board.boardPB.Visible = false; board.boardPB.Paint += new PaintEventHandler(boardPB_Paint); board.boardPB.BringToFront(); tmr_movement.Stop(); tmr_animation.Stop(); board.boardPB.Visible = false; scoreLabel.Visible = false; highScoreLabel.Visible = false; textLabel.Visible = false; levelLabel.Visible = false; blinky.ResetPosition(); pinky.ResetPosition(); inky.ResetPosition(); clyde.ResetPosition(); Ghost.ResetChaseScatter(); Ghost.travellingGhosts = 0; ShowScoreLabel(); ShowHighScoreLabel(); ShowLevelLabel(); board.boardPB.Visible = true; //.Hide() / .Show() ShowReadyText(); tmr_refresh.Start(); wmp_game_start.Stop(); wmp_game_start.Open(new Uri("Sounds/game_start.wav", UriKind.Relative)); //wmp_game_start.Position = new TimeSpan(0); //wmp_game_start.Position = new TimeSpan(0, 0, 0, 3, 935); wmp_game_start.Play(); }
public void newGame() { pacman = new PacMan(); this.Width = PacMan.Radius * 2 * (WORLD_WIDTH + 1); this.Height = PacMan.Radius * 2 * (WORLD_HEIGHT + 1); // овде кодот за иницијализација на матрицата foodWorld foodWorld = new bool[WORLD_HEIGHT, WORLD_WIDTH]; for (int i = 0; i < WORLD_HEIGHT; i++) { for (int j = 0; j < WORLD_WIDTH; j++) { foodWorld[i, j] = true; } } // овде кодот за иницијализација и стартување на тајмерот timer = new Timer(); timer.Interval = TIMER_INTERVAL; timer.Enabled = true; timer.Tick += new EventHandler(timer_Tick); timer.Start(); }
/// <summary> /// Méthode qui réagit au Pacman qui mange un bonbon selon le type de Pacman /// </summary> /// <param name="p_pacman">Le Pacman qui agit</param> /// <param name="p_type">Le type du Pacman</param> public void AvoirPeur(PacMan p_pacman, PacManType p_type) { switch (p_type) { case PacManType.PacManNormal: peutEtreMangé = false; flash = false; resetDéplacement(); break; case PacManType.PacManMoyen: flash = true; break; case PacManType.SuperPacMan: peutEtreMangé = true; flash = false; break; default: break; } }
void CreateCreatures(Map map) { string[] notParsedCreatures = new StreamReader($"{map.PacManWindow.FolderLevelPath}/creatures.txt") .ReadToEnd() .Split('\n', '\r').Where(x => !string.IsNullOrEmpty(x)).ToArray(); Dictionary <string, Func <int, int, Creature> > dictionaryCreatures = new Dictionary <string, Func <int, int, Creature> > { { "p", (x, y) => new PacMan(this, new Position(x, y) * Map.LENGTH_CELL) }, { "s", (x, y) => new ShadowGhost(this, new Position(x, y) * Map.LENGTH_CELL, map) }, { "r", (x, y) => new RoflGhost(this, new Position(x, y) * Map.LENGTH_CELL, map) } }; creatures = new List <Creature>(); foreach (string creature in notParsedCreatures) { string[] data = creature.Split(); creatures.Add(dictionaryCreatures[data[0]] ((int)float.Parse(data[1]), (int)float.Parse(data[2]))); } Player = (PacMan)(creatures.First(x => x is PacMan) ?? new PacMan(this, new Position(0, 0) * Map.LENGTH_CELL)); }
public void CreateGameField() { //game engine variables isRunning = true; isGameOver = false; isPaused = false; isGameWon = false; //score tracking totalBalls = 0; totalScore = 0; backLayer = new TiledLayer(gameFieldWidth, gameFieldHeight, tileSize); //create background backLayer.Add(new Wall(Wall.WallType.TopLeft), true, 0, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 1, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 2, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 3, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 4, 1); backLayer.Add(new Wall(Wall.WallType.TopJunction), true, 5, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 6, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 7, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 8, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 9, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 10, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 11, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 12, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 13, 1); backLayer.Add(new Wall(Wall.WallType.TopJunction), true, 14, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 15, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 16, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 17, 1); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 18, 1); backLayer.Add(new Wall(Wall.WallType.TopRight), true, 19, 1); backLayer.Add(new Wall(Wall.WallType.Left), true, 0, 2); backLayer.Add(new Path(), false, 1, 2); backLayer.Add(new Path(), false, 2, 2); backLayer.Add(new Path(), false, 3, 2); backLayer.Add(new Path(), false, 4, 2); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 5, 2); backLayer.Add(new Path(), false, 6, 2); backLayer.Add(new Path(), false, 7, 2); backLayer.Add(new Path(), false, 8, 2); backLayer.Add(new Path(), false, 9, 2); backLayer.Add(new Path(), false, 10, 2); backLayer.Add(new Path(), false, 11, 2); backLayer.Add(new Path(), false, 12, 2); backLayer.Add(new Path(), false, 13, 2); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 14, 2); backLayer.Add(new Path(), false, 15, 2); backLayer.Add(new Path(), false, 16, 2); backLayer.Add(new Path(), false, 17, 2); backLayer.Add(new Path(), false, 18, 2); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 19, 2); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 0, 3); backLayer.Add(new Path(), false, 1, 3); backLayer.Add(new Wall(Wall.WallType.TopLeft), true, 2, 3); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 3, 3); backLayer.Add(new Path(), false, 4, 3); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 5, 3); backLayer.Add(new Path(), false, 6, 3); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 7, 3); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 8, 3); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 9, 3); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 10, 3); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 11, 3); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 12, 3); backLayer.Add(new Path(), false, 13, 3); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 14, 3); backLayer.Add(new Path(), false, 15, 3); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 16, 3); backLayer.Add(new Wall(Wall.WallType.TopRight), true, 17, 3); backLayer.Add(new Path(), false, 18, 3); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 19, 3); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 0, 4); backLayer.Add(new Path(), false, 1, 4); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 2, 4); backLayer.Add(new Path(), false, 3, 4); backLayer.Add(new Path(), false, 4, 4); backLayer.Add(new Path(), false, 5, 4); backLayer.Add(new Path(), false, 6, 4); backLayer.Add(new Path(), false, 7, 4); backLayer.Add(new Path(), false, 8, 4); backLayer.Add(new Path(), false, 9, 4); backLayer.Add(new Path(), false, 10, 4); backLayer.Add(new Path(), false, 11, 4); backLayer.Add(new Path(), false, 12, 4); backLayer.Add(new Path(), false, 13, 4); backLayer.Add(new Path(), false, 14, 4); backLayer.Add(new Path(), false, 15, 4); backLayer.Add(new Path(), false, 16, 4); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 17, 4); backLayer.Add(new Path(), false, 18, 4); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 19, 4); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 0, 5); backLayer.Add(new Path(), false, 1, 5); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 2, 5); backLayer.Add(new Path(), false, 3, 5); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 4, 5); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 5, 5); backLayer.Add(new Path(), false, 6, 5); backLayer.Add(new Wall(Wall.WallType.TopLeft), true, 7, 5); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 8, 5); backLayer.Add(new Path(), false, 9, 5); backLayer.Add(new Path(), false, 10, 5); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 11, 5); backLayer.Add(new Wall(Wall.WallType.TopRight), true, 12, 5); backLayer.Add(new Path(), false, 13, 5); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 14, 5); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 15, 5); backLayer.Add(new Path(), false, 16, 5); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 17, 5); backLayer.Add(new Path(), false, 18, 5); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 19, 5); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 0, 6); backLayer.Add(new Path(), false, 1, 6); backLayer.Add(new Path(), false, 2, 6); backLayer.Add(new Path(), false, 3, 6); backLayer.Add(new Path(), false, 4, 6); backLayer.Add(new Path(), false, 5, 6); backLayer.Add(new Path(), false, 6, 6); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 7, 6); backLayer.Add(new Path(), false, 8, 6); backLayer.Add(new Path(), false, 9, 6); backLayer.Add(new Path(), false, 10, 6); backLayer.Add(new Path(), false, 11, 6); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 12, 6); backLayer.Add(new Path(), false, 13, 6); backLayer.Add(new Path(), false, 14, 6); backLayer.Add(new Path(), false, 15, 6); backLayer.Add(new Path(), false, 16, 6); backLayer.Add(new Path(), false, 17, 6); backLayer.Add(new Path(), false, 18, 6); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 19, 6); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 0, 7); backLayer.Add(new Path(), false, 1, 7); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 2, 7); backLayer.Add(new Path(), false, 3, 7); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 4, 7); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 5, 7); backLayer.Add(new Path(), false, 6, 7); backLayer.Add(new Wall(Wall.WallType.BottomLeft), true, 7, 7); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 8, 7); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 9, 7); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 10, 7); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 11, 7); backLayer.Add(new Wall(Wall.WallType.BottomRight), true, 12, 7); backLayer.Add(new Path(), false, 13, 7); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 14, 7); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 15, 7); backLayer.Add(new Path(), false, 16, 7); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 17, 7); backLayer.Add(new Path(), false, 18, 7); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 19, 7); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 0, 8); backLayer.Add(new Path(), false, 1, 8); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 2, 8); backLayer.Add(new Path(), false, 3, 8); backLayer.Add(new Path(), false, 4, 8); backLayer.Add(new Path(), false, 5, 8); backLayer.Add(new Path(), false, 6, 8); backLayer.Add(new Path(), false, 7, 8); backLayer.Add(new Path(), false, 8, 8); backLayer.Add(new Path(), false, 9, 8); backLayer.Add(new Path(), false, 10, 8); backLayer.Add(new Path(), false, 11, 8); backLayer.Add(new Path(), false, 12, 8); backLayer.Add(new Path(), false, 13, 8); backLayer.Add(new Path(), false, 14, 8); backLayer.Add(new Path(), false, 15, 8); backLayer.Add(new Path(), false, 16, 8); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 17, 8); backLayer.Add(new Path(), false, 18, 8); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 19, 8); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 0, 9); backLayer.Add(new Path(), false, 1, 9); backLayer.Add(new Wall(Wall.WallType.BottomLeft), true, 2, 9); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 3, 9); backLayer.Add(new Path(), false, 4, 9); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 5, 9); backLayer.Add(new Path(), false, 6, 9); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 7, 9); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 8, 9); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 9, 9); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 10, 9); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 11, 9); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 12, 9); backLayer.Add(new Path(), false, 13, 9); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 14, 9); backLayer.Add(new Path(), false, 15, 9); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 16, 9); backLayer.Add(new Wall(Wall.WallType.BottomRight), true, 17, 9); backLayer.Add(new Path(), false, 18, 9); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 19, 9); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 0, 10); backLayer.Add(new Path(), false, 1, 10); backLayer.Add(new Path(), false, 2, 10); backLayer.Add(new Path(), false, 3, 10); backLayer.Add(new Path(), false, 4, 10); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 5, 10); backLayer.Add(new Path(), false, 6, 10); backLayer.Add(new Path(), false, 7, 10); backLayer.Add(new Path(), false, 8, 10); backLayer.Add(new Path(), false, 9, 10); backLayer.Add(new Path(), false, 10, 10); backLayer.Add(new Path(), false, 11, 10); backLayer.Add(new Path(), false, 12, 10); backLayer.Add(new Path(), false, 13, 10); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 14, 10); backLayer.Add(new Path(), false, 15, 10); backLayer.Add(new Path(), false, 16, 10); backLayer.Add(new Path(), false, 17, 10); backLayer.Add(new Path(), false, 18, 10); backLayer.Add(new Wall(Wall.WallType.Vertical), true, 19, 10); backLayer.Add(new Wall(Wall.WallType.BottomLeft), true, 0, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 1, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 2, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 3, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 4, 11); backLayer.Add(new Wall(Wall.WallType.BottomJunction), true, 5, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 6, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 7, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 8, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 9, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 10, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 11, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 12, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 13, 11); backLayer.Add(new Wall(Wall.WallType.BottomJunction), true, 14, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 15, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 16, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 17, 11); backLayer.Add(new Wall(Wall.WallType.Horizontal), true, 18, 11); backLayer.Add(new Wall(Wall.WallType.BottomRight), true, 19, 11); //food layer foodLayer = new TiledLayer(gameFieldWidth, gameFieldHeight, tileSize); foodLayer.Add(new Ball(), false, 1, 2); foodLayer.Add(new Ball(), false, 2, 2); foodLayer.Add(new Ball(), false, 3, 2); foodLayer.Add(new Ball(), false, 4, 2); foodLayer.Add(new Ball(), false, 6, 2); foodLayer.Add(new Ball(), false, 7, 2); foodLayer.Add(new Ball(), false, 8, 2); foodLayer.Add(new Ball(), false, 9, 2); foodLayer.Add(new Ball(), false, 10, 2); foodLayer.Add(new Ball(), false, 11, 2); foodLayer.Add(new Ball(), false, 12, 2); foodLayer.Add(new Ball(), false, 13, 2); foodLayer.Add(new Ball(), false, 15, 2); foodLayer.Add(new Ball(), false, 16, 2); foodLayer.Add(new Ball(), false, 17, 2); foodLayer.Add(new Ball(Ball.BallType.Power), false, 18, 2); foodLayer.Add(new Ball(), false, 1, 3); foodLayer.Add(new Ball(), false, 4, 3); foodLayer.Add(new Ball(), false, 6, 3); foodLayer.Add(new Ball(), false, 13, 3); foodLayer.Add(new Ball(), false, 15, 3); foodLayer.Add(new Ball(), false, 18, 3); foodLayer.Add(new Ball(), false, 1, 4); foodLayer.Add(new Ball(), false, 3, 4); foodLayer.Add(new Ball(), false, 4, 4); foodLayer.Add(new Ball(), false, 5, 4); foodLayer.Add(new Ball(), false, 6, 4); foodLayer.Add(new Ball(), false, 7, 4); foodLayer.Add(new Ball(), false, 8, 4); foodLayer.Add(new Ball(), false, 9, 4); foodLayer.Add(new Ball(), false, 10, 4); foodLayer.Add(new Ball(), false, 11, 4); foodLayer.Add(new Ball(), false, 12, 4); foodLayer.Add(new Ball(), false, 13, 4); foodLayer.Add(new Ball(), false, 14, 4); foodLayer.Add(new Ball(), false, 15, 4); foodLayer.Add(new Ball(), false, 16, 4); foodLayer.Add(new Ball(), false, 18, 4); foodLayer.Add(new Ball(), false, 1, 5); foodLayer.Add(new Ball(), false, 3, 5); foodLayer.Add(new Ball(), false, 6, 5); foodLayer.Add(new Ball(), false, 13, 5); foodLayer.Add(new Ball(), false, 16, 5); foodLayer.Add(new Ball(), false, 18, 5); foodLayer.Add(new Ball(), false, 1, 6); foodLayer.Add(new Ball(), false, 2, 6); foodLayer.Add(new Ball(), false, 3, 6); foodLayer.Add(new Ball(), false, 4, 6); foodLayer.Add(new Ball(), false, 5, 6); foodLayer.Add(new Ball(), false, 6, 6); foodLayer.Add(new Ball(), false, 13, 6); foodLayer.Add(new Ball(), false, 14, 6); foodLayer.Add(new Ball(), false, 15, 6); foodLayer.Add(new Ball(), false, 16, 6); foodLayer.Add(new Ball(), false, 17, 6); foodLayer.Add(new Ball(), false, 18, 6); foodLayer.Add(new Ball(), false, 1, 7); foodLayer.Add(new Ball(), false, 3, 7); foodLayer.Add(new Ball(), false, 6, 7); foodLayer.Add(new Ball(), false, 13, 7); foodLayer.Add(new Ball(), false, 16, 7); foodLayer.Add(new Ball(), false, 18, 7); foodLayer.Add(new Ball(), false, 1, 8); foodLayer.Add(new Ball(), false, 3, 8); foodLayer.Add(new Ball(), false, 4, 8); foodLayer.Add(new Ball(), false, 5, 8); foodLayer.Add(new Ball(), false, 6, 8); foodLayer.Add(new Ball(), false, 7, 8); foodLayer.Add(new Ball(), false, 8, 8); foodLayer.Add(new Ball(), false, 9, 8); foodLayer.Add(new Ball(), false, 10, 8); foodLayer.Add(new Ball(), false, 11, 8); foodLayer.Add(new Ball(), false, 12, 8); foodLayer.Add(new Ball(), false, 13, 8); foodLayer.Add(new Ball(), false, 14, 8); foodLayer.Add(new Ball(), false, 15, 8); foodLayer.Add(new Ball(), false, 16, 8); foodLayer.Add(new Ball(), false, 18, 8); foodLayer.Add(new Ball(), false, 1, 9); foodLayer.Add(new Ball(), false, 4, 9); foodLayer.Add(new Ball(), false, 6, 9); foodLayer.Add(new Ball(), false, 13, 9); foodLayer.Add(new Ball(), false, 15, 9); foodLayer.Add(new Ball(), false, 18, 9); foodLayer.Add(new Ball(Ball.BallType.Power), false, 1, 10); foodLayer.Add(new Ball(), false, 2, 10); foodLayer.Add(new Ball(), false, 3, 10); foodLayer.Add(new Ball(), false, 4, 10); foodLayer.Add(new Ball(), false, 6, 10); foodLayer.Add(new Ball(), false, 7, 10); foodLayer.Add(new Ball(), false, 8, 10); foodLayer.Add(new Ball(), false, 9, 10); foodLayer.Add(new Ball(), false, 10, 10); foodLayer.Add(new Ball(), false, 11, 10); foodLayer.Add(new Ball(), false, 12, 10); foodLayer.Add(new Ball(), false, 13, 10); foodLayer.Add(new Ball(), false, 15, 10); foodLayer.Add(new Ball(), false, 16, 10); foodLayer.Add(new Ball(), false, 17, 10); foodLayer.Add(new Ball(Ball.BallType.Power), false, 18, 10); //safeplaces safePlace = new List <Point>(); safePlace.Add(new Point(1, 2)); safePlace.Add(new Point(18, 2)); safePlace.Add(new Point(1, 10)); safePlace.Add(new Point(18, 10)); //spawning place spawningPlace = new Point(8, 6); //GAME OBJECTS GameObjects = new List <Sprite>(); //add food object to game objects for (int c = 0; c < foodLayer.Columns; c++) { for (int r = 0; r < foodLayer.Rows; r++) { if (foodLayer.TileObject[c, r] != null) { //with ball if (foodLayer.TileObject[c, r].Sprite.GetType() == typeof(Ball)) { Ball ball = (Ball)foodLayer.TileObject[c, r].Sprite; ball.TileLocation = new Point(c, r); GameObjects.Add(ball); totalBalls++; } } } } //create pacman pacMan = new PacMan(backLayer.TileObject[1, 2].Sprite.Location.X, backLayer.TileObject[1, 2].Sprite.Location.Y); pacMan.TileLocation = new Point(1, 2); pacMan.Speed = pacManSpeed; //create ghosts ghost1 = new Ghost(backLayer.TileObject[8, 6].Sprite.Location.X, backLayer.TileObject[8, 6].Sprite.Location.Y); ghost1.TileLocation = new Point(8, 6); ghost1.Speed = ghostSpeed; ghost2 = new Ghost(backLayer.TileObject[18, 2].Sprite.Location.X, backLayer.TileObject[18, 2].Sprite.Location.Y); ghost2.TileLocation = new Point(18, 2); ghost2.Speed = ghostSpeed; ghost3 = new Ghost(backLayer.TileObject[18, 10].Sprite.Location.X, backLayer.TileObject[18, 10].Sprite.Location.Y); ghost3.TileLocation = new Point(18, 10); ghost3.Speed = ghostSpeed; ghost4 = new Ghost(backLayer.TileObject[13, 10].Sprite.Location.X, backLayer.TileObject[13, 10].Sprite.Location.Y); ghost4.TileLocation = new Point(13, 10); ghost4.Speed = ghostSpeed; ghost5 = new Ghost(backLayer.TileObject[13, 2].Sprite.Location.X, backLayer.TileObject[13, 2].Sprite.Location.Y); ghost5.TileLocation = new Point(13, 2); ghost5.Speed = ghostSpeed; //add ghosts to game objects GameObjects.Add(ghost1); GameObjects.Add(ghost2); GameObjects.Add(ghost3); GameObjects.Add(ghost4); GameObjects.Add(ghost5); maxGhosts = totalGhosts = 5; }
/// <summary> /// Inscrit le fantome au Pacman qui mange un bonbon /// </summary> /// <param name="p_pacman">Le Pacman du jeu</param> public void Subscribe(PacMan p_pacman) { p_pacman.MangerBonbon += new PacMan.BonbonHandler(AvoirPeur); }
public void LoadObjects() { Player = new PacMan(Map.StartPoint); Player.D = Map.StartDirection; Enemies.Clear(); for (int n = 0; n < Map.Enemies.Count; n++) { Ghost en = new Ghost(Map.Enemies[n], false); en.Color = ConsoleColor.White; if (n % 2 != 0) en.White = true; Enemies.Add(en); } }
/// <summary> /// Réinitialise le Pacman /// </summary> public void resetPacman() { Instance = new PacMan(); }
/// <summary> /// The main entry point for the application. /// </summary> public static void Main(string[] args) { using (PacMan game = new PacMan()) { game.Run(); } }
void Awake() { Instance = this; }
//CHOOSE DIRECTION public Ghost.GhostDirection ChooseDirection(PacMan pacMan) { Ghost.GhostDirection currentDirection = _ghost.Direction; //line of sight if (HasLineOfSight(pacMan)) { _ghost.HasLineOfSight = true; losTimer.Stop(); } else { losTimer.Start(); } if (pacMan.HasPower == false && _ghost.HasLineOfSight == true) //chase { _ghost.IsChasing = true; //find path to pacman resultPath.Clear(); resultPath = pathfinder.PathFind(_ghost.TileLocation, pacMan.TileLocation); } else if (pacMan.HasPower == true) //run { _ghost.IsChasing = false; //find path to safelocation int bestSafePlace = 0; int bestSafePlaceDistance = pathfinder.CalculateDistance(GameEngine.safePlace[0], pacMan.TileLocation); for (int i = 0; i < GameEngine.safePlace.Count; i++) { //for each calculate distance from pacman to safe location Point safePlace = GameEngine.safePlace[i]; int safePlaceDistance = pathfinder.CalculateDistance(GameEngine.safePlace[i], pacMan.TileLocation); if (bestSafePlaceDistance < safePlaceDistance) { bestSafePlace = i; } } resultPath.Clear(); resultPath = pathfinder.PathFind(_ghost.TileLocation, GameEngine.safePlace[bestSafePlace]); } else { _ghost.IsChasing = true; if (_ghost.TileLocation == randomPoint || (randomPoint.X == -1 && randomPoint.Y == -1)) { List <Point> availableDestinations = new List <Point>(); //choose random destination for (int c = 0; c < GameEngine.backLayer.Columns; c++) { for (int r = 0; r < GameEngine.backLayer.Rows; r++) { if (GameEngine.backLayer.TileObject[c, r] == null) { continue; } if (GameEngine.backLayer.TileObject[c, r].Sprite.GetType() == typeof(Path)) { availableDestinations.Add(new Point(c, r)); } } } Random rand = new Random(); int random = rand.Next(0, availableDestinations.Count - 1); randomPoint = availableDestinations[random]; } resultPath.Clear(); resultPath = pathfinder.PathFind(_ghost.TileLocation, randomPoint); } //determine next direction if (resultPath != null && resultPath.Count > 0) { Point nextPoint = resultPath.Pop(); Point ghostPoint = _ghost.TileLocation; if (nextPoint.X > ghostPoint.X) { currentDirection = Ghost.GhostDirection.Right; } else if (nextPoint.X < ghostPoint.X) { currentDirection = Ghost.GhostDirection.Left; } else if (nextPoint.Y < ghostPoint.Y) { currentDirection = Ghost.GhostDirection.Up; } else if (nextPoint.Y > ghostPoint.Y) { currentDirection = Ghost.GhostDirection.Down; } else { currentDirection = Ghost.GhostDirection.None; } } else { currentDirection = Ghost.GhostDirection.None; } return(currentDirection); }
void OnDestroy() { DestroySingletons(); Instance = null; }