diff options
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 86 |
1 files changed, 57 insertions, 29 deletions
@@ -9,6 +9,9 @@ import pygame from pygame.locals import * from robot import Robot +from garbage import Garbage +from person import Person + pygame.init() @@ -16,35 +19,37 @@ pygame.init() window_h = 600 window_w = 800 unit = 1.0 -speed = 9 -screen = pygame.display.set_mode((window_w, window_h)) +robot_speed = 9 +garbage_speed = 3 +person_speed = 4 -# 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) +# Person generation interval +person_generation_ticks = 100 +last_person_tick = 0 -# Normal speed +#garbages = [] +people = [] +screen = pygame.display.set_mode((window_w, window_h)) -# Garbage image -object_garbage = pygame.image.load('images/paper.png') -position_garbage = [ 400, 300 ] -screen.blit(object_garbage, position_garbage) +# Background image +object_background = pygame.image.load('images/park_2.png') -# Initialize images -pygame.display.update() -position_garbage = [0,0] +# Robot +robot = Robot(window_w, window_h, unit, robot_speed) +# Person +person = Person( window_w, window_h, unit, person_speed) + start_time = time.time() fps = 30 frame_time = 1.0/fps # Main loop exit = False +lost_game = False while not exit: @@ -63,32 +68,55 @@ while not exit: 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 + if lost_game == False: + # If enough time passed generate a new object + if last_person_tick == 0: + last_person_tick = person_generation_ticks + people.append(Person( window_w, window_h, unit, person_speed)) + else: + last_person_tick -= 1 + # Score text score = 10 - score_text = "Score: " + str(score) + score_text = "Score: " + str(score) + " Next in : " + str(last_person_tick) font = pygame.font.Font(None, 36) text = font.render( score_text , 1, (0, 0, 0, 0)) - screen.blit(text, (0, 0)) - - # Robot - 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) ] + # check collisions + for person in people: + if robot.collides_with(person): + #lost_game = True + people.remove(person) + + # Remove objects that "died" + for person in people: + if person.died(): + people.remove(person) + + # update objects + for person in people: + person.update() + robot.update() + + # draw the background first, because it will cover all the screen + screen.blit(object_background, (0,0)) + # draw everything else over the background + # Score + screen.blit(text, (0, 0)) + + # Persons + for person in people: + person.draw(screen) + #Robot + robot.draw(screen) # Add score if you pick garbage #if position_garbage == position_robot: # score = score + 1 + pygame.display.update() pygame.quit() |