def add_trash(dt): global game_objects global trash_label global count x_pos = randint(300, window.width - 300) if window.current_state == 2: # Game Scene new_trash = trash.Trash(x=x_pos, y=window.height, batch=main_batch) # increase speed trash falls based on score if score > 100: new_trash.dy = randint(50, 80) if score > 30: new_trash.dy = randint(40, 70) elif score > 20: new_trash.dy = randint(40, 65) elif score > 15: new_trash.dy = randint(30, 60) elif score > 10: new_trash.dy = randint(30, 60) elif score > 5: new_trash.dy = randint(30, 60) # add trash to game objects game_objects.append(new_trash) trash_label.text = new_trash.name # change rate new trash appears based on how many new trash have been added count += 1
def tick(self): self.player.move() if self.player.pos.x>800 and self.howmuch == 0: self.howmuch = 1 self.trashs.append(trash.Trash( self.screen, 900, 520)) if self.time > 30: if int(self.time)%4 == 0: self.newBin() if int(self.time*10)%42 == 0: self.time+=1
def reset_level(): # pass global score, count, lives, lives_sprites, game_objects score = 0 score_label.text = "Score: " + str(score) count = 0 lives = 4 for obj in game_objects: if isinstance(obj, trash.Trash): obj.delete() game_objects = [bins] + [ trash.Trash(x=window.width // 2, y=window.height, batch=main_batch) ] game_over_label.y = -300 restart_button.y = -300 lives_sprites = [pyglet.sprite.Sprite(img=life, \ x=window.width - life.width - 35*i - 30,\ y=window.height - life.height - 30, batch=main_batch) \ for i in range(lives)] # remove event to listen to restart button pyglet.clock.unschedule(add_trash) pyglet.clock.schedule_interval(add_trash, 7) window.pop_handlers()
import pyglet from character import Character from physicalobject import PhysicalObject import window import resources import bins import trash from random import randint window = window.Window() main_batch = window.states[2].batch # GameScene # main game objects bins = bins.Bin(x=window.width // 2, y=80, batch=main_batch) trash_obj = trash.Trash(x=window.width // 2, y=window.height, batch=main_batch) # Set up top labels score_label = pyglet.text.Label(text="Score: 0", x=10, y=window.height - 20, batch=main_batch) level_label = pyglet.text.Label(text="WRM: It's a Game!", x=window.width - 100, y=window.height - 20, anchor_x='center', batch=main_batch) trash_objects = [trash_obj] trash_label = pyglet.text.Label(text=trash_obj.name, x=window.width / 2, y=window.height - 20, batch=main_batch,
def throwTrash(screen, pos): global t_actual t_actual = trash.Trash("trash", t_actual.trash_type, pos) t_actual.throwTrash(screen, pos)
def throwTrashNew(screen, pos): global t_actual t_actual = trash.Trash("trash", random.choice(list(trashtype.TrashType)), pos) t_actual.throwTrash(screen, pos)
window_width = 992 window_height = 800 FPS = 30 level = map.Map(32) level.load_map("mapa2") neuralnet = neuralnetwork.neuralnetwork() entity_manager = entity_manager.Entity_manager() entity_manager.add(bomb.Bomb(7, 12, "bomba.gif", level, neuralnet)) entity_manager.add(bomb.Bomb(8, 15, "bomba.gif", level, neuralnet)) entity_manager.add(bomb.Bomb(11, 5, "bomba.gif", level, neuralnet)) entity_manager.add(trash.Trash(15, 4, "bomba.gif", level, neuralnet)) entity_manager.add(bomb.Bomb(3, 7, "bomba.gif", level, neuralnet)) entity_manager.add(saper.Saper(4, 3, 0, "saper.gif", level, entity_manager)) #-------------------------------------------------------------------------------- gameDisplay = pygame.display.set_mode((window_width, window_height)) pygame.display.set_caption('Inteligentny Saper') clock = pygame.time.Clock() gameExit = False while not gameExit: #game_loop for event in pygame.event.get(): #event_loop if event.type == pygame.QUIT: gameExit = True if event.type == pygame.KEYDOWN: