Exemple #1
0
        # check for closing window
        if e.type == pg.QUIT or (e.type == pg.KEYDOWN
                                 and e.key == pg.K_ESCAPE):
            game = False
        if e.type == pg.KEYDOWN and e.key == pg.K_LEFT:
            player1.goLeft = True
        elif e.type == pg.KEYUP and e.key == pg.K_LEFT:
            player1.goLeft = False
        elif e.type == pg.KEYDOWN and e.key == pg.K_RIGHT:
            player1.goRight = True
        elif e.type == pg.KEYUP and e.key == pg.K_RIGHT:
            player1.goRight = False
        elif e.type == pg.KEYDOWN and e.key == pg.K_UP:
            player1.goUp = True
        elif e.type == pg.KEYUP and e.key == pg.K_UP:
            player1.goUp = False
        elif e.type == pg.KEYDOWN and e.key == pg.K_DOWN:
            player1.goDown = True
        elif e.type == pg.KEYUP and e.key == pg.K_DOWN:
            player1.goDown = False

    player1.update()
    worldPhisics(player1)
    wallGroup.draw(mainScreen)
    prixGroup.draw(mainScreen)
    enemyGroup.draw(mainScreen)
    player1.draw(mainScreen)
    pg.display.flip()

pg.quit()
Exemple #2
0
    for event in pygame.event.get():
        # Check for KEYDOWN event
        if event.type == KEYDOWN:
            # If the Esc key is pressed, then exit the main loop
            if event.key == K_ESCAPE:
                running = False
        # Check for QUIT event. If QUIT, then set running to false.
        if event.type == QUIT:
            running = False

    screen.blit(background, (0, 0))  # SCENE
    display_score(player, screen)  # SCORE

    ############### HANDLE PLAYER MOVEMENT ###############################
    pressed_keys = pygame.key.get_pressed()
    player.update(pressed_keys)

    try:
        axis_x = joystick.get_axis(2)
        axis_y = joystick.get_axis(3)

        x_change = make_coordinate(axis_x)
        y_change = make_coordinate(axis_y)

        slow_button = joystick.get_button(4)
        fast_button = joystick.get_button(5)
        player.speed = PLAYER_SPEED + fast_button * 10 - slow_button * 2
        player.rect.move_ip(x_change * player.speed, y_change * player.speed)

    except:
        player.speed = PLAYER_SPEED