//Get target coordinates //Отримання координатів цілі public override Point GetTarget() { if (travellingHome) { return(AboveHome); } else if (scatter) { return(scatterTarget); } else { Point myTarget = PacForm.pixelToCoord(form.pacman.location); switch (form.pacman.direction) { case 0: myTarget.Y -= 4; break; case 1: myTarget.X -= 4; break; case 2: myTarget.Y += 4; break; case 3: myTarget.X += 4; break; } return(myTarget); } }
//Find the path to the target that is the shortest //Знаходження найкоротшого шляху до цілі private int FindShortestPathToTarget(bool[] array, Point target) { int[] pathLengths = new int[4]; for (int i = 0; i < array.Length; i++) { if (array[i] == true) { Point p = PacForm.pixelToCoord(location); p.X += directions[i].X; p.Y += directions[i].Y; int distance = (p.X - target.X) * (p.X - target.X) + (p.Y - target.Y) * (p.Y - target.Y); pathLengths[i] = distance; } } int min = int.MaxValue; int minIndex = 0; for (int i = 0; i < pathLengths.Length; i++) { if (array[i] == true && pathLengths[i] < min) { min = pathLengths[i]; minIndex = i; } } return(minIndex); }
//Cut out sprites from spritesheet and put them in a list //Виокремлення спрайтів із загального полотна і поміщення їх у контейнер list public void MakeSprites() { int SpriteWhite = 268; //8 int SpriteWhite2 = 270; //9 int SpriteFrightened = 272; //10 int SpriteFrightened2 = 274; //11 int SpriteEyesRight = 592; //12 int SpriteEyesRight2 = 594; //13 int SpriteEyesDown = 596; //14 int SpriteEyesDown2 = 598; //15 int SpriteEyesLeft = 600; //16 int SpriteEyesLeft2 = 602; //17 int SpriteEyesUp = 604; //18 int SpriteEyesUp2 = 606; //19 int SpriteScore200 = 400; //20 int SpriteScore400 = 402; //21 int SpriteScore800 = 404; //22 int SpriteScore1600 = 406; //23 Sprites.Add(PacForm.CutSprite(SpriteUp, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteUp2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteLeft, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteLeft2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteDown, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteDown2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteRight, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteRight2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteWhite, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteWhite2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteFrightened, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteFrightened2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteEyesUp, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteEyesUp2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteEyesLeft, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteEyesLeft2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteEyesDown, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteEyesDown2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteEyesRight, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteEyesRight2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteScore200, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteScore400, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteScore800, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(SpriteScore1600, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); }
//Drawing Pac-Man. Малювання пакмена public void Draw(Graphics gr) { PointF drawLocation = PacForm.drawCoord(location); gr.DrawImage(currentSprite, drawLocation.X, drawLocation.Y); //Draw Lives. Малювання кількості спроб for (int i = 2; i < lives * 2 + 2; i += 2) { PointF livesLocation = PacForm.coordToPixelCorner(new Point(i, 34)); gr.DrawImage(pacmanSprites[4], livesLocation.X, livesLocation.Y); } //coordinates debug //using (Font myFont = new Font("Arial", 14)) //{ // gr.DrawString(location.X.ToString() + "x" + location.Y.ToString(), myFont, Brushes.Red, new PointF(location.X, location.Y)); //} //coords as squares debug //using (Font myFont = new Font("Arial", 14)) //{ // Point coord = PacForm.pixelToCoord(location); // gr.DrawString(coord.X.ToString() + "x" + coord.Y.ToString(), myFont, Brushes.Red, new PointF(location.X, location.Y)); //} //chase-scatter debug //using (Font myFont = new Font("Arial", 14)) //{ // if (Ghost.scatter) gr.DrawString("SCATTER", myFont, Brushes.Red, new PointF(location.X, location.Y)); // else gr.DrawString("CHASE", myFont, Brushes.Red, new PointF(location.X, location.Y)); //} //using (Brush brush = new SolidBrush(Color.Green)) //{ // int size = PacForm.BoardTileSize * PacForm.SpriteScale; // gr.FillRectangle(brush, location.X, location.Y, size, size); //} //using (Font myFont = new Font("Arial", 14)) //{ // gr.DrawString(String.Format("\n{0:F4}",speed), myFont, Brushes.Red, new PointF(location.X, location.Y)); // gr.DrawString(location.X.ToString() + "x" + location.Y.ToString(), myFont, Brushes.Red, new PointF(location.X, location.Y)); //} //using (Pen pen = new Pen(Color.Red, 2)) //{ // gr.DrawRectangle(pen, 0, 0, size, size); //} }
//Is ghost slowed inside a tunnel? Чи уповільнений привид у тунелі? bool insideTunnel() { if (form.items.itemsMap[PacForm.pixelToCoord(location).Y, PacForm.pixelToCoord(location).X] == 5) { return(true); } else { return(false); } }
public void ResetPosition() { location = PacForm.coordToPixelCenter(new Point(14, 26)); location.X -= PacForm.BoardTileSize * PacForm.SpriteScale / 2; direction = 0; nextDirection = 0; currentSprite = pacmanSprites[2]; moving = false; dead = false; keyPressed = false; }
public Levels(PacForm frm) { form = frm; level = 0; bonuslives = 1; newLifeScore = 10000; blinkTimerInterval = 300; speed = PacForm.boardUnitSize * 10F / 1000F; frightTime = new int[] { 6000, 5000, 4000, 3000, 2000, 5000, 2000, 2000, 1000, 5000, 2000, 1000, 1000, 3000, 1000, 1000, 0, 1000, 0, 0, 0 }; nFlashes = new int[] { 5, 5, 5, 5, 5, 5, 5, 5, 3, 5, 5, 3, 3, 5, 3, 3, 0, 3, 0, 0, 0 }; pacmanSpeed = new float[] { 0.8F, 0.9F, 0.9F, 0.9F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 0.9F }; frightPacmanSpeed = new float[] { 0.9F, 0.95F, 0.95F, 0.95F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F }; ghostSpeed = new float[] { 0.75F, 0.85F, 0.85F, 0.85F, 0.95F, 0.95F, 0.95F, 0.95F, 0.95F, 0.95F, 0.95F, 0.95F, 0.95F, 0.95F, 0.95F, 0.95F, 0.95F, 0.95F, 0.95F, 0.95F, 0.95F }; ghostTunnelSpeed = new float[] { 0.40F, 0.45F, 0.45F, 0.45F, 0.50F, 0.50F, 0.50F, 0.50F, 0.50F, 0.50F, 0.50F, 0.50F, 0.50F, 0.50F, 0.50F, 0.50F, 0.50F, 0.50F, 0.50F, 0.50F, 0.50F }; frightGhostSpeed = new float[] { 0.5F, 0.55F, 0.55F, 0.55F, 0.6F, 0.6F, 0.6F, 0.6F, 0.6F, 0.6F, 0.6F, 0.6F, 0.6F, 0.6F, 0.6F, 0.6F, 0.6F, 0.6F, 0.6F, 0.6F, 0.6F }; bonusSymbol = new int[] { 2, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9 }; bonusPoints = new int[] { 100, 300, 500, 500, 700, 700, 1000, 1000, 2000, 2000, 3000, 3000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000 }; chaseScatter = new int[, ] { { 0007000, 0020000, 0007000, 0020000, 0005000, 0020000, 0005000, 9999999 }, //0 { 0007000, 0020000, 0007000, 0020000, 0005000, 1033000, 0000016, 9999999 }, //1 { 0007000, 0020000, 0007000, 0020000, 0005000, 1033000, 0000016, 9999999 }, //2 { 0007000, 0020000, 0007000, 0020000, 0005000, 1033000, 0000016, 9999999 }, //3 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //4 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //5 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //6 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //7 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //8 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //9 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //10 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //11 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //12 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //13 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //14 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //15 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //16 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //17 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //18 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 }, //19 { 0005000, 0020000, 0005000, 0020000, 0005000, 1037000, 0000016, 9999999 } //20 }; elroy1DotsLeft = new int[] { 20, 30, 40, 40, 40, 50, 50, 50, 60, 60, 60, 80, 80, 80, 100, 100, 100, 100, 120, 120, 120 }; elroy2DotsLeft = new int[] { 10, 15, 20, 20, 20, 25, 25, 25, 30, 30, 30, 40, 40, 40, 50, 50, 50, 50, 60, 60, 60 }; elroy1Speed = new float[] { 0.8F, 0.9F, 0.9F, 0.9F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F, 1F }; elroy2Speed = new float[] { 0.85F, 0.95F, 0.95F, 0.95F, 1.05F, 1.05F, 1.05F, 1.05F, 1.05F, 1.05F, 1.05F, 1.05F, 1.05F, 1.05F, 1.05F, 1.05F, 1.05F, 1.05F, 1.05F, 1.05F, 1.05F }; ghostDotThreshold = new int[, ] { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 60, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; globalDotThreshold = new int[] { 0, 7, 17, 32 }; exitTimerThreshold = new int[] { 4000, 4000, 4000, 4000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000 }; }
void MakeSprites() { int dotSprite = 16; //0 int powerPelletSprite = 20; //1 int cherriesSprite = 320; //2 int strawberrySprite = 322; //3 int peachSprite = 324; //4 int appleSprite = 328; //5 int grapesSprite = 330; //6 int galaxianSprite = 332; //7 int bellSprite = 326; //8 int keySprite = 334; //9 int score_100_1_Sprite = 129; //10 int score_300_1_Sprite = 130; //11 int score_500_1_Sprite = 131; //12 int score_700_1_Sprite = 132; //13 int score_00_Sprite = 133; //14 int score_1000_1_Sprite = 134; //15 int score_2000_1_1Sprite = 135; //16 int score_2000_2_Sprite = 136; //17 int score_3000_1_Sprite = 137; //18 int score_3000_2_Sprite = 138; //19 int score_5000_1_Sprite = 139; //20 int score_5000_2_Sprite = 140; //21 int score_5000_3_Sprite = 141; //22 int score_5000_4_Sprite = 142; //23 Sprites.Add(PacForm.CutSprite(dotSprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(powerPelletSprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(cherriesSprite, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(strawberrySprite, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(peachSprite, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(appleSprite, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(grapesSprite, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(galaxianSprite, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(bellSprite, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(keySprite, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(score_100_1_Sprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(score_300_1_Sprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(score_500_1_Sprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(score_700_1_Sprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(score_00_Sprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(score_1000_1_Sprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(score_2000_1_1Sprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(score_2000_2_Sprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(score_3000_1_Sprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(score_3000_2_Sprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(score_5000_1_Sprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(score_5000_2_Sprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(score_5000_3_Sprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); Sprites.Add(PacForm.CutSprite(score_5000_4_Sprite, PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale)); }
void MakeWaypoints() { PointF way_01 = PacForm.coordToPixelCenter(new Point(14, 14)); way_01.X -= PacForm.BoardTileSize * PacForm.SpriteScale / 2; PointF way_02 = PacForm.coordToPixelCenter(new Point(14, 17)); way_02.X -= PacForm.BoardTileSize * PacForm.SpriteScale / 2; waypoints = new PointF[] { way_01, way_02 }; }
//Get target coordinates //Отримання координатів цілі public override Point GetTarget() { if (travellingHome) { return(AboveHome); } else if (scatter) { return(scatterTarget); } else { return(PacForm.pixelToCoord(form.pacman.location)); } }
public PacMan(PacForm frm) { lives = 4; direction = 0; nextDirection = 0; deadSpriteLoop = 0; spriteLoop = 0; form = frm; dead = false; MakeSprites(); location = PacForm.coordToPixelCenter(new Point(14, 26)); location.X -= PacForm.BoardTileSize * PacForm.SpriteScale / 2; speed = 1f; currentSprite = pacmanSprites[2]; bonusCounter = 0; InitializeSound(); }
void ChooseRandomDirection() { currentCoordinate = PacForm.pixelToCoord(location); if (currentCoordinate != previousCoordinate) { previousCoordinate = currentCoordinate; bool[] whereToGo = LookAround(); int nDirections = CountDirections(whereToGo); if (nDirections > 1) { nextDirection = FindRandomDirection(whereToGo); } else { nextDirection = Math.Abs(nDirections); } } }
public Blinky(PacForm frm) : base(frm) { ghostNumber = 0; color = Color.Red; SpriteRight = 384; SpriteRight2 = 386; SpriteDown = 388; SpriteDown2 = 390; SpriteLeft = 392; SpriteLeft2 = 394; SpriteUp = 396; SpriteUp2 = 398; home = PacForm.coordToPixelCenter(new Point(14, 14)); scatterTarget = new Point(25, 0); MakeWaypoints(); MakeSprites(); ResetPosition(); }
//Determines if movement is possible. Визначає, чи можливий рух public bool CanMove(int dir) { Point nextCoord = PacForm.pixelToCoord(location); switch (dir) { case 0: if (form.board.ValidMove(new Point(nextCoord.X, nextCoord.Y - 1))) { return(true); } break; case 1: if ((nextCoord.X - 1) < 0) { nextCoord = new Point(nextCoord.X + form.board.size.Width, nextCoord.Y); } if (form.board.ValidMove(new Point(nextCoord.X - 1, nextCoord.Y))) { return(true); } break; case 2: if (form.board.ValidMove(new Point(nextCoord.X, nextCoord.Y + 1))) { return(true); } break; case 3: if ((nextCoord.X + 1) >= form.board.size.Width) { nextCoord = new Point(nextCoord.X - form.board.size.Width, nextCoord.Y); } if (form.board.ValidMove(new Point(nextCoord.X + 1, nextCoord.Y))) { return(true); } break; } return(false); }
//Check for collisions with Pac-Man //Перевірка зіткнень привида і Пакмена private void PacManCollision() { //if (form.pacman.energized && PacForm.pixelToCoord(form.pacman.location) == PacForm.pixelToCoord(location)) //if (PacForm.pixelToCoord(location).X < 14) AboveHome = LeftAboveHome; //else AboveHome = RightAboveHome; if ((form.pacman.energized || form.energyBtn.Checked) && !travellingHome && !followingWaypoints && PacForm.pixelToCoord(form.pacman.location) == PacForm.pixelToCoord(location)) { wmp_eat_ghost.Stop(); wmp_eat_ghost.Open(new Uri("Sounds/eat_ghost.wav", UriKind.Relative)); //wmp_eat_ghost.Position = new TimeSpan(0); wmp_eat_ghost.Play(); travellingHome = true; if (travellingGhosts == 0) { eatenAll = false; } travellingGhostsPrivate = travellingGhosts; travellingGhosts++; form.player.adjustScore((int)Math.Pow(2, travellingGhosts) * 100); if (travellingGhosts == 4 && !eatenAll) { wmp_extend.Stop(); wmp_extend.Open(new Uri("Sounds/extend.wav", UriKind.Relative)); //wmp_extend.Position = new TimeSpan(0); wmp_extend.Play(); form.player.adjustScore(12000); eatenAll = true; } showScore = true; //form.LastTime = DateTime.Now; showScoreTimer.Start(); } if (!form.pacman.energized && !travellingHome && !followingWaypoints && PacForm.pixelToCoord(form.pacman.location) == PacForm.pixelToCoord(location)) { if (!form.invincBtn.Checked) { currentSprite = emptySprite; form.pacman.Die(); } } }
public Clyde(PacForm frm) : base(frm) { ghostNumber = 3; color = Color.Orange; SpriteRight = 576; SpriteRight2 = 578; SpriteDown = 580; SpriteDown2 = 582; SpriteLeft = 584; SpriteLeft2 = 586; SpriteUp = 588; SpriteUp2 = 590; home = PacForm.coordToPixelCenter(new Point(15, 17)); scatterTarget = new Point(0, 35); stayAtHomeWayPointUp = PacForm.coordToPixelCorner(new Point(16, 17)); stayAtHomeWayPointDown = PacForm.coordToPixelCorner(new Point(16, 18)); MakeWaypoints(); MakeSprites(); ResetPosition(); }
public Inky(PacForm frm) : base(frm) { ghostNumber = 2; color = Color.Aqua; SpriteRight = 528; SpriteRight2 = 530; SpriteDown = 532; SpriteDown2 = 534; SpriteLeft = 536; SpriteLeft2 = 538; SpriteUp = 540; SpriteUp2 = 542; home = PacForm.coordToPixelCenter(new Point(12, 17)); scatterTarget = new Point(27, 35); stayAtHomeWayPointUp = PacForm.coordToPixelCorner(new Point(12, 17)); stayAtHomeWayPointDown = PacForm.coordToPixelCorner(new Point(12, 18)); MakeWaypoints(); MakeSprites(); ResetPosition(); }
//Get target coordinates //Отримання координатів цілі public override Point GetTarget() { if (travellingHome) { return(AboveHome); } else if (scatter) { return(scatterTarget); } else { Point myTarget = new Point(); Point pacmanLoc = PacForm.pixelToCoord(form.pacman.location); Point blinkyLoc = PacForm.pixelToCoord(form.blinky.location); myTarget.X = pacmanLoc.X + (pacmanLoc.X - blinkyLoc.X); myTarget.Y = pacmanLoc.Y + (pacmanLoc.Y - blinkyLoc.Y); return(myTarget); } }
public Pinky(PacForm frm) : base(frm) { ghostNumber = 1; color = Color.Pink; SpriteRight = 512; SpriteRight2 = 514; SpriteDown = 516; SpriteDown2 = 518; SpriteLeft = 520; SpriteLeft2 = 522; SpriteUp = 524; SpriteUp2 = 526; home = PacForm.coordToPixelCenter(new Point(14, 17)); scatterTarget = new Point(2, 0); stayAtHomeWayPointUp = PacForm.coordToPixelCorner(new Point(14, 17)); stayAtHomeWayPointDown = PacForm.coordToPixelCorner(new Point(14, 18)); MakeWaypoints(); MakeSprites(); ResetPosition(); }
//Cutting sprites from spritesheet. Вирізання спрайтів з полотна private void MakeSprites() { int SpriteLeft = 192; int SpriteLeft2 = 196; int SpriteUp = 194; int SpriteUp2 = 198; int SpriteRight = 200; int SpriteRight2 = 204; int SpriteDown = 202; int SpriteDown2 = 206; int SpriteFull = 448; int SpriteDead = 456; pacmanSprites.Add(PacForm.CutSprite(SpriteUp, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteUp2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteFull, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteUp2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteLeft, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteLeft2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteFull, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteLeft2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteDown, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteDown2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteFull, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteDown2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteRight, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteRight2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteFull, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); pacmanSprites.Add(PacForm.CutSprite(SpriteRight2, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); for (int i = 0; i < 24; i += 2) { pacmanSprites.Add(PacForm.CutSprite(SpriteDead + i, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale)); } }
public Ghost(PacForm frm) { int SpriteEmpty = 478; travellingGhosts = 0; emptySprite = PacForm.CutSprite(SpriteEmpty, PacForm.SpriteSize, PacForm.SpriteSize * PacForm.SpriteScale); form = frm; directions[0] = new Point(0, -1); directions[1] = new Point(-1, 0); directions[2] = new Point(0, 1); directions[3] = new Point(1, 0); speed = 1F; blinkTimer = new Timer(); blinkTimer.Interval = form.levels.blinkTimerInterval; blinkTimer.Tick += new EventHandler(BlinkingAnimation); showScoreTimer = new Timer(); showScoreTimer.Interval = 1000; showScoreTimer.Tick += new EventHandler(showEatenScore); scatterTimer = new Timer(); scatterTimer.Tick += new EventHandler(ScatterOffEvent); chaseTimer = new Timer(); chaseTimer.Tick += new EventHandler(ChaseOffEvent); scatterStopwatch = new Stopwatch(); chaseStopwatch = new Stopwatch(); //Used in blinking animation. Використовується у анімації блимання frightenedSpriteNumber = 10; AboveHome = new Point(14, 14); waypointsCounter = 0; spriteLoop = 0; //Exit conditions. Умови иходу привидів з домівки canExit = new bool[4]; ghostItemCounter = new int[4]; InitializeSound(); }
//Choose where to go. Вибір напрямку руху void ChooseDirection() { currentCoordinate = PacForm.pixelToCoord(location); if (currentCoordinate != previousCoordinate) { previousCoordinate = currentCoordinate; bool[] whereToGo = LookAround(); int nDirections = CountDirections(whereToGo); if (nDirections > 1) { nextDirection = FindShortestPathToTarget(whereToGo, GetTarget()); } else { nextDirection = Math.Abs(nDirections); } if (currentCoordinate == AboveHome && travellingHome) { followingWaypoints = true; } } }
//Ghosts leave the ghost house at the start of round //Привиди залишають свою домівку на початку раунду public void ExitHouse() { location.X = (float)Math.Round(location.X); location.Y = (float)Math.Round(location.Y); PointF exitPoint = PacForm.coordToPixelCenter(new Point(14, 14)); exitPoint.X -= PacForm.BoardTileSize * PacForm.SpriteScale / 4; if (location.X > exitPoint.X) { location.X -= 1; direction = 1; } else if (location.X < exitPoint.X) { location.X += 1; direction = 3; } else if (location.X == exitPoint.X && location.Y > exitPoint.Y) { location.Y -= 1; direction = 0; } else if (location.X == exitPoint.X && location.Y < exitPoint.Y) { location.Y += 1; direction = 2; } if (location == exitPoint) { exited = true; int dir = random.Next(0, 2); if (dir > 0) { direction = 1; } else { direction = 3; } } }
//Draw sprite on screen //Малювання персонажу на екрані public void Draw(Graphics gr) { PointF drawLocation = PacForm.drawCoord(location); gr.DrawImage(currentSprite, drawLocation.X, drawLocation.Y); //debug text //using (Font myFont = new Font("Arial", 14)) //{ // gr.DrawString(eatenAll.ToString(), myFont, System.Drawing.Brushes.Red, new PointF(location.X, location.Y)); //} //debug targeting //using (Brush brush = new SolidBrush(color)) //{ // int size = PacForm.BoardTileSize * PacForm.SpriteScale; // gr.FillRectangle(brush, PacForm.coordToPixelCorner(GetTarget()).X, PacForm.coordToPixelCorner(GetTarget()).Y, size, size); //} }
//Get target coordinates //Отримання координатів цілі public override Point GetTarget() { if (travellingHome) { return(AboveHome); } else if (scatter) { return(scatterTarget); } else { Point pacmanLoc = PacForm.pixelToCoord(form.pacman.location); Point myLoc = PacForm.pixelToCoord(location); if (FindDistance(myLoc, pacmanLoc) < 9) { return(scatterTarget); } else { return(pacmanLoc); } } }
public Items(PacForm frm) { //0 wall //1 free //2 dot //3 superdot //4 bonus fruit //5 slow terrain random = new Random(); form = frm; //itemsMap = new int[form.board.size.Width, form.board.size.Height]; itemsMap = new int[, ] { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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 0, 0, 0, 0, 0 }, }; powerPelletVisible = true; blinkTimer = new Timer(); blinkTimer.Interval = 150; blinkTimer.Enabled = true; blinkTimer.Tick += new EventHandler(tmr_Blink); fruitTimer = new Timer(); //NextDouble() * (max - min) + min fruitTimer.Interval = random.Next(9000, 10001); fruitTimer.Tick += new EventHandler(HideFruit); hideScoreTimer = new Timer(); hideScoreTimer.Tick += new EventHandler(HideScore); hideScoreTimer.Interval = 3000; Sprites = new List <Bitmap>(); bonusFruitLocation = PacForm.coordToPixelCorner(new Point(13, 19)); bonusFruitLocation.Y += PacForm.unitCenter; score1coord = PacForm.coordToPixelCorner(new Point(12, 20)); score2coord = PacForm.coordToPixelCorner(new Point(13, 20)); score3coord = PacForm.coordToPixelCorner(new Point(14, 20)); score4coord = PacForm.coordToPixelCorner(new Point(15, 20)); ghostDotCounter = new int[4]; dotStopwatch = new Stopwatch(); InitializeSound(); MakeSprites(); }
//Display items on the board. Малювання предметів на ігровому полі public void Draw(Graphics gr) { dots = 0; using (Bitmap result = new Bitmap(form.board.boardPBSize.Width, form.board.boardPBSize.Height)) { using (Graphics tempGr = Graphics.FromImage(result)) { for (int i = 0; i < form.board.size.Height; i++) { for (int j = 0; j < form.board.size.Width; j++) { if (itemsMap[i, j] == 2) { tempGr.DrawImage(Sprites[0], PacForm.coordToPixelCorner(new Point(j, i))); dots++; } if (powerPelletVisible) { if (itemsMap[i, j] == 3) { tempGr.DrawImage(Sprites[1], PacForm.coordToPixelCorner(new Point(j, i))); } } } } //Draw bonus fruit. Малювання фрукту, який можна з'їсти if (fruitTime) { tempGr.DrawImage(Sprites[form.levels.get_bonusSymbol()], bonusFruitLocation); } //Draw level fruits. Малювання фруктів на позначення рівня int startingLevelToDraw = 0; if (form.levels.get_level() > 5) { startingLevelToDraw = form.levels.get_level() - 5; } int numberOfFruitsToDraw = 0; if (form.levels.get_level() < 5) { numberOfFruitsToDraw = form.levels.get_level() + 1; } else { numberOfFruitsToDraw = 6; } for (int pos = 24, lvl = startingLevelToDraw; pos >= 26 - numberOfFruitsToDraw * 2; pos -= 2, lvl++) { PointF fruitLocation = PacForm.coordToPixelCorner(new Point(pos, 34)); tempGr.DrawImage(form.items.Sprites[form.levels.get_bonusSymbol(lvl)], fruitLocation.X, fruitLocation.Y); } //Draw score after eating fruit. Малювання балів за з'їдені фрукти if (showScore) { switch (form.levels.get_level()) { case 0: tempGr.DrawImage(Sprites[10], score2coord); tempGr.DrawImage(Sprites[14], score3coord); break; case 1: tempGr.DrawImage(Sprites[11], score2coord); tempGr.DrawImage(Sprites[14], score3coord); break; case 2: case 3: tempGr.DrawImage(Sprites[12], score2coord); tempGr.DrawImage(Sprites[14], score3coord); break; case 4: case 5: tempGr.DrawImage(Sprites[13], score2coord); tempGr.DrawImage(Sprites[14], score3coord); break; case 6: case 7: tempGr.DrawImage(Sprites[15], score2coord); tempGr.DrawImage(Sprites[14], score3coord); break; case 8: case 9: tempGr.DrawImage(Sprites[16], score1coord); tempGr.DrawImage(Sprites[17], score2coord); tempGr.DrawImage(Sprites[22], score3coord); tempGr.DrawImage(Sprites[23], score4coord); break; case 10: case 11: tempGr.DrawImage(Sprites[18], score1coord); tempGr.DrawImage(Sprites[19], score2coord); tempGr.DrawImage(Sprites[22], score3coord); tempGr.DrawImage(Sprites[23], score4coord); break; case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20: tempGr.DrawImage(Sprites[20], score1coord); tempGr.DrawImage(Sprites[21], score2coord); tempGr.DrawImage(Sprites[22], score3coord); tempGr.DrawImage(Sprites[23], score4coord); break; } } //Final drawing of everything. Перенесення намальованого на екран gr.DrawImage(result, PointF.Empty); } } }
public Board(PacForm form) { size = new Size(28, 36);//224 x 288 boardPBSize = new Size(size.Width * PacForm.BoardTileSize * PacForm.SpriteScale, size.Height * PacForm.BoardTileSize * PacForm.SpriteScale); board = new int[size.Width, size.Height]; map = new Bitmap(size.Width * PacForm.BoardTileSize * PacForm.SpriteScale, size.Height * PacForm.BoardTileSize * PacForm.SpriteScale); boardPB = new PictureBox(); mapChanged = new Bitmap(map.Width, map.Height); //Board layout. Numbers represent sprites on the spritesheet. 022 and 023 are empty sprites //Розташування об'єктів на ігровому полі. Номера відповідають номерам спрайтів. 022 та 023 є пустими зображеннями board = new int[, ] { { 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023 }, { 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023 }, { 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023 }, { 145, 154, 154, 154, 154, 154, 154, 154, 154, 154, 154, 154, 154, 187, 186, 154, 154, 154, 154, 154, 154, 154, 154, 154, 154, 154, 154, 144 }, { 147, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 121, 120, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 146 }, { 147, 022, 119, 158, 158, 118, 022, 119, 158, 158, 158, 118, 022, 121, 120, 022, 119, 158, 158, 158, 118, 022, 119, 158, 158, 118, 022, 146 }, { 147, 022, 121, 023, 023, 120, 022, 121, 023, 023, 023, 120, 022, 121, 120, 022, 121, 023, 023, 023, 120, 022, 121, 023, 023, 120, 022, 146 }, { 147, 022, 185, 116, 116, 184, 022, 185, 116, 116, 116, 184, 022, 123, 295, 022, 185, 116, 116, 116, 184, 022, 185, 116, 116, 184, 022, 146 }, { 147, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 146 }, { 147, 022, 119, 158, 158, 118, 022, 119, 118, 022, 119, 158, 158, 158, 158, 158, 158, 118, 022, 119, 118, 022, 119, 158, 158, 118, 022, 146 }, { 147, 022, 185, 116, 116, 184, 022, 121, 120, 022, 185, 116, 116, 179, 178, 116, 116, 184, 022, 121, 120, 022, 185, 116, 116, 184, 022, 146 }, { 147, 022, 022, 022, 022, 022, 022, 121, 120, 022, 022, 022, 022, 121, 120, 022, 022, 022, 022, 121, 120, 022, 022, 022, 022, 022, 022, 146 }, { 149, 156, 156, 156, 156, 118, 022, 121, 180, 158, 158, 118, 022, 121, 120, 022, 119, 158, 158, 181, 120, 022, 119, 156, 156, 156, 156, 148 }, { 023, 023, 023, 023, 023, 147, 022, 121, 178, 116, 116, 184, 022, 185, 184, 022, 185, 116, 116, 179, 120, 022, 146, 023, 023, 023, 023, 023 }, { 023, 023, 023, 023, 023, 147, 022, 121, 120, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 121, 120, 022, 146, 023, 023, 023, 023, 023 }, { 023, 023, 023, 023, 023, 147, 022, 121, 120, 022, 125, 156, 177, 023, 023, 176, 156, 124, 022, 121, 120, 022, 146, 023, 023, 023, 023, 023 }, { 155, 155, 155, 155, 155, 184, 022, 185, 184, 022, 146, 022, 022, 022, 022, 022, 022, 147, 022, 185, 184, 022, 185, 155, 155, 155, 155, 155 }, { 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 146, 022, 022, 022, 022, 022, 022, 147, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022 }, { 156, 156, 156, 156, 156, 118, 022, 119, 118, 022, 146, 022, 022, 022, 022, 022, 022, 147, 022, 119, 118, 022, 119, 156, 156, 156, 156, 156 }, { 023, 023, 023, 023, 023, 147, 022, 121, 120, 022, 127, 155, 155, 155, 155, 155, 155, 126, 022, 121, 120, 022, 146, 023, 023, 023, 023, 023 }, { 023, 023, 023, 023, 023, 147, 022, 121, 120, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 121, 120, 022, 146, 023, 023, 023, 023, 023 }, { 023, 023, 023, 023, 023, 147, 022, 121, 120, 022, 119, 158, 158, 158, 158, 158, 158, 118, 022, 121, 120, 022, 146, 023, 023, 023, 023, 023 }, { 145, 155, 155, 155, 155, 184, 022, 185, 184, 022, 185, 116, 116, 179, 178, 116, 116, 184, 022, 185, 184, 022, 185, 155, 155, 155, 155, 144 }, { 147, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 121, 120, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 146 }, { 147, 022, 119, 158, 158, 118, 022, 119, 158, 158, 158, 118, 022, 121, 120, 022, 119, 158, 158, 158, 118, 022, 119, 158, 158, 118, 022, 146 }, { 147, 022, 185, 116, 179, 120, 022, 185, 116, 116, 116, 184, 022, 185, 184, 022, 185, 116, 116, 116, 184, 022, 121, 178, 116, 184, 022, 146 }, { 147, 022, 022, 022, 121, 120, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 121, 120, 022, 022, 022, 146 }, { 151, 158, 118, 022, 121, 120, 022, 119, 118, 022, 119, 158, 158, 158, 158, 158, 158, 118, 022, 119, 118, 022, 121, 120, 022, 119, 158, 150 }, { 153, 116, 184, 022, 185, 184, 022, 121, 120, 022, 185, 116, 116, 179, 178, 116, 116, 184, 022, 121, 120, 022, 185, 184, 022, 185, 116, 152 }, { 147, 022, 022, 022, 022, 022, 022, 121, 120, 022, 022, 022, 022, 121, 120, 022, 022, 022, 022, 121, 120, 022, 022, 022, 022, 022, 022, 146 }, { 147, 022, 119, 158, 158, 158, 158, 181, 180, 158, 158, 118, 022, 121, 120, 022, 119, 158, 158, 181, 180, 158, 158, 158, 158, 118, 022, 146 }, { 147, 022, 185, 116, 116, 116, 116, 116, 116, 116, 116, 184, 022, 185, 184, 022, 185, 116, 116, 116, 116, 116, 116, 116, 116, 184, 022, 146 }, { 147, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 022, 146 }, { 149, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 157, 148 }, { 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023 }, { 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023, 023 }, }; //Creating board background image //Створення фонового малюнку ігрового поля using (Graphics g = Graphics.FromImage(map)) { //Draw walls. Малювання стін for (int i = 0; i < size.Width; i++) { for (int j = 0; j < size.Height; j++) { Bitmap chunk = PacForm.CutSprite(board[j, i], PacForm.BoardTileSize, PacForm.BoardTileSize * PacForm.SpriteScale); g.DrawImage(chunk, i * PacForm.BoardTileSize * PacForm.SpriteScale, j * PacForm.BoardTileSize * PacForm.SpriteScale); } } //Draw ghost house door. Малювання дверей до будинку привидів using (Brush brush = new SolidBrush(Color.FromArgb(255, 255, 181, 255))) { g.FillRectangle(brush, 156 * PacForm.SpriteScale, 188 * PacForm.SpriteScale, 24 * PacForm.SpriteScale, 2 * PacForm.SpriteScale); } } boardPB.Name = "Map"; boardPB.SizeMode = PictureBoxSizeMode.Normal; boardPB.Location = new Point(3, 32); boardPB.Size = boardPBSize; //boardPB.Image = map; mapChanged = AdjustColor(); boardPB.BackgroundImage = map; boardPB.BackColor = Color.Black; form.Controls.Add(boardPB); }
//Usual movement. Звичайний рух void NormalMovement() { switch (direction) { case 0: PacManCollision(); location = new PointF(location.X, location.Y -= speed); if (location.Y % PacForm.boardUnitSize < PacForm.unitCenter) { if (reverseDirection) { reverseDirection = false; ReverseDirection(); } else { direction = nextDirection; location.X = PacForm.coordToPixelCenter(PacForm.pixelToCoord(location)).X; } } PacManCollision(); break; case 1: PacManCollision(); location = new PointF(location.X -= speed, location.Y); if (location.X % PacForm.boardUnitSize < PacForm.unitCenter) { if (reverseDirection) { reverseDirection = false; ReverseDirection(); } else { direction = nextDirection; location.Y = PacForm.coordToPixelCenter(PacForm.pixelToCoord(location)).Y; } } PacManCollision(); break; case 2: PacManCollision(); location = new PointF(location.X, location.Y += speed); if (location.Y % PacForm.boardUnitSize > PacForm.unitCenter) { if (reverseDirection) { reverseDirection = false; ReverseDirection(); } else { direction = nextDirection; location.X = PacForm.coordToPixelCenter(PacForm.pixelToCoord(location)).X; } } PacManCollision(); break; case 3: PacManCollision(); location = new PointF(location.X += speed, location.Y); if (location.X % PacForm.boardUnitSize > PacForm.unitCenter) { if (reverseDirection) { reverseDirection = false; ReverseDirection(); } else { direction = nextDirection; location.Y = PacForm.coordToPixelCenter(PacForm.pixelToCoord(location)).Y; } } PacManCollision(); break; } if (location.X < 0) { location = new PointF(location.X + form.board.boardPBSize.Width, location.Y); } if (location.X >= form.board.boardPBSize.Width) { location = new PointF(location.X - form.board.boardPBSize.Width, location.Y); } }
//Pac-Man's moving logic. Керує логікою руху пакмена public void Move(float elapsed) { if (sleepAfterLunch == 0) { GetLife(); if (energized) { speed = form.levels.speed * form.levels.get_frightPacmanSpeed() * elapsed; } else { speed = form.levels.speed * form.levels.get_pacmanSpeed() * elapsed; } //speed = 3f; form.items.Eat(PacForm.pixelToCoord(location)); if (CanMove(nextDirection)) { direction = nextDirection; } //else nextDirection = direction; if (CanMove(direction)) { moving = true; switch (direction) { case 0: location.Y -= speed; centerX(); break; case 1: location.X -= speed; centerY(); break; case 2: location.Y += speed; centerX(); break; case 3: location.X += speed; centerY(); break; } } else { moving = false; //don't center when game starts if (keyPressed) { centerX(); centerY(); } } if (location.X < 0) { location = new PointF(location.X + form.board.boardPBSize.Width, location.Y); } if (location.X >= form.board.boardPBSize.Width) { location = new PointF(location.X - form.board.boardPBSize.Width, location.Y); } } else { sleepAfterLunch--; } }