示例#1
0
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)
示例#2
0
def do_game_over(state):
        destroy_mover.add(state, ENT_MAN, do_replace=True)
        entities.insert(state,
                        "game_over",
                        GAME_OVER_SPRITEDEF,
                        (1.0, 2.0, 0.0),
                        (0,0),
                        screen_relative=True
                        )
示例#3
0
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)