Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17625

Discover Python and Patterns (10): Keyboard

$
0
0

Thanks to the Pygame library we installed in the previous post, we can draw 2D graphics. In this post, I propose to introduce controls with the keyboard as well as some improvements like window centering and frame rate handling.

This post is part of the Discover Python and Patterns series

Keyboard events

Pygame events allow the capture of keyboard presses:

import pygame

pygame.init()
window = pygame.display.set_mode((640,480))

x = 120
y = 120
running = True
while running:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            break
        elif event.type == pygame.KEYDOWN:
            if event.key …

Viewing all articles
Browse latest Browse all 17625

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>