Moving a square:
For starters, create a program in which we can move a box around the screen with the arrow keys.
- Two ways to get events:
- polling the device
- using sdl events
Functions:
-
init: pygame.init() or pygame.*.init()
-
screen = pygame.display.set_mode(size)
-
screen functions:
- blit(screen, rect)
- fill(color)
-
loading & converting images: (surfaces) image = pygame.image.load('player.bmp').convert()
-
Keyboard input:
event.KEYDOWN and KEYUP when key pressed. event.key indicates which key http://www.pygame.org/docs/ref/key.html
for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: print event.key
Template for a working pygame program:
- Get it from the gp2x wiki.
- extract.
- use the example to set up the environment before launching python programs.
pygame.display.set_mode((320, 240), 0, 16)
- how to get input?