4cf9b8d2192e0c5e99f11ea32f2ce30ddc54d311
[matches/honours.git] / research / transmission_spectroscopy / simulator / pgu-0.18 / examples / tilevid1.py
1 """<title>tutorial on how to load tiles and levels</title>
2
3 <p>The following tutorial demonstrates how to use tileedit and leveledit via the
4 command line.  You can just as easily do all these things via the in-program
5 "File/Open" and "File/New" menu items.
6
7 <p>Here's an introduction to using tileedit and leveledit
8 <pre>$ -- linux, etc instructions
9 C:\> -- windows instructions</pre>
10
11 <p>first you need to be in the examples dir for this tutorial to
12 work
13
14 <pre>$ cd examples
15 C:\pgu> cd examples
16
17 $ tileedit tiles.tga 16 16
18 C:\pgu\examples> python ../scripts/tileedit tiles.tga 16 16</pre>
19
20 <p>the next time you run tileedit, you will not need to provide 
21 the width and height of the tiles
22
23 <pre>$ tileedit codes.tga 16 16
24 C:\pgu\examples> python ../scripts/tileedit codes.tga 16 16</pre>
25
26 <p>the next time you run tileedit, you will not need to provide 
27 the width and height of the codes
28
29 <pre>$ leveledit level.tga tiles.tga codes.tga 16 16
30 C:\pgu\examples> python ../scripts/leveledit level.tga tiles.tga codes.tga 16 16</pre>
31
32 <p>the next time you run leveledit, you will not need to provide
33 the tiles, codes, and width and height of the tiles
34
35 """
36
37
38
39
40 import pygame
41 from pygame.locals import *
42
43 # the following line is not needed if pgu is installed
44 import sys; sys.path.insert(0, "..")
45
46 from pgu import tilevid
47
48 SW,SH = 320,240
49 TW,TH = 16,16
50
51 ##This is the initialization function I created for
52 ##the game.
53 ##
54 ##I use the tga_ methods to load up the tiles and level I created.
55 ##::
56 def init():
57     g = tilevid.Tilevid()
58
59     g.screen = pygame.display.set_mode((SW,SH),SWSURFACE)
60     
61     g.tga_load_tiles('tiles.tga',(TW,TH))
62     g.tga_load_level('level.tga')
63
64     return g
65 ##
66     
67 ##This is the run function I created for the game.  In this example,
68 ##the level is displayed, but there is no interaction (other than allowing the
69 ##user to quit via ESC or the QUIT signal.
70 ##::
71 def run(g): 
72     g.quit = 0
73     
74     g.paint(g.screen)
75     pygame.display.flip()
76     
77     while not g.quit:
78         for e in pygame.event.get():
79             if e.type is QUIT: g.quit = 1
80             if e.type is KEYDOWN and e.key == K_ESCAPE: g.quit = 1
81         
82         g.loop()
83         updates = g.update(g.screen)
84         pygame.display.update(updates)
85 ##    
86     
87 run(init())

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