示例#1
0
 def __init__(self, screen, squareSize=30, mapSize=20, drawerParams={}):
     self.screen = screen
     self.players = [
         Player(Objects.Player2, 0, 0),
         Player(Objects.Player1, mapSize - 1, mapSize - 1)
     ]
     self.map = MapModel(mapSize, self.players[0], self.players[1])
     self.players[0].setMap(self.map)
     self.players[1].setMap(self.map)
     self.drawer = MapDrawer(self.map, screen, squareSize, mapSize,
                             **drawerParams)
示例#2
0
class Game:
    def __init__(self, screen, squareSize=30, mapSize=20, drawerParams={}):
        self.screen = screen
        self.players = [
            Player(Objects.Player2, 0, 0),
            Player(Objects.Player1, mapSize - 1, mapSize - 1)
        ]
        self.map = MapModel(mapSize, self.players[0], self.players[1])
        self.players[0].setMap(self.map)
        self.players[1].setMap(self.map)
        self.drawer = MapDrawer(self.map, screen, squareSize, mapSize,
                                **drawerParams)

    def redraw(self, update=True):
        self.drawer.redraw(update)

    def processEvents(self, t):
        """ Processes events, taking into account t seconds have passed since last """
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit(0)
            #if event.type == KEYDOWN and event.key == K_t:
            #    print("CHEAT")
            #    Objects.BombBonus.collectBy(self.player[0])
            #    Objects.Pepper.collectBy(self.player[0])
        self.handleKeys(self.players[0], t, P1_KEYS)
        self.handleKeys(self.players[1], t, P2_KEYS)

    def handleKeys(self, player, t, playerKeys):
        keys = pygame.key.get_pressed()
        pressed = 0
        newDirection = (0, 0)
        for key, direction in zip(playerKeys[:-1], DIRECTIONS):
            if keys[key]:
                pressed += 1
                newDirection = direction
        if keys[playerKeys[-1]]:
            self.map.placeBomb(player)
        if pressed != 1:
            player.setMovement((0, 0))
        else:
            player.setMovement(newDirection)
            player.setDirection(newDirection)

    def update(self, t, update=True):
        " Updates the map and redraws it. Returns True if something on the map was added/removed "
        result = self.map.update(t)
        self.redraw(update)
        return result

    def winners(self):
        return list(filter(lambda p: p.lives == 0, self.players))
示例#3
0
文件: Game.py 项目: macobo/Bomberman
class Game:
    def __init__(self, screen, squareSize = 30, mapSize = 20, drawerParams={}):
        self.screen = screen
        self.players = [Player(Objects.Player2, 0, 0), 
                        Player(Objects.Player1, mapSize-1, mapSize-1)]
        self.map = MapModel(mapSize, self.players[0], self.players[1])
        self.players[0].setMap(self.map)
        self.players[1].setMap(self.map)
        self.drawer = MapDrawer(self.map, screen, squareSize, mapSize, **drawerParams)
    
    def redraw(self, update = True):
        self.drawer.redraw(update)
    
    def processEvents(self, t):
        """ Processes events, taking into account t seconds have passed since last """
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit(0)
            #if event.type == KEYDOWN and event.key == K_t:
            #    print("CHEAT")
            #    Objects.BombBonus.collectBy(self.player[0])
            #    Objects.Pepper.collectBy(self.player[0])
        self.handleKeys(self.players[0], t, P1_KEYS)
        self.handleKeys(self.players[1], t, P2_KEYS)
            
    def handleKeys(self, player, t, playerKeys):
        keys = pygame.key.get_pressed()
        pressed = 0
        newDirection = (0,0)
        for key, direction in zip(playerKeys[:-1], DIRECTIONS):
            if keys[key]:
                pressed += 1
                newDirection = direction
        if keys[playerKeys[-1]]:
            self.map.placeBomb(player)
        if pressed != 1:
            player.setMovement((0,0))
        else:
            player.setMovement(newDirection)
            player.setDirection(newDirection)
    
    def update(self, t, update=True):
        " Updates the map and redraws it. Returns True if something on the map was added/removed "
        result = self.map.update(t)
        self.redraw(update)      
        return result
        
    def winners(self):
        return list(filter(lambda p: p.lives == 0, self.players))
示例#4
0
文件: Game.py 项目: macobo/Bomberman
 def __init__(self, screen, squareSize = 30, mapSize = 20, drawerParams={}):
     self.screen = screen
     self.players = [Player(Objects.Player2, 0, 0), 
                     Player(Objects.Player1, mapSize-1, mapSize-1)]
     self.map = MapModel(mapSize, self.players[0], self.players[1])
     self.players[0].setMap(self.map)
     self.players[1].setMap(self.map)
     self.drawer = MapDrawer(self.map, screen, squareSize, mapSize, **drawerParams)