Пример #1
0
def process_events():
    global spaceHold, player, currHold,currHoldU,currHoldR,currHoldD,currHoldL, shotCount, game_over, playerColor
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            quit_game = True
            return True
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                player.changespeed(-3,0)
                currHold += currHoldL
                if spaceHold == False:
                    shotDir = shotDirL
            elif event.key == pygame.K_RIGHT:
                player.changespeed(3,0)
                currHold += currHoldR
                if spaceHold == False:
                    shotDir = shotDirR
            elif event.key == pygame.K_UP:
                player.changespeed(0,-3)
                currHold += currHoldU
                if spaceHold == False:
                    shotDir = shotDirU
            elif event.key == pygame.K_DOWN:
                player.changespeed(0,3)
                currHold += currHoldD
                if spaceHold == False:
                    shotDir = shotDirD
            elif event.key == pygame.K_SPACE:
                spaceHold = True
                if currHold != 0:
                    shotDir = currHold
            elif event.key == pygame.K_LSHIFT or event.key == pygame.K_RSHIFT:
                #player = switchPlayerColor(player)
                if playerColor == 0:
                    playerColor = 1
                    newPlayer = player.Player(colors.RED, player.getX(), player.getY())
                    newPlayer.setSpeed(player.getChangeX(), player.getChangeY())
                    for p in Lists.player_list:
                        p.remove()
                        p.kill()
                    player = newPlayer
                    Lists.player_list.add(player)
                    Lists.all_sprites_list.add(player)
                elif playerColor == 1:
                    playerColor = 0
                    newPlayer = player.Player(colors.BLUE, player.getX(), player.getY())
                    newPlayer.setSpeed(player.getChangeX(), player.getChangeY())
                    for p in Lists.player_list:
                        p.remove()
                        p.kill()
                    player = newPlayer
                    Lists.player_list.add(player)
                    Lists.all_sprites_list.add(player)
#                     if game_over:
#                         #this resets to a new instance of the game if game over is true and the space bar is pressed
#                         self.__init__()

        # Reset speed when key goes up
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT:
                currHold -= currHoldL
                player.changespeed(3,0)
            elif event.key == pygame.K_RIGHT:
                currHold -= currHoldR
                player.changespeed(-3,0)
            elif event.key == pygame.K_UP:
                currHold -= currHoldU
                player.changespeed(0,3)
            elif event.key == pygame.K_DOWN:
                currHold -= currHoldD
                player.changespeed(0,-3)
            elif event.key == pygame.K_SPACE:
                shotCount = 0
                spaceHold = False

    #method that handles bullet generation. Spawning the bullets based on
    #current held directio  or last preivously held direction. Also has
    #a shot clock to prevent bullets from coming out as a constant stream
    if spaceHold:
        if wavePower:
            if shotCount == 0:
                bullets.fireWave(player)
                shotCount = 1
            elif shotCount == 15:
                shotCount = 0
            else:
                shotCount +=1
        else:
            if shotCount == 0:
                bullets.fireNorm(player)

                shotCount = 1
            elif shotCount == 8:
                shotCount = 0
            else:
                shotCount +=1
    if game_over:
        return True
    else:
        return False
Пример #2
0
    def process_events(self):


        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                constants.quit_game = True
                return True
            elif event.type == pygame.KEYDOWN:
                ## quit keyes
                if event.key == pygame.K_BACKSPACE or event.key == pygame.K_ESCAPE:
                    constants.quit_game = True
                    return True
                if event.key == pygame.K_LEFT:
                    constants.player.changespeed(-3,0)
                    constants.currHold += constants.currHoldL
                    if constants.spaceHold == False:
                        constants.shotDir = constants.shotDirL
                elif event.key == pygame.K_RIGHT:
                    constants.player.changespeed(3,0)
                    constants.currHold += constants.currHoldR
                    if constants.spaceHold == False:
                        constants.shotDir = constants.shotDirR
                elif event.key == pygame.K_UP:
                    constants.player.changespeed(0,-3)
                    constants.currHold += constants.currHoldU
                    if constants.spaceHold == False:
                        constants.shotDir = constants.shotDirU
                elif event.key == pygame.K_DOWN:
                    constants.player.changespeed(0,3)
                    constants.currHold += constants.currHoldD
                    if constants.spaceHold == False:
                        constants.shotDir = constants.shotDirD
                elif event.key == pygame.K_SPACE:
                    constants.spaceHold = True
                    if constants.currHold != 0:
                        constants.shotDir = constants.currHold
                elif (event.key == pygame.K_LSHIFT or event.key == pygame.K_RSHIFT) and (constants.activeMode == 2):
                    #constants.player = constants.switchPlayerColor(constants.player)
                    if constants.playerColor == 0:
                        constants.playerColor = 1
                        newPlayer = player.Player(colors.RED, constants.player.getX(), constants.player.getY())
                        newPlayer.setSpeed(constants.player.getChangeX(), constants.player.getChangeY())
                        for p in Lists.player_list:
                            p.remove()
                            p.kill()
                        constants.player = newPlayer
                        Lists.player_list.add(constants.player)
                        Lists.all_sprites_list.add(constants.player)
                    elif constants.playerColor == 1:
                        constants.playerColor = 0
                        newPlayer = player.Player(colors.BLUE, constants.player.getX(), constants.player.getY())
                        newPlayer.setSpeed(constants.player.getChangeX(), constants.player.getChangeY())
                        for p in Lists.player_list:
                            p.remove()
                            p.kill()
                        constants.player = newPlayer
                        Lists.player_list.add(constants.player)
                        Lists.all_sprites_list.add(constants.player)
#                     if constants.game_over:
#                         #this resets to a new instance of the game if game over is true and the space bar is pressed
#                         self.__init__()

            # Reset speed when key goes up
            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT:
                    constants.currHold -= constants.currHoldL
                    constants.player.changespeed(3,0)
                elif event.key == pygame.K_RIGHT:
                    constants.currHold -= constants.currHoldR
                    constants.player.changespeed(-3,0)
                elif event.key == pygame.K_UP:
                    constants.currHold -= constants.currHoldU
                    constants.player.changespeed(0,3)
                elif event.key == pygame.K_DOWN:
                    constants.currHold -= constants.currHoldD
                    constants.player.changespeed(0,-3)
                elif event.key == pygame.K_SPACE:
                    constants.shotCount = 0
                    constants.spaceHold = False

        #method that handles bullet generation. Spawning the bullets based on
        #current held directio  or last preivously held direction. Also has
        #a shot clock to prevent bullets from coming out as a constant stream
        if constants.spaceHold:
            if self.wavePower:
                if constants.shotCount == 0:
                    bullets.fireWave(constants.player)
                    constants.shotCount = 1
                elif constants.shotCount == 15:
                    constants.shotCount = 0
                else:
                    constants.shotCount +=1
            else:
                if constants.shotCount == 0:
                    bullets.fireNorm(constants.player)

                    constants.shotCount = 1
                elif constants.shotCount == 8:
                    constants.shotCount = 0
                else:
                    constants.shotCount +=1
        if constants.game_over:
            return True
        else:
            return False