« Pygame/Concevoir des jeux avec Pygame » : différence entre les versions

Contenu supprimé Contenu ajouté
ébauche avec ressource
plan en anglais
Ligne 48 :
 
Pour la révision (ça ne peut pas faire de mal), et pour s'assurer que vous êtes familier avec la structure d'un programme python standard, je vais brièvement parcourir un programme python simple, qui n'affichera rien de plus qu'une fenêtre avec un peu de texte à l'intérieur, et qui devrait finalement ressembler à ça (naturellement, la décoration de la fenêtre pourra être différente sur votre système) :
 
 
ICI une image manquante
 
Dans cet exemple, le code complet ressemble à ça :
 
<source lang="python">
#!/usr/bin/python
 
import pygame
from pygame.locals import *
 
def main():
# Initialise screen
pygame.init()
screen = pygame.display.set_mode((150, 50))
pygame.display.set_caption('Basic Pygame program')
 
# Fill background
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((250, 250, 250))
 
# Display some text
font = pygame.font.Font(None, 36)
text = font.render("Hello There", 1, (10, 10, 10))
textpos = text.get_rect()
textpos.centerx = background.get_rect().centerx
background.blit(text, textpos)
 
# Blit everything to the screen
screen.blit(background, (0, 0))
pygame.display.flip()
 
# Event loop
while 1:
for event in pygame.event.get():
if event.type == QUIT:
return
 
screen.blit(background, (0, 0))
pygame.display.flip()
 
 
if __name__ == '__main__': main()
</source>
 
===Basic Pygame objects===
===Blitting===
===The event loop===
===Ta-da!===
 
==Kicking things off==
 
===The first lines, and loading modules===
===Resource handling functions===
 
==Game object classes==
 
===A simple ball class===
 
====Diversion 1: Sprites====
==== Diversion 2: Vector physics====
 
== User-controllable objects==
 
===A simple bat class===
 
===Diversion 3: Pygame events===
 
== Putting it all together==
 
===Let the ball hit sides===
===Let the ball hit bats===
===The Finished product===