Merge commit 'v37' into upstream
Jonas Smedegaard
13 years ago
0 | 37 | |
1 | * Remove broken slideshow until it is fixed #2054 (James Cameron) | |
2 | * Adapt pippy examples to screen dimensions (except xolyimpics), | |
3 | dev.laptop.org #9260 (James Cameron) | |
4 | ||
0 | 5 | 36 |
1 | 6 | * Add COPYING based on activity.info license field, verify source file |
2 | 7 | licenses, include LICENSE from Elements upstream SVN, fixes |
3 | 3 | service_name = org.laptop.Pippy |
4 | 4 | class = pippy_app.PippyActivity |
5 | 5 | icon = activity-icon |
6 | activity_version = 36 | |
6 | activity_version = 37 | |
7 | 7 | mime_types = text/x-python, pickle/groupthink-pippy |
8 | 8 | show_launcher = yes |
9 | 9 |
1 | 1 | |
2 | 2 | import pippy, pygame, sys |
3 | 3 | from pygame.locals import * |
4 | from random import * | |
4 | ||
5 | # the text to bounce around the screen | |
6 | msg = "Hello!" | |
7 | ||
8 | # the size of the text, in pixels | |
9 | fsize = 36 | |
10 | ||
11 | # vector for motion, will control speed and angle | |
12 | mvect = [3, 2] | |
5 | 13 | |
6 | 14 | # always need to init first thing |
7 | 15 | pygame.init() |
9 | 17 | # turn off cursor |
10 | 18 | pygame.mouse.set_visible(False) |
11 | 19 | |
12 | # XO screen is 1200x900 | |
13 | size = width, height = 1200, 900 | |
14 | ||
15 | # we'll use 36 pixel high text | |
16 | fsize = 36 | |
17 | ||
18 | # vector for motion, will control speed and angle | |
19 | mvect = [3,2] | |
20 | ||
21 | 20 | # create the window and keep track of the surface |
22 | 21 | # for drawing into |
23 | screen = pygame.display.set_mode(size) | |
22 | screen = pygame.display.set_mode() | |
24 | 23 | |
25 | msg = "Hello!" | |
24 | # ask for screen's width and height | |
25 | size = width, height = screen.get_size() | |
26 | 26 | |
27 | 27 | # create a Font object from a file, or use the default |
28 | 28 | # font if the file name is None. size param is height |
34 | 34 | # Font.render draws text onto a new surface. |
35 | 35 | # |
36 | 36 | # usage: Font.render(text, antialias, color, bg=None) |
37 | text = font.render(msg, True, (10,10,10)) | |
37 | text = font.render(msg, True, (10, 10, 10)) | |
38 | 38 | |
39 | 39 | # the Rect object is used for positioning |
40 | 40 | textRect = text.get_rect() |
45 | 45 | |
46 | 46 | while pippy.pygame.next_frame(): |
47 | 47 | |
48 | # every time we move the text, check for quit or keydown events and exit | |
48 | 49 | for event in pygame.event.get(): |
49 | 50 | if event.type == QUIT: |
50 | 51 | sys.exit() |
52 | 53 | elif event.type == KEYDOWN: |
53 | 54 | sys.exit() |
54 | 55 | |
55 | screen.fill((250,250,250)) | |
56 | ||
56 | # fill the screen with almost white | |
57 | screen.fill((250, 250, 250)) | |
58 | ||
57 | 59 | # draw the text |
58 | 60 | screen.blit(text, textRect) |
59 | 61 |
0 | # image: take a picture | |
0 | # camera: take a picture, animate it on screen | |
1 | 1 | |
2 | 2 | import gst, pippy, pygame, sys, time |
3 | from random import * | |
4 | ||
5 | # XO screen is 1200 by 900 | |
6 | size = width, height = 1200, 900 | |
7 | 3 | |
8 | 4 | # grey background |
9 | bgcolor = (128,128,128) | |
5 | bgcolor = (128, 128, 128) | |
10 | 6 | |
11 | 7 | # grab a frame from camera to file |
12 | 8 | pipeline = gst.parse_launch('v4l2src ! ffmpegcolorspace ! jpegenc ! filesink location=/tmp/pippypic.jpg') |
13 | 9 | pipeline.set_state(gst.STATE_PLAYING) |
14 | 10 | |
15 | # pygame always needs to be initialized as the first call | |
11 | # start using pygame | |
16 | 12 | pygame.init() |
17 | 13 | |
18 | 14 | # turn off cursor |
19 | 15 | pygame.mouse.set_visible(False) |
20 | 16 | |
21 | # create the pygame window at the desired size and return a Surface object for | |
17 | # create the pygame window and return a Surface object for | |
22 | 18 | # drawing in that window. |
23 | screen = pygame.display.set_mode(size) | |
19 | screen = pygame.display.set_mode() | |
24 | 20 | |
21 | # pause for a second to allow the camera frame to be grabbed | |
25 | 22 | time.sleep(1) |
23 | ||
24 | # stop the camera frame grabbing | |
26 | 25 | pipeline.set_state(gst.STATE_NULL) |
27 | 26 | |
28 | # load in previously grabbed frame | |
27 | # load in the grabbed camera frame | |
29 | 28 | image = pygame.image.load("/tmp/pippypic.jpg") |
30 | 29 | |
31 | 30 | angle = 0.0 |
32 | 31 | scale = 2.0 |
33 | 32 | |
34 | 33 | while pippy.pygame.next_frame(): |
34 | # every time we animate, check for quit or keydown events and exit | |
35 | 35 | for event in pygame.event.get(): |
36 | 36 | if event.type == pygame.QUIT: sys.exit() |
37 | 37 | elif event.type == pygame.KEYDOWN: sys.exit() |
38 | 38 | |
39 | newImage = pygame.transform.rotozoom(image, angle,scale) | |
39 | # rotate and scale the image | |
40 | newImage = pygame.transform.rotozoom(image, angle, scale) | |
40 | 41 | newImageRect = newImage.get_rect() |
41 | 42 | newImageRect.centerx = screen.get_rect().centerx |
42 | 43 | newImageRect.centery = screen.get_rect().centery |
43 | 44 | |
45 | # display the rotated and scaled image | |
44 | 46 | screen.fill(bgcolor) |
45 | 47 | screen.blit(newImage, newImageRect) |
46 | 48 | pygame.display.flip() |
47 | 49 | |
50 | # choose a new rotation angle and scale | |
48 | 51 | angle = angle + 5.0 |
49 | 52 | scale = scale * 0.95 |
53 | ||
54 | # finish once the scale becomes very very small | |
55 | if scale < 0.001: | |
56 | break |
11 | 11 | print "_|_" |
12 | 12 | print " " |
13 | 13 | pippy.wait() |
14 | ||
14 | ||
15 | 15 | pippy.console.clear() |
16 | 16 | print "_o_" |
17 | 17 | print " | " |
18 | 18 | print "/ \\" |
19 | 19 | pippy.wait() |
20 | ||
20 | ||
21 | 21 | pippy.console.clear() |
22 | 22 | print " o " |
23 | 23 | print "/|\\" |
24 | 24 | print "| |" |
25 | 25 | pippy.wait() |
26 | ||
26 | ||
27 | 27 | pippy.console.clear() |
28 | 28 | print "_o_" |
29 | 29 | print " | " |
2 | 2 | import pippy, pygame, sys |
3 | 3 | from pygame.locals import * |
4 | 4 | from random import * |
5 | ||
6 | # XO screen is 1200x900 | |
7 | size = width, height = 1200, 900 | |
8 | 5 | |
9 | 6 | # always need to init first thing |
10 | 7 | pygame.init() |
14 | 11 | |
15 | 12 | # create the window and keep track of the surface |
16 | 13 | # for drawing into |
17 | screen = pygame.display.set_mode(size) | |
14 | screen = pygame.display.set_mode() | |
15 | ||
16 | # ask for screen's width and height | |
17 | size = width, height = screen.get_size() | |
18 | ||
18 | 19 | # start the screen all black |
19 | 20 | screen.fill((0,0,0)) |
20 | 21 | |
47 | 48 | pygame.display.flip() |
48 | 49 | |
49 | 50 | # update the end points and the color |
50 | for i in range(2): | |
51 | for i in range(2): | |
51 | 52 | start[i] = start[i] + mvect_start[i] |
52 | 53 | end[i] = end[i] + mvect_end[i] |
53 | 54 |
5 | 5 | |
6 | 6 | # initialize pygame first thing |
7 | 7 | pygame.init() |
8 | screen = pygame.display.set_mode((1200,900)) | |
9 | ||
8 | screen = pygame.display.set_mode() | |
9 | ||
10 | 10 | # set up the physics world (instance of Elements) |
11 | 11 | world = physics.Elements(screen.get_size()) |
12 | 12 | world.renderer.set_surface(screen) |
13 | ||
13 | ||
14 | 14 | # set up initial physics objects |
15 | 15 | world.add.ground() |
16 | 16 | world.add.ball((600,0), 50) |
18 | 18 | |
19 | 19 | # add 20 more balls |
20 | 20 | balls = 0 |
21 | while(balls<20): | |
22 | world.add.ball((balls*5+200,balls*5), 50) | |
23 | balls+=1 | |
21 | while(balls < 20): | |
22 | world.add.ball((balls*5+200, balls*5), 50) | |
23 | balls += 1 | |
24 | 24 | |
25 | 25 | # begin physics simulation |
26 | 26 | world.run_physics = True |
45 | 45 | world.mouse_move(event.pos) |
46 | 46 | |
47 | 47 | # clear display with a color |
48 | # (r,g,b), where 0<=value<256 | |
49 | screen.fill((80,160,240)) | |
48 | screen.fill((80, 160, 240)) | |
50 | 49 | |
51 | 50 | # update & draw physics world |
52 | 51 | world.update() |
54 | 53 | |
55 | 54 | # update the display |
56 | 55 | pygame.display.flip() |
57 |
0 | 0 | # pong: hit the ball with the paddle |
1 | 1 | # |
2 | 2 | # use the escape key to exit |
3 | # | |
3 | # | |
4 | 4 | # on the XO, the escape key is the top lefthand key, |
5 | 5 | # circle with an x in it. |
6 | 6 | |
11 | 11 | # always need to init first thing |
12 | 12 | pygame.init() |
13 | 13 | |
14 | # XO screen is 1200x900 | |
15 | size = width, height = 1200, 900 | |
16 | ||
17 | 14 | # create the window and keep track of the surface |
18 | 15 | # for drawing into |
19 | screen = pygame.display.set_mode(size) | |
16 | screen = pygame.display.set_mode() | |
17 | ||
18 | # ask for screen's width and height | |
19 | size = width, height = screen.get_size() | |
20 | 20 | |
21 | 21 | # turn off the cursor |
22 | 22 | pygame.mouse.set_visible(False) |
23 | 23 | |
24 | 24 | # turn on key repeating (repeat 40 times per second) |
25 | pygame.key.set_repeat(25,25) | |
25 | pygame.key.set_repeat(25, 25) | |
26 | 26 | |
27 | 27 | # start the screen all black |
28 | bgcolor = (0,0,0) | |
28 | bgcolor = (0, 0, 0) | |
29 | 29 | screen.fill(bgcolor) |
30 | 30 | |
31 | 31 | # paddle constants |
32 | 32 | paddle_width = 20 |
33 | 33 | paddle_length = 100 |
34 | 34 | paddle_radius = paddle_length / 2 |
35 | paddle_color = (250,250,250) | |
35 | paddle_color = (250, 250, 250) | |
36 | 36 | step = 6 # paddle moves 3 pixels at a go |
37 | 37 | |
38 | 38 | # ball constants |
39 | ball_color = (250,250,250) | |
39 | ball_color = (250, 250, 250) | |
40 | 40 | ball_radius = 25 |
41 | 41 | |
42 | 42 | # game constants |
43 | 43 | fsize = 48 |
44 | 44 | msg = "Press 'g' to start game" |
45 | 45 | |
46 | font=pygame.font.Font(None, fsize) | |
47 | text = font.render(msg, True, (250,250,250)) | |
46 | font = pygame.font.Font(None, fsize) | |
47 | text = font.render(msg, True, (250, 250, 250)) | |
48 | 48 | textRect = text.get_rect() |
49 | 49 | textRect.centerx = screen.get_rect().centerx |
50 | 50 | textRect.centery = screen.get_rect().centery |
99 | 99 | or event.key == 259 \ |
100 | 100 | or event.key == 258: # down |
101 | 101 | paddle_location = paddle_location + step |
102 | ||
102 | ||
103 | 103 | # make sure the paddle is in-bounds |
104 | 104 | if paddle_location - paddle_radius < 0: |
105 | 105 | paddle_location = paddle_radius |
112 | 112 | # draw the paddle on the right side of the screen |
113 | 113 | pygame.draw.line(screen, |
114 | 114 | paddle_color, |
115 | (width - paddle_width, paddle_location - | |
115 | (width - paddle_width, paddle_location - | |
116 | 116 | paddle_radius), |
117 | 117 | (width - paddle_width, |
118 | 118 | paddle_location+paddle_radius), |
123 | 123 | |
124 | 124 | # draw the unused balls |
125 | 125 | for i in range(balls): |
126 | pygame.draw.circle(screen, ball_color, (int(round(30+i*ball_radius*2.4)), 30), | |
126 | pygame.draw.circle(screen, ball_color, | |
127 | (int(round(30+i*ball_radius*2.4)), 30), | |
127 | 128 | ball_radius) |
128 | 129 | |
129 | 130 | # update the display |
0 | # slideshow: show datastore photos | |
1 | def pippy_activity_class(): return 'activity.PyGameActivity' | |
2 | if __name__ == '__main__': | |
3 | import gst, pippy, pygame, sys, time | |
4 | from pippy import query | |
5 | ||
6 | from random import * | |
7 | ||
8 | # XO screen is 1200 by 900 | |
9 | size = width, height = 1200, 900 | |
10 | ||
11 | # grey background | |
12 | bgcolor = (128,128,128) | |
13 | ||
14 | # Create a search dict | |
15 | search = {} | |
16 | search["mime_type"] = "image/jpeg" | |
17 | ||
18 | # Perform the search and retrieve the jobjects | |
19 | results = query.find(search) | |
20 | # XXX: Fix caching limit in query.py | |
21 | objects = results.read(15) | |
22 | ||
23 | if len(objects) == 0: | |
24 | print "No photos found." | |
25 | time.sleep(3) | |
26 | sys.exit() | |
27 | ||
28 | def get_image(): | |
29 | for jobject in objects: | |
30 | yield jobject.get_file_path() | |
31 | ||
32 | next_image = get_image() | |
33 | ||
34 | # pygame always needs to be initialized as the first call | |
35 | pygame.init() | |
36 | ||
37 | # turn off cursor | |
38 | pygame.mouse.set_visible(False) | |
39 | ||
40 | # create the pygame window at the desired size and return a Surface object for | |
41 | # drawing in that window. | |
42 | screen = pygame.display.set_mode(size) | |
43 | ||
44 | # load in previously grabbed frame | |
45 | image = pygame.image.load(next_image.next()) | |
46 | ||
47 | while pippy.pygame.next_frame(): | |
48 | for event in pygame.event.get(): | |
49 | if event.type == pygame.QUIT: sys.exit() | |
50 | elif event.type == pygame.KEYDOWN: | |
51 | try: | |
52 | image = pygame.image.load(next_image.next()) | |
53 | except StopIteration: | |
54 | sys.exit() | |
55 | ||
56 | # Scale up from 640x480 -> 1280x960 | |
57 | newImage = pygame.transform.rotozoom(image, 0, 2.0) | |
58 | newImageRect = newImage.get_rect() | |
59 | newImageRect.centerx = screen.get_rect().centerx | |
60 | newImageRect.centery = screen.get_rect().centery | |
61 | ||
62 | screen.fill(bgcolor) | |
63 | screen.blit(newImage, newImageRect) | |
64 | pygame.display.flip() |
0 | # snow | |
0 | 1 | |
1 | 2 | import pippy, pygame, sys |
2 | 3 | from pygame.locals import * |
5 | 6 | # always need to init first thing |
6 | 7 | pygame.init() |
7 | 8 | |
8 | # XO screen is 1200x900 | |
9 | size = width, height = 1200, 900 | |
10 | ||
11 | 9 | # create the window and keep track of the surface |
12 | 10 | # for drawing into |
13 | screen = pygame.display.set_mode(size) | |
11 | screen = pygame.display.set_mode() | |
12 | ||
13 | # ask for screen's width and height | |
14 | width, height = screen.get_size() | |
14 | 15 | |
15 | 16 | # turn off the cursor |
16 | 17 | pygame.mouse.set_visible(False) |
17 | 18 | |
18 | bg_color = (0,0,0) | |
19 | bg_color = (0, 0, 0) | |
19 | 20 | |
20 | 21 | xs = [] |
21 | 22 | ys = [] |
0 | ||
1 | import pippy, pygame, sys | |
2 | from pygame.locals import * | |
3 | from random import * | |
4 | import math | |
5 | ||
6 | # always need to init first thing | |
7 | pygame.init() | |
8 | ||
9 | # XO screen is 1200x900 | |
10 | size = width, height = 1200, 900 | |
11 | ||
12 | # create the window and keep track of the surface | |
13 | # for drawing into | |
14 | screen = pygame.display.set_mode(size) | |
15 | ||
16 | # turn off the cursor | |
17 | pygame.mouse.set_visible(False) | |
18 | ||
19 | color = (250,250,250) | |
20 | min_factor = 0.8 | |
21 | max_factor = 0.9 | |
22 | start_length = 130 | |
23 | min_length = 40 | |
24 | min_angle_delta = 0.4 | |
25 | max_angle_delta = 0.5 | |
26 | ||
27 | # start the screen all black | |
28 | bgcolor = (0,0,0) | |
29 | screen.fill(bgcolor) | |
30 | ||
31 | def draw_tree(x, y, length, angle): | |
32 | x2 = x + length * math.sin(angle) | |
33 | y2 = y - length * math.cos(angle) | |
34 | pygame.draw.line(screen, color, (x, y), (x2, y2)) | |
35 | ||
36 | if length > min_length: | |
37 | # draw left branch | |
38 | left_angle = angle - \ | |
39 | uniform(min_angle_delta, max_angle_delta) | |
40 | left_length = length * \ | |
41 | uniform(min_factor, max_factor) | |
42 | draw_tree(x2, y2, left_length, left_angle) | |
43 | # draw middle branch | |
44 | middle_length = length * \ | |
45 | uniform(min_factor, max_factor) | |
46 | draw_tree(x2, y2, middle_length, angle) | |
47 | # draw right branch | |
48 | right_angle = angle + \ | |
49 | uniform(min_angle_delta, max_angle_delta) | |
50 | right_length = length * \ | |
51 | uniform(min_factor, max_factor) | |
52 | draw_tree(x2, y2, right_length, right_angle) | |
53 | ||
54 | # clear the screen | |
55 | screen.fill(bgcolor) | |
56 | ||
57 | # draw a tree, starting at the bottom centre of the | |
58 | # screen | |
59 | draw_tree((width / 2), height - 20, start_length, 0) | |
60 | pygame.display.flip() | |
61 | ||
62 | while pippy.pygame.next_frame(): | |
63 | # chill until a key is pressed | |
64 | for event in pygame.event.get(): | |
65 | if event.type == QUIT: | |
66 | sys.exit() | |
67 | ||
68 | if event.type == KEYDOWN: | |
69 | if event.key == K_ESCAPE: | |
70 | sys.exit() | |
0 | # tree | |
1 | ||
2 | import pippy, pygame, sys | |
3 | from pygame.locals import * | |
4 | from random import * | |
5 | import math | |
6 | ||
7 | # always need to init first thing | |
8 | pygame.init() | |
9 | ||
10 | # create the window and keep track of the surface | |
11 | # for drawing into | |
12 | screen = pygame.display.set_mode() | |
13 | ||
14 | # ask for screen's width and height | |
15 | width, height = screen.get_size() | |
16 | ||
17 | # turn off the cursor | |
18 | pygame.mouse.set_visible(False) | |
19 | ||
20 | color = (250, 250, 250) | |
21 | min_factor = 0.8 | |
22 | max_factor = 0.9 | |
23 | start_length = 130 | |
24 | min_length = 40 | |
25 | min_angle_delta = 0.4 | |
26 | max_angle_delta = 0.5 | |
27 | ||
28 | # start the screen all black | |
29 | bgcolor = (0,0,0) | |
30 | screen.fill(bgcolor) | |
31 | ||
32 | def draw_tree(x, y, length, angle): | |
33 | x2 = x + length * math.sin(angle) | |
34 | y2 = y - length * math.cos(angle) | |
35 | pygame.draw.line(screen, color, (x, y), (x2, y2)) | |
36 | ||
37 | if length > min_length: | |
38 | # draw left branch | |
39 | left_angle = angle - \ | |
40 | uniform(min_angle_delta, max_angle_delta) | |
41 | left_length = length * \ | |
42 | uniform(min_factor, max_factor) | |
43 | draw_tree(x2, y2, left_length, left_angle) | |
44 | # draw middle branch | |
45 | middle_length = length * \ | |
46 | uniform(min_factor, max_factor) | |
47 | draw_tree(x2, y2, middle_length, angle) | |
48 | # draw right branch | |
49 | right_angle = angle + \ | |
50 | uniform(min_angle_delta, max_angle_delta) | |
51 | right_length = length * \ | |
52 | uniform(min_factor, max_factor) | |
53 | draw_tree(x2, y2, right_length, right_angle) | |
54 | ||
55 | # clear the screen | |
56 | screen.fill(bgcolor) | |
57 | ||
58 | # draw a tree, starting at the bottom centre of the | |
59 | # screen | |
60 | draw_tree((width / 2), height - 20, start_length, 0) | |
61 | pygame.display.flip() | |
62 | ||
63 | # do nothing visible until the escape key is pressed | |
64 | while pippy.pygame.next_frame(): | |
65 | for event in pygame.event.get(): | |
66 | if event.type == QUIT: | |
67 | sys.exit() | |
68 | ||
69 | if event.type == KEYDOWN: | |
70 | if event.key == K_ESCAPE: | |
71 | sys.exit() |
12 | 12 | from pippy.physics import box2d |
13 | 13 | |
14 | 14 | class XOlympicsGame: |
15 | def __init__(self,screen): | |
15 | def __init__(self): | |
16 | 16 | self.rightscore = self.leftscore = 0 |
17 | 17 | self.forcespeed = 75 |
18 | 18 | self.jumpforce = 20 |
26 | 26 | self.rightJump = False |
27 | 27 | self.updateList = [] |
28 | 28 | |
29 | self.screen = pygame.display.set_mode((1200,900)) | |
29 | self.screen = pygame.display.set_mode() | |
30 | self.width, self.height = self.screen.get_size() | |
30 | 31 | |
31 | 32 | self.clock = pygame.time.Clock() |
32 | self.font = pygame.font.Font(None, 24) # font object | |
33 | 33 | |
34 | 34 | # set up the world (instance of Elements) |
35 | 35 | self.world = physics.Elements(self.screen.get_size()) |
36 | 36 | self.world.renderer.set_surface(self.screen) |
37 | 37 | # set up static environment |
38 | self.world.set_color((0, 255, 0)) | |
38 | self.world.set_color((0, 255, 0)) | |
39 | 39 | self.world.add.ground() |
40 | self.ball = self.world.add.ball((600, 0), 50) | |
40 | self.ball = self.world.add.ball((self.width / 2, 0), 50) | |
41 | 41 | # add the left border and player (red) |
42 | self.world.set_color((255, 0, 0)) | |
43 | self.world.add.rect((0,-20), 25, 900, dynamic=False, density=1.0, restitution=0.16, friction=0.5) | |
44 | self.leftplayer = self.world.add.poly(( 264.0, 81.0 ), ((-109.9405166666667, -64.244016666666653), (110.60718333333335, -63.089316666666605), (-0.66666666666668561, 127.33333333333337)) , dynamic=True, density=1.0, restitution=0.16, friction=0.5, screenCoord=False) | |
45 | # add the right border and player (blue) | |
46 | self.world.set_color((0, 0, 255)) | |
47 | self.world.add.rect((1180,-20), 25, 900, dynamic=False, density=1.0, restitution=0.16, friction=0.5) | |
48 | self.rightplayer = self.world.add.poly(( 885.0, 78.0 ), [(108.94051666666667, -65.976066666666611), (2.6666666666666288, 127.33333333333337), (-111.60718333333341, -61.357266666666646)] , dynamic=True, density=1.0, restitution=0.16, friction=0.5, screenCoord=False) | |
49 | # we're getting 2 grounds - grey and green. wtf. | |
50 | self.leftplayer.linearDamping = 0.07 | |
51 | self.test = self.leftplayer.GetWorldCenter() | |
42 | self.world.set_color((255, 0, 0)) | |
43 | self.world.add.rect((0, -20), 25, self.height, | |
44 | dynamic=False, density=1.0, | |
45 | restitution=0.16, friction=0.5) | |
46 | self.leftplayer = self.world.add.poly(( self.width * 0.25, 81.0 ), [(-109.9405166666667, -64.244016666666653), (110.60718333333335, -63.089316666666605), (-0.66666666666668561, 127.33333333333337)] , dynamic=True, density=1.0, restitution=0.16, friction=0.5, screenCoord=False) | |
47 | # add the right border and player (blue) | |
48 | self.world.set_color((0, 0, 255)) | |
49 | self.world.add.rect((self.width, -20), 25, self.height, | |
50 | dynamic=False, density=1.0, | |
51 | restitution=0.16, friction=0.5) | |
52 | self.rightplayer = self.world.add.poly(( self.width * 0.75, 81.0 ), [(108.94051666666667, -65.976066666666611), (2.6666666666666288, 127.33333333333337), (-111.60718333333341, -61.357266666666646)] , dynamic=True, density=1.0, restitution=0.16, friction=0.5, screenCoord=False) | |
53 | # we're getting 2 grounds - grey and green. why? | |
54 | ||
52 | 55 | def run(self): |
53 | self.running = True | |
56 | self.running = True | |
54 | 57 | while self.running: |
55 | 58 | |
56 | 59 | for event in pygame.event.get(): |
83 | 86 | if (event.type == KEYDOWN and (event.key == K_UP or event.key == K_KP9)): |
84 | 87 | self.rightJump = True |
85 | 88 | if (event.type == KEYUP and (event.key == K_UP or event.key == K_KP9)): |
86 | self.rightJump = False | |
89 | self.rightJump = False | |
87 | 90 | if (event.type == KEYDOWN and (event.key == K_DOWN or event.key == K_KP3)): |
88 | 91 | self.rightDPress = True |
89 | 92 | if (event.type == KEYUP and (event.key == K_DOWN or event.key == K_KP3)): |
90 | self.rightDPress = False | |
93 | self.rightDPress = False | |
91 | 94 | |
92 | 95 | if self.leftLPress: |
93 | 96 | self.leftplayer.ApplyForce(box2d.b2Vec2(-self.forcespeed,0), self.leftplayer.GetWorldCenter()) |
101 | 104 | if self.rightRPress: |
102 | 105 | self.rightplayer.ApplyForce(box2d.b2Vec2(self.forcespeed,0), self.rightplayer.GetWorldCenter()) |
103 | 106 | if self.rightDPress: |
104 | self.rightplayer.ApplyImpulse(box2d.b2Vec2(0,-self.jumpforce), self.rightplayer.GetWorldCenter()) | |
107 | self.rightplayer.ApplyImpulse(box2d.b2Vec2(0,-self.jumpforce), self.rightplayer.GetWorldCenter()) | |
105 | 108 | if self.rightJump: |
106 | 109 | if self.rightplayer.GetWorldCenter().y < 0.75: |
107 | self.rightplayer.ApplyImpulse(box2d.b2Vec2(0,self.jumpforce), self.rightplayer.GetWorldCenter()) | |
110 | self.rightplayer.ApplyImpulse(box2d.b2Vec2(0,self.jumpforce), self.rightplayer.GetWorldCenter()) | |
108 | 111 | if self.leftDPress: |
109 | 112 | self.leftplayer.ApplyImpulse(box2d.b2Vec2(0,-self.jumpforce), self.leftplayer.GetWorldCenter()) |
110 | 113 | |
111 | # Clear Display | |
114 | # Clear Display | |
112 | 115 | if self.ball.GetWorldCenter().x < 1: |
113 | 116 | self.leftscore += 1 |
114 | 117 | print "Goal Blue!", self.leftscore |
115 | 118 | self.world.set_color((0, 0, 255)) |
116 | self.ball = self.world.add.ball((600, 0), 50) | |
119 | self.ball = self.world.add.ball((self.width/2, 0), 50) | |
117 | 120 | elif self.ball.GetWorldCenter().x > 11: |
121 | # FIXME: the 11 above works only when display width is | |
122 | # 1200 pixels | |
118 | 123 | self.rightscore += 1 |
119 | 124 | print "Goal Red!", self.rightscore |
120 | 125 | self.world.set_color((255, 0, 0)) |
121 | self.ball = self.world.add.ball((600, 0), 50) | |
126 | self.ball = self.world.add.ball((self.width/2, 0), 50) | |
122 | 127 | |
123 | self.screen.fill((255,255,255)) | |
128 | self.screen.fill((255,255,255)) | |
124 | 129 | # Update & Draw World |
125 | 130 | self.world.update() |
126 | 131 | self.world.draw() |
127 | ||
132 | ||
128 | 133 | # Flip Display |
129 | pygame.display.flip() | |
130 | ||
134 | pygame.display.flip() | |
135 | ||
131 | 136 | # Try to stay at 30 FPS |
132 | self.clock.tick(30) # originally 50 | |
137 | self.clock.tick(30) # originally 50 | |
133 | 138 | |
134 | 139 | def main(): |
135 | toolbarheight = 0 | |
136 | tabheight = 0 | |
137 | 140 | pygame.init() |
138 | 141 | pygame.display.init() |
139 | x,y = pygame.display.list_modes()[0] | |
140 | screen = pygame.display.set_mode((x,y-toolbarheight))#-tabheight)) | |
141 | 142 | # create an instance of the game |
142 | game = XOlympicsGame(screen) | |
143 | game = XOlympicsGame() | |
143 | 144 | # start the main loop |
144 | 145 | game.run() |
145 | 146 | |
146 | # make sure that main get's called | |
147 | # make sure that main is called | |
147 | 148 | if __name__ == '__main__': |
148 | 149 | main() |
149 |
16 | 16 | 'Directors & Advisors': 'Howard Anderson, Rebecca Allen, Ayo Kusamotu, Jose Maria Aznar, V. Michael Bove, Jr., Rodrigo Mesquita, Seymour Papert, Ted Selker, Ethan Beard (Google); John Roese (Nortel); Dandy Hsu (Quanta); Marcelo Claure (Brightstar); Gary Dillabough (eBay); Gustavo Arenas (AMD); Mike Evans (Red Hat); Ed Horowitz (SES Astra); Jeremy Philips (NewsCorp); Scott Soong (Chi Lin); Sehat Sutardja (Marvell); Joe Jacobson (MIT Media Lab); Steve Kaufman (Riverside); and Tom Meredith (MFI)', |
17 | 17 | 'Pippy': 'Chris Ball, C. Scott Ananian' |
18 | 18 | } |
19 | ||
19 | ||
20 | 20 | import random, time |
21 | 21 | from pippy.console import * |
22 | 22 | from textwrap import fill |
23 | 23 | |
24 | # Determine the number of columns in our window in | |
25 | # order to wrap text to that width -- this changes | |
26 | # when we run as a standalone activity instead of | |
24 | # Determine the number of columns in our window in | |
25 | # order to wrap text to that width -- this changes | |
26 | # when we run as a standalone activity instead of | |
27 | 27 | # inside the output pane. |
28 | 28 | cols, lines = size() |
29 | 29 | |
35 | 35 | random.choice([red, green, yellow, blue, magenta, cyan])() |
36 | 36 | #random.choice([normal, bold, underlined, inverse])() |
37 | 37 | print '\n', fill("%s: %s" % (subsystem, table[subsystem]), int(cols)) |
38 | table.pop(subsystem) | |
39 | if len(table) == 0: | |
40 | break | |
38 | 41 | |
39 | 42 | time.sleep(3) |
43 | reset() |