Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/main.py
diff options
context:
space:
mode:
authorRodolfo D. Arce S <rodolfo.arce.s@gmail.com>2011-05-13 01:36:52 (GMT)
committer Rodolfo D. Arce S <rodolfo.arce.s@gmail.com>2011-05-13 01:36:52 (GMT)
commitce75b367b415edf0d524aea10c4281c5aaa54ae6 (patch)
tree692b3a4542a30b7cdc7d81eb59447f109950a7a5 /main.py
parent843daab512ec3e9f07077e6feaa91711afb5f64f (diff)
Added separate file for robot class, with various actions
Diffstat (limited to 'main.py')
-rw-r--r--main.py56
1 files changed, 17 insertions, 39 deletions
diff --git a/main.py b/main.py
index 66db0eb..aebdc53 100644
--- a/main.py
+++ b/main.py
@@ -8,34 +8,33 @@ import random
import pygame
from pygame.locals import *
+from robot import Robot
+
pygame.init()
# Screen size
window_h = 600
window_w = 800
+unit = 1.0
+speed = 9
+
screen = pygame.display.set_mode((window_w, window_h))
# Background image
object_background = pygame.image.load('images/park_2.png')
screen.blit(object_background, (0, 0))
+# Robot
+robot = Robot( window_w, window_h, unit, speed)
+
# Normal speed
-speed = 9
+
# Garbage image
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_1.png')
-position_robot = [0, window_h - object_robot.get_height()]
-x_direction = 0
-y_direction = 0
-screen.blit(object_robot, position_robot)
-
-
-
# Initialize images
pygame.display.update()
@@ -56,33 +55,10 @@ while not exit:
(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
- # Uncomment this if you want the robot to stop when you release the keys
-# 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
-
+ robot.input(event)
if exit:
break
-
+
current_time = time.time()
if current_time - start_time <= frame_time:
continue
@@ -100,16 +76,18 @@ while not exit:
screen.blit(text, (0, 0))
# Robot
- screen.blit(object_robot, (position_robot[0], position_robot[1]))
- # Move the character around the screen
- position_robot = [((position_robot[0] + x_direction * speed )%window_w), \
- ((position_robot[1] + y_direction * speed )%window_h) ]
+ #screen.blit(object_robot, (position_robot[0], position_robot[1]))
+ robot.draw(screen)
# Garbage
screen.blit(object_garbage, (position_garbage[0], position_garbage[1]))
position_garbage = [((position_garbage[0] + random.randint(0,10) )%window_w), \
((position_garbage[1] + random.randint(0,10) )%window_h) ]
# position_garbage = [(position_garbage[0] + 3 ), (position_garbage[1] + 3 ) ]
+ robot.update()
+ # Add score if you pick garbage
+ #if position_garbage == position_robot:
+ # score = score + 1
pygame.display.update()
pygame.quit()