Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/main.py
blob: aebdc53e3fd84b4513c773b180c3a306995b497c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Robot saving nature

import os
import sys
import time
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


# Garbage image
object_garbage = pygame.image.load('images/paper.png')
position_garbage = [ 400, 300 ]
screen.blit(object_garbage, position_garbage)

# Initialize images 
pygame.display.update()

position_garbage = [0,0]
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
		robot.input(event)
	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
	
	# Score text
	score = 10
	score_current = "Score: " + str(score)
	font = pygame.font.Font(None, 36)
	text = font.render( score_current , 1, (0, 0, 0, 0))
	screen.blit(text, (0, 0))
		
	# Robot
	#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()