Ejemplo n.º 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)
Ejemplo n.º 2
0
        def build(self):
                state = factory.create(screen_width, screen_height, tile_size)

                tiles.add_tile_def(state, ' ', ("assets/img/tiles/blank.png",))
                tiles.add_tile_def(state, '+', ("assets/img/tiles/block.png",),
                                   (("rectangle", 0, 0, 1, 1),))
                area_strings = (
                        "    ",
                        " +  ",
                        "    ",
                        " +  ",
                        "    ",
                        )
                tiles.set_area(state, tiles_helpers.strings_to_chars(area_strings))

                collisions.set_handler(state, collision_handler)

                BALL_SIZE = (1.0 / 4.0)
                CIRCLE_RADIUS = BALL_SIZE / 2
                entities.insert(state,
                                "ball",
                                {
                                 "*": {
                                       "textures": ("assets/img/sprites/quarter_ball.png",),
                                       },
                                 },
                                (1.25, 0, 0,),
                                collision=(("circle", CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS,),)
                                )

                linear_mover.add(state, "ball", (0, 7), 1.5)

                return ScreenWidget(state, debugging=True)
Ejemplo n.º 3
0
def start_movement(state, mover_name):
    n_steps = 20
    for index in xrange(n_steps):
        degrees = float(index) / n_steps * 360.0
        dx = math.cos(math.radians(degrees)) / n_steps
        dy = math.sin(math.radians(degrees)) / n_steps
        linear_mover.add(state, "500_text_1", (dx, dy), 0.5, ("auto", 0),
                         None if index != n_steps - 1 else start_movement)
Ejemplo n.º 4
0
def start_stars_movement(state, mover_name):
    int_screen_width = int(screen.get_width(state))
    int_screen_height = int(screen.get_height(state))
    for x in xrange((int_screen_width / 256) + 1):
        for y in xrange((int_screen_height / 256) + 2):
            entity_name = star_name(x, y)
            jump_mover.add(state, entity_name, ((x * 2), (y * 2), 0))
            linear_mover.add(state, entity_name, (0, -2), 0.25)
    wait_mover.add(state, entity_name, 0, start_stars_movement)
Ejemplo n.º 5
0
def start_movement(state, mover_name):
    path = ((5.0, 0), (0, 5.0), (-5.0, 0), (0, -5.0))
    for index in xrange(len(path)):
        set_property_mover.add(state, "man", "set_active_sprite", "idle")
        wait_mover.add(state, "man", 2.0)
        set_property_mover.add(state, "man", "set_active_sprite", "walk")
        rel_vector = ((path[index][0]), (path[index][1]))
        linear_mover.add(state, "man", rel_vector, 1.0, ("auto", 0),
                         None if index != len(path) - 1 else start_movement)
Ejemplo n.º 6
0
def start_stars_movement(state, mover_name):
        int_screen_width = int(screen.get_width(state))
        int_screen_height = int(screen.get_height(state))
        for x in xrange((int_screen_width / 256) + 1):
                for y in xrange((int_screen_height / 256) + 2):
                        entity_name = star_name(x, y)
                        jump_mover.add(state, entity_name, ((x * 2), (y * 2), 0))
                        linear_mover.add(state, entity_name, (0, -2), 0.25)
        wait_mover.add(state, entity_name, 0, start_stars_movement)
Ejemplo n.º 7
0
def start_movement(state, mover_name):
        path = ((5.0, 0), (0, 5.0), (-5.0, 0), (0, -5.0))
        for index in xrange(len(path)):
                set_property_mover.add(state, "man", "set_active_sprite", "idle")
                wait_mover.add(state, "man", 2.0)
                set_property_mover.add(state, "man", "set_active_sprite", "walk")
                rel_vector = ((path[index][0]), (path[index][1]))
                linear_mover.add(state, "man", rel_vector, 1.0,
                        ("auto", 0), None if index != len(path) - 1 else start_movement)
Ejemplo n.º 8
0
def start_ghost_movement(state, mover_name):
        path = (
                (2.0, 0.0),
                (0.0, 2.0),
                (-2.0, 0.0),
                (0.0, -2.0),
                )
        for index in xrange(len(path)):
                rel_vector = ((path[index][0]), (path[index][1]))
                linear_mover.add(state, ENT_GHOST, rel_vector, 1.0, on_end_function=None if index != len(path) - 1 else start_ghost_movement)
Ejemplo n.º 9
0
def start_movement(state, mover_name):
        n_steps = 20
        for index in xrange(n_steps):
                degrees = float(index) / n_steps * 360.0
                dx = math.cos(math.radians(degrees)) / n_steps
                dy = math.sin(math.radians(degrees)) / n_steps
                linear_mover.add(state, "500_text_1",
                        (dx, dy),
                        0.5,
                        ("auto", 0), None if index != n_steps - 1 else start_movement)
Ejemplo n.º 10
0
    def build(self):
        state = factory.create(screen_width, screen_height, tile_size)

        tiles.add_tile_def(state, ' ', ("assets/img/tiles/blank.png", ))
        tiles.add_tile_def(state, '+', ("assets/img/tiles/block.png", ),
                           (("rectangle", 0, 0, 1, 1), ))
        area_strings = (
            "    ",
            " +  ",
            "    ",
            " +  ",
            "    ",
        )
        tiles.set_area(state, tiles_helpers.strings_to_chars(area_strings))

        collisions.set_handler(state, collision_handler)

        BALL_SIZE = (1.0 / 4.0)
        CIRCLE_RADIUS = BALL_SIZE / 2
        entities.insert(state,
                        "ball", {
                            "*": {
                                "textures":
                                ("assets/img/sprites/quarter_ball.png", ),
                            },
                        }, (
                            1.25,
                            0,
                            0,
                        ),
                        collision=((
                            "circle",
                            CIRCLE_RADIUS,
                            CIRCLE_RADIUS,
                            CIRCLE_RADIUS,
                        ), ))

        linear_mover.add(state, "ball", (0, 7), 1.5)

        return ScreenWidget(state, debugging=True)