Mercurial > pygame
annotate examples/testsprite.py @ 3172:d1b367fc08bc tests-returncode
Use a return code of 1 when the tests fail.
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 10:13:57 +0000 |
| parents | 9126dee1087d |
| children |
| rev | line source |
|---|---|
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
2 # like the testsprite.c that comes with sdl, this pygame version shows |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
3 # lots of sprites moving around. |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
4 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
5 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
6 import pygame, sys, os |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
7 from pygame.locals import * |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
8 from random import randint |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
9 from time import time |
|
660
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
10 import pygame.joystick |
|
1572
9126dee1087d
adapt joystick and cdrom modules for Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1568
diff
changeset
|
11 from pygame.compat import xrange_ |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
12 |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
13 ##import FastRenderGroup as FRG |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
14 import pygame.sprite as FRG |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
15 |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
16 if "-psyco" in sys.argv: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
17 try: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
18 import psyco |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
19 psyco.full() |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
20 except Exception: |
|
1568
c35441d4f466
allow all Python modules to install with Python 3.1, though some may not work correctly
Lenard Lindstrom <len-l@telus.net>
parents:
1447
diff
changeset
|
21 print ("No psyco for you! psyco failed to import and run.") |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
22 |
|
1427
a6e94e964a69
examples can be run from outside the examples directory
Lenard Lindstrom <len-l@telus.net>
parents:
949
diff
changeset
|
23 main_dir = os.path.split(os.path.abspath(__file__))[0] |
|
a6e94e964a69
examples can be run from outside the examples directory
Lenard Lindstrom <len-l@telus.net>
parents:
949
diff
changeset
|
24 data_dir = os.path.join(main_dir, 'data') |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
25 |
|
1432
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
26 |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
27 |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
28 |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
29 |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
30 |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
31 # use this to use update rects or not. |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
32 # If the screen is mostly full, then update rects are not useful. |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
33 update_rects = True |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
34 if "-update_rects" in sys.argv: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
35 update_rects = True |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
36 if "-noupdate_rects" in sys.argv: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
37 update_rects = False |
|
1432
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
38 |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
39 use_static = False |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
40 if "-static" in sys.argv: |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
41 use_static = True |
|
1432
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
42 |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
43 |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
44 use_FastRenderGroup = False |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
45 if "-FastRenderGroup" in sys.argv: |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
46 update_rects = True |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
47 use_FastRenderGroup = True |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
48 |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
49 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
50 flags = 0 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
51 if "-flip" in sys.argv: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
52 flags ^= DOUBLEBUF |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
53 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
54 if "-fullscreen" in sys.argv: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
55 flags ^= FULLSCREEN |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
56 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
57 if "-sw" in sys.argv: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
58 flags ^= SWSURFACE |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
59 |
|
660
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
60 use_rle = True |
|
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
61 |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
62 if "-hw" in sys.argv: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
63 flags ^= HWSURFACE |
|
660
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
64 use_rle = False |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
65 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
66 |
|
664
204502f6e7da
Fixed up the height and width command line paramaters.
Rene Dudfield <renesd@gmail.com>
parents:
660
diff
changeset
|
67 screen_dims = [640, 480] |
|
204502f6e7da
Fixed up the height and width command line paramaters.
Rene Dudfield <renesd@gmail.com>
parents:
660
diff
changeset
|
68 |
|
204502f6e7da
Fixed up the height and width command line paramaters.
Rene Dudfield <renesd@gmail.com>
parents:
660
diff
changeset
|
69 if "-height" in sys.argv: |
|
204502f6e7da
Fixed up the height and width command line paramaters.
Rene Dudfield <renesd@gmail.com>
parents:
660
diff
changeset
|
70 i = sys.argv.index("-height") |
|
204502f6e7da
Fixed up the height and width command line paramaters.
Rene Dudfield <renesd@gmail.com>
parents:
660
diff
changeset
|
71 screen_dims[1] = int(sys.argv[i+1]) |
|
204502f6e7da
Fixed up the height and width command line paramaters.
Rene Dudfield <renesd@gmail.com>
parents:
660
diff
changeset
|
72 |
|
204502f6e7da
Fixed up the height and width command line paramaters.
Rene Dudfield <renesd@gmail.com>
parents:
660
diff
changeset
|
73 if "-width" in sys.argv: |
|
204502f6e7da
Fixed up the height and width command line paramaters.
Rene Dudfield <renesd@gmail.com>
parents:
660
diff
changeset
|
74 i = sys.argv.index("-width") |
|
204502f6e7da
Fixed up the height and width command line paramaters.
Rene Dudfield <renesd@gmail.com>
parents:
660
diff
changeset
|
75 screen_dims[0] = int(sys.argv[i+1]) |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
76 |
|
772
7bf7fcda9328
added a command line flag for using alpha.
Rene Dudfield <renesd@gmail.com>
parents:
664
diff
changeset
|
77 if "-alpha" in sys.argv: |
|
7bf7fcda9328
added a command line flag for using alpha.
Rene Dudfield <renesd@gmail.com>
parents:
664
diff
changeset
|
78 use_alpha = True |
|
7bf7fcda9328
added a command line flag for using alpha.
Rene Dudfield <renesd@gmail.com>
parents:
664
diff
changeset
|
79 else: |
|
7bf7fcda9328
added a command line flag for using alpha.
Rene Dudfield <renesd@gmail.com>
parents:
664
diff
changeset
|
80 use_alpha = False |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
81 |
|
1568
c35441d4f466
allow all Python modules to install with Python 3.1, though some may not work correctly
Lenard Lindstrom <len-l@telus.net>
parents:
1447
diff
changeset
|
82 print (screen_dims) |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
83 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
84 |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
85 ##class Thingy(pygame.sprite.Sprite): |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
86 ## images = None |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
87 ## def __init__(self): |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
88 ## pygame.sprite.Sprite.__init__(self) |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
89 ## self.image = Thingy.images[0] |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
90 ## self.rect = self.image.get_rect() |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
91 ## self.rect.x = randint(0, screen_dims[0]) |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
92 ## self.rect.y = randint(0, screen_dims[1]) |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
93 ## #self.vel = [randint(-10, 10), randint(-10, 10)] |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
94 ## self.vel = [randint(-1, 1), randint(-1, 1)] |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
95 ## |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
96 ## def move(self): |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
97 ## for i in [0, 1]: |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
98 ## nv = self.rect[i] + self.vel[i] |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
99 ## if nv >= screen_dims[i] or nv < 0: |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
100 ## self.vel[i] = -self.vel[i] |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
101 ## nv = self.rect[i] + self.vel[i] |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
102 ## self.rect[i] = nv |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
103 |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
104 class Thingy(FRG.DirtySprite): |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
105 images = None |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
106 def __init__(self): |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
107 ## pygame.sprite.Sprite.__init__(self) |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
108 FRG.DirtySprite.__init__(self) |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
109 self.image = Thingy.images[0] |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
110 self.rect = self.image.get_rect() |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
111 self.rect.x = randint(0, screen_dims[0]) |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
112 self.rect.y = randint(0, screen_dims[1]) |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
113 #self.vel = [randint(-10, 10), randint(-10, 10)] |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
114 self.vel = [randint(-1, 1), randint(-1, 1)] |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
115 self.dirty = 2 |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
116 |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
117 def update(self): |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
118 for i in [0, 1]: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
119 nv = self.rect[i] + self.vel[i] |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
120 if nv >= screen_dims[i] or nv < 0: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
121 self.vel[i] = -self.vel[i] |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
122 nv = self.rect[i] + self.vel[i] |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
123 self.rect[i] = nv |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
124 |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
125 class Static(FRG.DirtySprite): |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
126 images = None |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
127 def __init__(self): |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
128 FRG.DirtySprite.__init__(self) |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
129 self.image = Static.images[0] |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
130 self.rect = self.image.get_rect() |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
131 self.rect.x = randint(0, 3*screen_dims[0]/4) |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
132 self.rect.y = randint(0, 3*screen_dims[1]/4) |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
133 |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
134 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
135 |
|
1432
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
136 def main(update_rects = True, |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
137 use_static = False, |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
138 use_FastRenderGroup = False, |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
139 screen_dims = [640, 480], |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
140 use_alpha = False, |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
141 flags = 0, |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
142 ): |
|
1447
4e990d6a8285
make the main function consistent accross examples, taking arguments
Lenard Lindstrom <len-l@telus.net>
parents:
1432
diff
changeset
|
143 """Show lots of sprites moving around |
|
4e990d6a8285
make the main function consistent accross examples, taking arguments
Lenard Lindstrom <len-l@telus.net>
parents:
1432
diff
changeset
|
144 |
|
4e990d6a8285
make the main function consistent accross examples, taking arguments
Lenard Lindstrom <len-l@telus.net>
parents:
1432
diff
changeset
|
145 Optional keyword arguments: |
|
4e990d6a8285
make the main function consistent accross examples, taking arguments
Lenard Lindstrom <len-l@telus.net>
parents:
1432
diff
changeset
|
146 update_rects - use the RenderUpdate sprite group class (default True) |
|
4e990d6a8285
make the main function consistent accross examples, taking arguments
Lenard Lindstrom <len-l@telus.net>
parents:
1432
diff
changeset
|
147 use_static - include non-moving images (default False) |
|
4e990d6a8285
make the main function consistent accross examples, taking arguments
Lenard Lindstrom <len-l@telus.net>
parents:
1432
diff
changeset
|
148 use_FastRenderGroup - Use the FastRenderGroup sprite group (default False) |
|
4e990d6a8285
make the main function consistent accross examples, taking arguments
Lenard Lindstrom <len-l@telus.net>
parents:
1432
diff
changeset
|
149 screen_dims - Pygame window dimensions (default [640, 480]) |
|
4e990d6a8285
make the main function consistent accross examples, taking arguments
Lenard Lindstrom <len-l@telus.net>
parents:
1432
diff
changeset
|
150 use_alpha - use alpha blending (default False) |
|
4e990d6a8285
make the main function consistent accross examples, taking arguments
Lenard Lindstrom <len-l@telus.net>
parents:
1432
diff
changeset
|
151 flags - additional display mode flags (default no addiontal flags) |
|
4e990d6a8285
make the main function consistent accross examples, taking arguments
Lenard Lindstrom <len-l@telus.net>
parents:
1432
diff
changeset
|
152 |
|
4e990d6a8285
make the main function consistent accross examples, taking arguments
Lenard Lindstrom <len-l@telus.net>
parents:
1432
diff
changeset
|
153 """ |
|
1432
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
154 |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
155 if use_FastRenderGroup: |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
156 update_rects = True |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
157 |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
158 |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
159 #pygame.init() |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
160 pygame.display.init() |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
161 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
162 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
163 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
164 #if "-fast" in sys.argv: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
165 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
166 screen = pygame.display.set_mode(screen_dims, flags) |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
167 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
168 |
|
660
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
169 # this is mainly for GP2X, so it can quit. |
|
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
170 pygame.joystick.init() |
|
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
171 num_joysticks = pygame.joystick.get_count() |
|
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
172 if num_joysticks > 0: |
|
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
173 stick = pygame.joystick.Joystick(0) |
|
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
174 stick.init() # now we will receive events for the joystick |
|
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
175 |
|
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
176 |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
177 screen.fill([0,0,0]) |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
178 pygame.display.flip() |
|
1427
a6e94e964a69
examples can be run from outside the examples directory
Lenard Lindstrom <len-l@telus.net>
parents:
949
diff
changeset
|
179 sprite_surface = pygame.image.load(os.path.join(data_dir, "asprite.bmp")) |
|
a6e94e964a69
examples can be run from outside the examples directory
Lenard Lindstrom <len-l@telus.net>
parents:
949
diff
changeset
|
180 sprite_surface2 = pygame.image.load(os.path.join(data_dir, "static.png")) |
|
660
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
181 |
|
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
182 if use_rle: |
|
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
183 sprite_surface.set_colorkey([0xFF, 0xFF, 0xFF], SRCCOLORKEY|RLEACCEL) |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
184 sprite_surface2.set_colorkey([0xFF, 0xFF, 0xFF], SRCCOLORKEY|RLEACCEL) |
|
660
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
185 else: |
|
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
186 sprite_surface.set_colorkey([0xFF, 0xFF, 0xFF], SRCCOLORKEY) |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
187 sprite_surface2.set_colorkey([0xFF, 0xFF, 0xFF], SRCCOLORKEY) |
|
660
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
188 |
|
772
7bf7fcda9328
added a command line flag for using alpha.
Rene Dudfield <renesd@gmail.com>
parents:
664
diff
changeset
|
189 if use_alpha: |
|
7bf7fcda9328
added a command line flag for using alpha.
Rene Dudfield <renesd@gmail.com>
parents:
664
diff
changeset
|
190 sprite_surface = sprite_surface.convert_alpha() |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
191 sprite_surface2 = sprite_surface2.convert_alpha() |
|
772
7bf7fcda9328
added a command line flag for using alpha.
Rene Dudfield <renesd@gmail.com>
parents:
664
diff
changeset
|
192 else: |
|
7bf7fcda9328
added a command line flag for using alpha.
Rene Dudfield <renesd@gmail.com>
parents:
664
diff
changeset
|
193 sprite_surface = sprite_surface.convert() |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
194 sprite_surface2 = sprite_surface2.convert() |
|
660
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
195 |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
196 Thingy.images = [sprite_surface] |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
197 if use_static: |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
198 Static.images = [sprite_surface2] |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
199 |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
200 if len(sys.argv) > 1: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
201 try: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
202 numsprites = int(sys.argv[-1]) |
|
1568
c35441d4f466
allow all Python modules to install with Python 3.1, though some may not work correctly
Lenard Lindstrom <len-l@telus.net>
parents:
1447
diff
changeset
|
203 except Exception: |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
204 numsprites = 100 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
205 else: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
206 numsprites = 100 |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
207 sprites = None |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
208 if use_FastRenderGroup: |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
209 ## sprites = FRG.FastRenderGroup() |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
210 sprites = FRG.LayeredDirty() |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
211 else: |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
212 if update_rects: |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
213 sprites = pygame.sprite.RenderUpdates() |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
214 else: |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
215 sprites = pygame.sprite.Group() |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
216 |
|
1572
9126dee1087d
adapt joystick and cdrom modules for Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1568
diff
changeset
|
217 for i in xrange_(0, numsprites): |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
218 if use_static and i%2==0: |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
219 sprites.add(Static()) |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
220 sprites.add(Thingy()) |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
221 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
222 done = False |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
223 frames = 0 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
224 start = time() |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
225 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
226 background = pygame.Surface(screen.get_size()) |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
227 background = background.convert() |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
228 background.fill([0,0,0]) |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
229 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
230 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
231 while not done: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
232 if not update_rects: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
233 screen.fill([0,0,0]) |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
234 |
|
843
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
235 ## for sprite in sprites: |
|
31f763040de7
Lots of sprite module changes from DR0ID.
Rene Dudfield <renesd@gmail.com>
parents:
772
diff
changeset
|
236 ## sprite.move() |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
237 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
238 if update_rects: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
239 sprites.clear(screen, background) |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
240 sprites.update() |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
241 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
242 rects = sprites.draw(screen) |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
243 if update_rects: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
244 pygame.display.update(rects) |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
245 else: |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
246 pygame.display.flip() |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
247 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
248 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
249 for event in pygame.event.get(): |
|
660
3d9225a14782
Added support for joystick quit. Which makes the gp2x able to quit the test, and go back to the menu. Also added not using RLE when using hardware.
Rene Dudfield <renesd@gmail.com>
parents:
655
diff
changeset
|
250 if event.type in [KEYDOWN, QUIT, JOYBUTTONDOWN]: |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
251 done = True |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
252 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
253 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
254 frames += 1 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
255 end = time() |
|
1568
c35441d4f466
allow all Python modules to install with Python 3.1, though some may not work correctly
Lenard Lindstrom <len-l@telus.net>
parents:
1447
diff
changeset
|
256 print ("FPS: %f" % (frames / ((end - start)))) |
|
1432
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
257 pygame.quit() |
|
655
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
258 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
259 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
260 |
|
b8247c989c19
like the testsprite.c that comes with sdl, this pygame version shows lots of sprites moving around. It is not an exact copy of testsprite.c, but is close. Thanks to zx64 for converting it.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
261 if __name__ == "__main__": |
|
1432
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
262 main( update_rects, |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
263 use_static, |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
264 use_FastRenderGroup, |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
265 screen_dims, |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
266 use_alpha, |
|
9eb2b6341928
Added argv arguments to main() too, and used pygame.quit.
Rene Dudfield <renesd@gmail.com>
parents:
1427
diff
changeset
|
267 flags ) |
