def collision_handler(state, collisions_list): for entity_name_1, entity_name_2 in collisions_list: if entity_name_1 == ENT_MAN: if entity_name_2 == ENT_SHOT: pass elif entity_name_2 == ENT_GHOST: entities.undo_last_move(state, ENT_MAN) if not movers.get_active(state, ENT_GHOST)[0] == "wait": wait_mover.add(state, ENT_GHOST, 1.0, prepend=True) incr_health(state, -80) if get_health(state) <= 0: do_game_over(state) else: entities.undo_last_move(state, ENT_GHOST) elif entity_name_2[0:len(ENT_PREFIX_COINS)] == ENT_PREFIX_COINS: incr_score(state, 10) destroy_mover.add(state, entity_name_2, do_replace=True) else: entities.undo_last_move(state, entity_name_1) elif entity_name_1 == ENT_SHOT: if entity_name_2[0:len(ENT_PREFIX_COINS)] == ENT_PREFIX_COINS: pass elif entity_name_2 == ENT_GHOST: do_ghost_boom(state, entities.get_pos(state, ENT_GHOST)) destroy_mover.add(state, ENT_GHOST, do_replace=True) do_shot_boom(state, entities.get_pos(state, ENT_SHOT)) destroy_mover.add(state, ENT_SHOT, do_replace=True) else: do_shot_boom(state, entities.get_pos(state, ENT_SHOT)) destroy_mover.add(state, ENT_SHOT, do_replace=True)
def on_fire_button(state, button_pressed): if button_pressed and not entities.get(state, ENT_SHOT): man_pos = entities.get_pos(state, ENT_MAN) man_rot = math.radians(man_pos[2] + 90.0) heading_x = math.cos(man_rot) heading_y = math.sin(man_rot) start_pos = (man_pos[0] + (START_OFFSET_FACTOR * heading_x), man_pos[1] + (START_OFFSET_FACTOR * heading_y), 0, ) heading = ((TRAVEL_DISTANCE * heading_x), (TRAVEL_DISTANCE * heading_y), ) entities.insert(state, ENT_SHOT, SHOT_SPRITE_DEF, start_pos, SHOT_SPRITE_OFFSET, collision=SHOT_COLLISION_DEF, ) linear_mover.add(state, ENT_SHOT, heading, SHOT_SPEED, SHOT_ROTATE_DEF, None, True) destroy_mover.add(state, ENT_SHOT)
def on_timer(state, last_frame_delta): phys_mover = movers.get_active(state, ENT_PLAYER_CAR) if phys_mover: exhaust_sprite_name = entities.get_active_sprite_name( state, ENT_PLAYER_CAR_EXHAUST) if not sprites.is_enabled(state, exhaust_sprite_name): do_exhaust( state, math_2d.get_radial_offset( entities.get_pos(state, ENT_PLAYER_CAR), -0.25))
def create(state, entity_name, width, height, offset, speed): """ """ start_pos = entities.get_pos(state, entity_name) orig_x,orig_y,old_angle = start_pos centre_x = orig_x + (width / 2.0) centre_y = orig_y + (height / 2.0) offset_x = centre_x + offset return [FLIPPER_MOVER_NAME, run, entity_name, collision_handler, start_pos, width, height, offset, speed, (offset_x, centre_y), (centre_x, centre_y), 0.0, ]
def create(state, entity_name, width, height, offset, speed): """ """ start_pos = entities.get_pos(state, entity_name) orig_x, orig_y, old_angle = start_pos centre_x = orig_x + (width / 2.0) centre_y = orig_y + (height / 2.0) offset_x = centre_x + offset return [ FLIPPER_MOVER_NAME, run, entity_name, collision_handler, start_pos, width, height, offset, speed, (offset_x, centre_y), (centre_x, centre_y), 0.0, ]
def on_timer(state, last_frame_delta): phys_mover = movers.get_active(state, ENT_PLAYER_CAR) if phys_mover: exhaust_sprite_name = entities.get_active_sprite_name(state, ENT_PLAYER_CAR_EXHAUST) if not sprites.is_enabled(state, exhaust_sprite_name): do_exhaust(state, math_2d.get_radial_offset(entities.get_pos(state, ENT_PLAYER_CAR), -0.25))