1 """<title>an example of engine usage</title>"""
4 from pygame.locals import *
6 # the following line is not needed if pgu is installed
7 import sys; sys.path.insert(0, "..")
13 screen = pygame.display.set_mode((320,240),SWSURFACE)
15 class Red(engine.State):
20 if e.type is KEYDOWN: return Green(self.game)
22 class Green(engine.State):
27 if e.type is KEYDOWN: return Blue(self.game)
29 ##A state may subclass engine.State.
31 class Blue(engine.State):
33 ##The init method should load data, etc. The __init__ method
34 ##should do nothing but record the parameters. If the init method
35 ##returns a value, it becomes the new state.
38 self.image = pygame.image.load("cuzco.png")
42 ##The paint method is called once. If you call repaint(), it
43 ##will be called again.
47 s.blit(self.image,self.pos)
50 ##Every time an event occurs, event is called. If the event method
51 ##returns a value, it will become the new state.
54 if e.type is KEYDOWN: return Red(self.game)
56 ##Loop is called once a frame. It should contain all the
57 ##logic. If the loop method returns a value it will become the
62 self.pos = self.pos[0]+1,self.pos[1]+1
64 ##Update is called once a frame. It should update the display.
66 def update(self,screen):
67 screen.fill((0,0,255),pygame.Rect(self._pos[0],self._pos[1],self.image.get_width(),self.image.get_height()))
68 screen.blit(self.image,self.pos)
69 pygame.display.flip() #better to do updates
73 game.run(Red(game),screen)