コード例 #1
0
ファイル: Ghost.py プロジェクト: Dawid12/Pacman2d
 def moveInDirection(self, direction, walls, teleports):
     move = Move.initWithDirection(Enums.Direction(direction))
     if self.canMove(move, pygame.Rect((self.x, self.y), (18,18)), walls):
         teleport = self.recognizeTeleport(move, pygame.Rect((self.x, self.y), (18,18)), teleports)
         if teleport != None:
             if teleport.left == 0:
                 self.makeMove(Move(500, 0))
             else:
                 self.makeMove(Move(-500, 0))
         else:
             self.makeMove(move)
     else:
         self.makeRandomMove(move, walls, teleports)
     return
コード例 #2
0
ファイル: Ghost.py プロジェクト: Dawid12/Pacman2d
    def makeRandomMove(self, move, walls, teleports):
        moveDirection = list(range(1,5))
        random.shuffle(moveDirection)
        for direction in moveDirection:
            move = Move.initWithDirection(Enums.Direction(direction))
            if self.canMove(move, pygame.Rect((self.x, self.y), (18,18)), walls):
                teleport = self.recognizeTeleport(move, pygame.Rect((self.x, self.y), (18,18)), teleports)
                if teleport != None:
                    if teleport.left == 0:
                        self.makeMove(Move(500, 0))
                    else:
                        self.makeMove(Move(-500, 0))
                else:
                    self.makeMove(move)

                break;
        return
コード例 #3
0
ファイル: Main.py プロジェクト: Dawid12/Pacman2d
from Pacman import Pacman
from Map import Map
from Move import Move
import time
pygame.init()
pygame.font.init()
frames = 30
(screenWidth, screenHeight) = ((560, 720))
pacman = Pacman()
map = Map("data\\map.txt")
map.getMap()
screen = pygame.display.set_mode((screenWidth, screenHeight))
pygame.display.set_caption('Pacman')
clock = pygame.time.Clock()
running = True
pacmanMove = Move.initWithDirection(Enums.Direction.Left)
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    pressed = pygame.key.get_pressed()
    if pressed[pygame.K_UP]:
        pacmanMove = Move.initWithDirection(Enums.Direction.Up)
    elif pressed[pygame.K_DOWN]:
        pacmanMove = Move.initWithDirection(Enums.Direction.Down)
    elif pressed[pygame.K_LEFT]:
        pacmanMove = Move.initWithDirection(Enums.Direction.Left)
    elif pressed[pygame.K_RIGHT]:
        pacmanMove = Move.initWithDirection(Enums.Direction.Right)
    map.spawnFruit(pacman.getPoints(), pacman.getLevel())
    pacman.move(pacmanMove, map.getWalls(), map.getTeleports(), map.getCoins(),