Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected override bool ProcessCmdKey(ref Message msg, Keys keyData) // Работа с кнопками-стрелками на клавиатуре
- //(перемещение персонажа с учётом стен, дверей и декоративных объектов)
- {
- switch (keyData)
- {
- case Keys.Left:
- {
- changeRoom();
- if (!Core.clash(hero.posX - 5, hero.posY, allObjects))
- {
- hero.posX -= 5; // Игрок у меня перемещается на 5 пикселей при нажатии на стрелочку
- Invalidate();
- }
- Core.touchTheDoor(allDoors, hero, previousRoom, currentRoom);
- // Метод touchTheDoor не имеет отношения к танкам, это про закрывание дверей
- break;
- }
- case Keys.Right:
- {
- changeRoom();
- if (!Core.clash(hero.posX + 5, hero.posY, allObjects))
- {
- hero.posX += 5;
- Invalidate();
- }
- Core.touchTheDoor(allDoors, hero, previousRoom, currentRoom);
- break;
- }
- case Keys.Up:
- {
- changeRoom();
- if (!Core.clash(hero.posX, hero.posY - 5, allObjects))
- {
- hero.posY -= 5;
- Invalidate();
- }
- Core.touchTheDoor(allDoors, hero, previousRoom, currentRoom);
- break;
- }
- case Keys.Down:
- {
- changeRoom();
- if (!Core.clash(hero.posX, hero.posY + 5, allObjects))
- {
- hero.posY += 5;
- Invalidate();
- }
- Core.touchTheDoor(allDoors, hero, previousRoom, currentRoom);
- break;
- }
- default: return base.ProcessCmdKey(ref msg, keyData);
- }
- return true;
- }
- // Метод Core.Clash :
- public static bool clash(int ulX, int ulY, List<GameElements.Stuff.ScenicObject> Objects) // ul - up left
- {
- int playerWidth = 25;
- System.Drawing.Rectangle heroBounds = new System.Drawing.Rectangle(ulX, ulY, playerWidth, playerWidth);
- System.Drawing.Rectangle obctBounds;
- foreach (GameElements.Stuff.ScenicObject obct in Objects)
- {
- if (!obct.noclip)
- {
- obctBounds = new System.Drawing.Rectangle(obct.X, obct.Y+3, obct.Width-3, obct.Height-6);
- if (heroBounds.IntersectsWith(obctBounds))
- {
- return true;
- }
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement