diff options
author | Rodolfo D. Arce S <rodolfo.arce.s@gmail.com> | 2011-05-12 02:36:39 (GMT) |
---|---|---|
committer | Rodolfo D. Arce S <rodolfo.arce.s@gmail.com> | 2011-05-12 02:36:39 (GMT) |
commit | ed0efa9bc739ef35da330f743d917226860498c9 (patch) | |
tree | 0dafb8038fbfb95ae83dcd71f72e1e43b6fa8ca3 | |
parent | 49f1cb6c2f49ad9690ba4a77b4933ed0eabc8e70 (diff) |
Added more images, added motion to robot, added comments for images authors
-rw-r--r-- | README | 10 | ||||
-rw-r--r-- | images/paper.png | bin | 0 -> 1374 bytes | |||
-rw-r--r-- | images/park_2.png | bin | 0 -> 100263 bytes | |||
-rw-r--r-- | images/person_1.png | bin | 0 -> 102414 bytes | |||
-rw-r--r-- | images/person_2.png | bin | 0 -> 93083 bytes | |||
-rw-r--r-- | images/person_3.png | bin | 0 -> 29107 bytes | |||
-rw-r--r-- | images/person_4.png | bin | 0 -> 138307 bytes | |||
-rw-r--r-- | images/robot_1.png | bin | 0 -> 6032 bytes | |||
-rw-r--r-- | main.py | 73 |
9 files changed, 61 insertions, 22 deletions
@@ -5,8 +5,16 @@ This game is design to make children aware of the damages to the enviroment we d Images: Background: -Me +http://www.openclipart.org/detail/62473 +http://www.openclipart.org/detail/62479 + Robot: http://www.openclipart.org/detail/102925 +http://www.openclipart.org/detail/161 + Paper: http://www.openclipart.org/detail/16727 + +Person: +http://www.openclipart.org/detail/27903 +http://www.openclipart.org/detail/48367 diff --git a/images/paper.png b/images/paper.png Binary files differnew file mode 100644 index 0000000..fc510bc --- /dev/null +++ b/images/paper.png diff --git a/images/park_2.png b/images/park_2.png Binary files differnew file mode 100644 index 0000000..3163dab --- /dev/null +++ b/images/park_2.png diff --git a/images/person_1.png b/images/person_1.png Binary files differnew file mode 100644 index 0000000..ef58c6d --- /dev/null +++ b/images/person_1.png diff --git a/images/person_2.png b/images/person_2.png Binary files differnew file mode 100644 index 0000000..5da9106 --- /dev/null +++ b/images/person_2.png diff --git a/images/person_3.png b/images/person_3.png Binary files differnew file mode 100644 index 0000000..0e1e41a --- /dev/null +++ b/images/person_3.png diff --git a/images/person_4.png b/images/person_4.png Binary files differnew file mode 100644 index 0000000..e00df53 --- /dev/null +++ b/images/person_4.png diff --git a/images/robot_1.png b/images/robot_1.png Binary files differnew file mode 100644 index 0000000..57a2efd --- /dev/null +++ b/images/robot_1.png @@ -13,17 +13,20 @@ window_w = 800 screen = pygame.display.set_mode((window_w, window_h)) # Background image -object_background = pygame.image.load('images/park_1.png') +object_background = pygame.image.load('images/park_2.png') screen.blit(object_background, (0, 0)) # Garbage image -object_garbage = pygame.image.load('images/paper.png') -position_garbage = [ 400, 300 ] -screen.blit(object_garbage, position_garbage) +#object_garbage = pygame.image.load('images/paper.png') +#position_garbage = [ 400, 300 ] +#screen.blit(object_garbage, position_garbage) + # Robot image -object_robot = pygame.image.load('images/robot.png') +object_robot = pygame.image.load('images/robot_1.png') position_robot = [0, window_h - object_robot.get_height()] +x_direction = 0 +y_direction = 0 screen.blit(object_robot, position_robot) @@ -35,28 +38,56 @@ start_time = time.time() fps = 30 frame_time = 1.0/fps - - # Main loop exit = False while not exit: # Process pygame events - for event in pygame.event.get(): - # Escape key to quit the game - if event.type == pygame.QUIT or \ - (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): - exit = True - break - if exit: - break - - current_time = time.time() - if current_time - start_time <= frame_time: - continue - start_time = current_time + for event in pygame.event.get(): + # Escape key to quit the game + if event.type == pygame.QUIT or \ + (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): + exit = True + break + # Handle movement for the character + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT: + x_direction = -1 + y_direction = 0 + if event.key == pygame.K_RIGHT: + x_direction = 1 + y_direction =0 + if event.key == pygame.K_UP: + y_direction = -1 + x_direction = 0 + if event.key == pygame.K_DOWN: + y_direction = 1 + x_direction = 0 + if event.type == pygame.KEYUP: + if (event.key == pygame.K_LEFT and x_direction == -1 and y_direction == 0) or\ + (event.key == pygame.K_RIGHT and x_direction == 1 and y_direction == 0) or\ + (event.key == pygame.K_UP and y_direction == -1 and x_direction == 0) or\ + (event.key == pygame.K_DOWN and y_direction == 1 and x_direction == 0): + x_direction = 0 + y_direction = 0 + if exit: + break + + current_time = time.time() + if current_time - start_time <= frame_time: + continue + start_time = current_time + + # draw the background first, because it will cover all the screen + screen.blit(object_background, (0,0)) + # draw everything else over the background + screen.blit(object_robot, (position_robot[0], position_robot[1])) + + # Move the character around the screen + position_robot = [((position_robot[0] + x_direction*6)%window_w), ((position_robot[1] + y_direction*6)%window_h) ] + - pygame.display.update() + pygame.display.update() pygame.quit() |