def __init__(self, pos, image, space, anim_name="", num_frames=1, sequence=[0, 1], frequency=8): self.is_movable = True GameObject.__init__( self, pos, util.to_sprite(util.load_image("data/info_sign0.png")), space, OBJECT_TYPE_INFO, pm.inf ) self.body, self.shape = create_box(space, (pos.x, pos.y), frequency, 12.0) self.shape.collision_type = OBJECT_TYPE_INFO self.info_bubble = util.load_image(image) space.add_static(self.shape) self._show_info = False self.cool_down = 0.0 if not anim_name == "": self.animation = animation.new_animation(anim_name, "png", num_frames, frequency, sequence) self.animation.play()
def __init__(self,pos,finish_time,time_until_play = 0.0): self.map_time = finish_time self.draw_pos = pos self.empty_timer = util.load_image("data/timer_empty0.png") self.blue_timer = util.load_image("data/timer_blue0.png") self.green_timer = util.load_image("data/timer_green0.png") self.red_timer = util.load_image("data/timer_red0.png") self.stopwatch = util.load_image("data/stopwatch0.png") self.red_animation = animation.new_animation("data/timer_red","png",1,8,[0,1]) self.timer_finish = finish_time self.time_until_finish = self.map_time self.time_until_play = time_until_play self.timer_on = False self.has_stopped = False self.rect = self.empty_timer.get_rect() self.wait_until_play = False self._show = True
def __init__(self, pos, space): gameobject.GameObject.__init__(self, pos, util.to_sprite(util.load_image("data/bw_player16.png")), space, gameobject.OBJECT_TYPE_PLAYER, 10.0) self.body, self.shape = gameobject.create_ball(space, (pos.x, pos.y), 8, 6) space.add(self.body, self.shape) self.shape.collision_type = gameobject.OBJECT_TYPE_PLAYER #self.shape.collision_type = gameobject.OBJECT_TYPE_PLAYER self.stop_hammer_time = False self.in_air = True self.is_pushing = False self.honk_timer = False self.honk_time = 4 self.time_to_honk = 0 self.show_honk = False self.honk_animation = animation.new_animation("data/honk_honk","png",1,1,[0,1,1]) self.honk_animation_r = animation.new_animation("data/honk_honk_r","png",1,1,[0,1,1]) #util.load_image("data/honk_honk0.png")#animation.new_animation("data/") self.animations = {} self.active_color = game.CBLUE #load animations animation_freq = 4 red_player_push_left = animation.new_animation("data/red_guy_push","png",1,animation_freq,[0,1]) red_player_push_right = animation.new_animation("data/red_guy_push_r","png",1,animation_freq,[0,1]) red_player_walk_left = animation.new_animation("data/red_guy_walk","png",1,animation_freq,[0,1]) red_player_walk_right = animation.new_animation("data/red_guy_walk_r","png",1,animation_freq,[0,1]) green_player_walk_left = animation.new_animation("data/green_guy_walk","png",1,animation_freq,[0,1]) green_player_walk_right = animation.new_animation("data/green_guy_walk_r","png",1,animation_freq,[0,1]) green_player_push_left = animation.new_animation("data/green_guy_push","png",1,animation_freq,[0,1]) green_player_push_right = animation.new_animation("data/green_guy_push_r","png",1,animation_freq,[0,1]) blue_player_walk_left = animation.new_animation("data/blue_guy_walk","png",1,animation_freq,[0,1]) blue_player_walk_right = animation.new_animation("data/blue_guy_walk_r","png",1,animation_freq,[0,1]) blue_player_push_left = animation.new_animation("data/blue_guy_push","png",1,animation_freq,[0,1]) blue_player_push_right = animation.new_animation("data/blue_guy_push_r","png",1,animation_freq,[0,1]) #player_walk_left.play() self.image = None # red player animations: self.animations["red_player_walk_left"] = red_player_walk_left self.animations["red_player_walk_right"] = red_player_walk_right self.animations["red_player_push_left"] = red_player_push_left self.animations["red_player_push_right"] = red_player_push_right # green player animations: self.animations["green_player_walk_left"] = green_player_walk_left self.animations["green_player_walk_right"] = green_player_walk_right self.animations["green_player_push_left"] = green_player_push_left self.animations["green_player_push_right"] = green_player_push_right # blue player animations: self.animations["blue_player_walk_left"] = blue_player_walk_left self.animations["blue_player_walk_right"] = blue_player_walk_right self.animations["blue_player_push_left"] = blue_player_push_left self.animations["blue_player_push_right"] = blue_player_push_right self.current_animation = red_player_walk_left self.look_dir = game.PDIR_LEFT self.active_color = game.CRED self.has_changed = True
def run(self): pxf_logo = animation.new_animation("data/pxf_logo0", "png", 12, 5, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12][:-1]) pxf_logo.play() intro_end_time = 5000 while self.playing_intro: self.dt_last_frame = self.clock.tick(60) intro_end_time -= self.dt_last_frame if intro_end_time <= 0: self.playing_intro = False self.screen.fill([0,0,0]) for event in pygame.event.get(): if event.type == QUIT: self.playing_intro = False self.is_running = False if event.type == pygame.KEYUP: if (event.key == K_ESCAPE): self.playing_intro = False pxf_logo.update(self.dt_last_frame) pxf_logo.draw(self.screen, (self.size[0] / 2 - 64, self.size[1] / 2 - 64), True) if self.scale: pygame.transform.scale2x(self.screen, self.actual_screen) else: self.actual_screen.blit(self.screen, (0, 0)) pygame.display.flip() #self.set_level(stage.Stage1(self.camera, self.player, self.space)) self.start_new_level(self.current_stage_id) while self.is_running: # update time self.dt_last_frame = self.clock.tick(60) if (self.restart_level_counter > 0): self.player.body.position = (-111111, -111111) self.restart_level_counter -= self.dt_last_frame / 1000.0 if (self.restart_level_counter <= 0): self.start_new_level(self.current_stage_id) # event handling if (self.restart_level_counter < 0): for event in pygame.event.get(): if event.type == QUIT: self.is_running = False elif event.type in (KEYDOWN, KEYUP): self.handle_input(event) # handle game input self.game_input() self.screen.fill([0,0,0]) # update animation #self.anim_test.update(self.dt_last_frame) #self.anim_test.draw(self.screen) # update player self.player.update(self.camera.get_pos(),self.dt_last_frame) # update physics self.space.step(1/60.0) if (self.remove_player): self.space.add_collisionpair_func(gameobject.OBJECT_TYPE_PLAYER, gameobject.OBJECT_TYPE_RED, None) self.space.add_collisionpair_func(gameobject.OBJECT_TYPE_PLAYER, gameobject.OBJECT_TYPE_GREEN, None) self.space.add_collisionpair_func(gameobject.OBJECT_TYPE_PLAYER, gameobject.OBJECT_TYPE_BLUE, None) self.space.add_collisionpair_func(gameobject.OBJECT_TYPE_PLAYER, gameobject.OBJECT_TYPE_BW, None) self.remove_player = False # update game objects for object in self.current_stage.tiles: #object.update(self.camera.pos) object.update(self.camera.get_pos()) for splosion in self.current_stage.splosion_objects: splosion.update(self.camera.get_pos()) for obj in self.current_stage.game_objects: obj.update(self.camera.get_pos()) for inf in self.current_stage.info_blocks: inf.update(self.camera.get_pos(),self.dt_last_frame) # update camera if (self.restart_level_counter < 0): self.camera.set_lookat(util.vec2(self.player.body.position.x, self.player.body.position.y)) self.camera.update() # draw billboards for billboard in self.billboards: billboard.update(self.camera.get_pos(),self.dt_last_frame) billboard.draw(self.screen) # update game self.current_stage.draw(self.screen) if self.animate_door: self.door_anim.update(self.dt_last_frame) p = self.current_stage.doorpos p = (p[0] - self.camera.get_pos().x, p[1] - self.camera.get_pos().y) self.door_anim.draw(self.screen, p, True) if self.door_anim.current == len(self.door_anim.frames)-1: self.start_new_level(self.current_stage_id + 1) self.door_anim.current = 0 self.animate_door = False self.door_anim.stop() elif self.door_anim.current == 3: self.fade_in_out = True self.fade_in_out_time = 3 self.player.draw(self.screen) # draw key gui self.gui_key.draw(self.screen) self.map_timer.update(self.dt_last_frame) self.map_timer.draw(self.screen) self.check_timer() if self.fade_in_out: self.fade_in_out_time -= self.dt_last_frame / 1000.0 surf = pygame.Surface(self.size) surf.fill((0, 0, 0)) if self.fade_in_out_time > 2.0: a = 255 - int(255 * ((self.fade_in_out_time-2.0)/2.0)) else: a = int(255 * ((self.fade_in_out_time)/1.0)) surf.set_alpha(a) self.screen.blit(surf, (0, 0)) if self.fade_in_out_time <= 0.0: self.fade_in_out = False # fps limit #3self.clock.tick(25) self.update_title() if self.scale: pygame.transform.scale2x(self.screen, self.actual_screen) else: self.actual_screen.blit(self.screen, (0, 0)) # swap buffers pygame.display.flip()