Python Forum

Full Version: help with game
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
You can use multiple keys. One for you and one for others.
# moving ship
    get_key = lambda key: Game.keys_press.get(key, False)
    if get_key('a') or get_key('Left'):
        Game.canvas.move(Game.ship, -Game.ship_speed, 0)
    if get_key('d') or get_key('Right'):
        Game.canvas.move(Game.ship, Game.ship_speed, 0)
    if get_key('w') or get_key('Up'):
        Game.canvas.move(Game.ship, 0, -Game.ship_speed)
    if get_key('s') or get_key('Down'):
        Game.canvas.move(Game.ship, 0, Game.ship_speed)
    if Game.keys_press.get('space', False):
        if pauser_elaspe(Game.shoot_pauser, Game.ticks):
            shoot()
If you don't know lambda does. It makes a quick simple function.
get_key = lambda key: Game.keys_press.get(key, False)
equal to
def get_key(key):
    return Game.keys_press.get(key, False)
Thank you :)
Pages: 1 2 3 4 5