ARGH
[matches/honours.git] / research / transmission_spectroscopy / simulator / pgu-0.18 / examples / tilevid2.py
1 """<title>tutorial on how to scroll and use a Timer object</title>"""
2
3 import pygame
4 from pygame.locals import *
5
6 # the following line is not needed if pgu is installed
7 import sys; sys.path.insert(0, "..")
8
9 from pgu import tilevid, timer
10
11 SW,SH = 320,240
12 TW,TH = 16,16
13 SPEED = 2
14 FPS = 40
15
16 def init():
17     g = tilevid.Tilevid()
18     
19     g.screen = pygame.display.set_mode((SW,SH),SWSURFACE)
20     
21     g.tga_load_tiles('tiles.tga',(TW,TH))
22     
23     ##In init(), I add bg=1 to tga_load_level so that the background layer is
24     ##also loaded.
25     ##::
26     g.tga_load_level('level.tga',1)
27     ##
28     
29     ##In init(), I also set the bounds of the level.  The view will never go
30     ##outside the bounds of the level.
31     ##::
32     g.bounds = pygame.Rect(TW,TH,(len(g.tlayer[0])-2)*TW,(len(g.tlayer)-2)*TH)
33     ##
34     
35     return g
36
37 def run(g): 
38     g.quit = 0
39     
40     ##In run(), I add a Timer so that I can keep a constant framerate of FPS fps.
41     ##::
42     t = timer.Timer(FPS)
43     ##
44     
45     g.paint(g.screen)
46     pygame.display.flip()
47     
48     while not g.quit:
49         for e in pygame.event.get():
50             if e.type is QUIT: g.quit = 1
51             if e.type is KEYDOWN and e.key == K_ESCAPE: g.quit = 1
52             
53         ##In run(), each frame I move the view to the right by SPEED pixels.
54         ##::
55         g.view.x += SPEED
56         ##
57         
58         g.loop()
59         updates = g.update(g.screen)
60         pygame.display.update(updates)
61         
62         ##In run(), at the end of each frame, I give the timer a tick.  The timer will delay the 
63         ##appropriate length.
64         ##::
65         t.tick()
66         ##
67     
68 run(init())

UCC git Repository :: git.ucc.asn.au