Esempio n. 1
0
 def move(self):
     self.player.move(self.SCREEN)
     for ghost in self.all_ghosts:
         ghost.move(self.player.current_tile, self.SCREEN,
                    self.power_points_infos)
Esempio n. 2
0
        player.moveUp(map)
    if pressed[pygame.K_DOWN]:
        player.moveDown(map)
    if pressed[pygame.K_LEFT]:
        player.moveLeft(map)
    if pressed[pygame.K_RIGHT]:
        player.moveRigth(map)
    if pressed[pygame.K_ESCAPE]:
        done = True

    if map[player.y / 30][player.x / 30] == 2:
        map[player.y / 30][player.x / 30] = 1
        score += 100

    for ghost in ghosts:
        ghost.move(map)

    screen.fill((0, 0, 0))
    map_y = len(map[0])
    map_x = len(map)
    for a in xrange(map_y):
        for b in xrange(map_x):
            if map[b][a] == 0:
                pygame.draw.rect(screen, (0, 0, 255), pygame.Rect(a * 30, b * 30, 30, 30))
            if map[b][a] == 1:
                pygame.draw.rect(screen, (0, 0, 0), pygame.Rect(a * 30, b * 30, 30, 30))
            if map[b][a] == 2:
                pygame.draw.circle(screen, (255, 255, 255), (a * 30 + 15, b * 30 + 15), 5, 0)
    player.draw(screen)
    if level.ispoints():
        print "win"
Esempio n. 3
0
import pacman
from game import game
import ghost

game = game()
pacman = pacman.pacman(1, 1, game.grid)
ghost = ghost.ghost(len(game.grid) - 2, len(game.grid[0]) - 2, game.grid)

while not game.win:
    game.show()  #shows the current state of the grid
    if game.remainingDots == 0:
        game.win = True
    if not pacman.alive:
        print("YOU DIED")
        print("GAME OVER")
        break
    if game.win:
        print("YOU WIN")
        break
    dir = input('enter a direction(wasd): ')
    pacman.move(dir, game.grid, game)
    ghost.calculatePath(pacman)
    ghost.move(ghost.direction, game.grid, pacman)
Esempio n. 4
0
    def PokrenutiNaPocetku(self):

        if self.tt < 10:
            if self.tt == 0:
                self.ghost1.x1 = 4.20
                self.ghost1.way1 = 4
                self.ghost2.x1 = 4.20
                self.ghost2.way1 = 4

            g.move(self.tiles, self.ghost1, self.player1, self.player2,
                   self.opcija)
            g.move(self.tiles, self.ghost2, self.player1, self.player2,
                   self.opcija)

        elif self.tt >= 10 and self.tt < 20:
            if self.tt == 10:
                self.ghost1.x1 = 4.20
                self.ghost1.way1 = 4
                self.ghost2.y1 = -4.20
                self.ghost2.way1 = 1
            g.move(self.tiles, self.ghost1, self.player1, self.player2,
                   self.opcija)
            g.move(self.tiles, self.ghost2, self.player1, self.player2,
                   self.opcija)

        elif self.tt >= 20 and self.tt < 30:
            if self.tt == 20:
                self.ghost3.x1 = -4.20
                self.ghost3.way1 = 3
                self.ghost4.x1 = -4.20
                self.ghost4.way1 = 3
                self.ghost1.y1 = -4.20
                self.ghost1.way1 = 1

            g.move(self.tiles, self.ghost2, self.player1, self.player2,
                   self.opcija)
            g.move(self.tiles, self.ghost3, self.player1, self.player2,
                   self.opcija)
            g.move(self.tiles, self.ghost4, self.player1, self.player2,
                   self.opcija)
            g.move(self.tiles, self.ghost1, self.player1, self.player2,
                   self.opcija)

        elif self.tt >= 30 and self.tt < 40:
            if self.tt == 30:
                self.ghost3.y1 = -4.20
                self.ghost3.way1 = 1
                self.ghost4.x1 = -4.20
                self.ghost4.way1 = 3

            g.move(self.tiles, self.ghost1, self.player1, self.player2,
                   self.opcija)
            g.move(self.tiles, self.ghost2, self.player1, self.player2,
                   self.opcija)
            g.move(self.tiles, self.ghost3, self.player1, self.player2,
                   self.opcija)
            g.move(self.tiles, self.ghost4, self.player1, self.player2,
                   self.opcija)

        elif self.tt == 40:
            self.ghost4.y1 = -4.20
            self.ghost4.way1 = 1

            g.move(self.tiles, self.ghost1, self.player1, self.player2,
                   self.opcija)
            g.move(self.tiles, self.ghost2, self.player1, self.player2,
                   self.opcija)
            g.move(self.tiles, self.ghost3, self.player1, self.player2,
                   self.opcija)
            g.move(self.tiles, self.ghost4, self.player1, self.player2,
                   self.opcija)

        self.tt = self.tt + 1
        self.update()
Esempio n. 5
0
    def ghost_move(self, ghost):
        """"""
        # TODO TESTS !!!!!!!!!
        directions = self.board.knots.get((ghost.pos_x, ghost.pos_z))

        if not ghost.was_eaten:

            if directions:
                if len(directions) > 1:
                    if ghost.next_direction in directions:
                        ghost.direction = ghost.next_direction
                        # TODO tę metodę trzeba poprawić
                        ghost.choice_next_direction()
                        ghost.move()
                    elif ghost.direction in directions:
                        ghost.move()
                    else:
                        ghost.choice_next_direction()

                elif len(directions) == 1:
                    ghost.direction = directions
                    ghost.choice_next_direction()
                    ghost.move()
            else:
                ghost.move()

        else:
            if ghost.the_way:
                if directions:
                    ghost.direction = ghost.the_way[0]
                    ghost.move()
                    ghost.the_way = ghost.the_way[1:]
                else:
                    ghost.move()

            else:
                if directions:
                    ghost.find_path(self.board.maze_graph,
                                    self.board.ghost_nest_position)
                    ghost.direction = ghost.the_way[0]
                    ghost.move()
                    ghost.the_way = ghost.the_way[1:]

                else:
                    ghost.move()

            if (ghost.pos_z, ghost.pos_x) == self.board.ghost_nest_position:
                ghost.start_from_nest()