Exemplo n.º 1
0
def create(screen_width, screen_height, tile_size):
    ENT_PADDLE = "500_paddle"
    ENT_BALL = "500_ball"

    PADDLE_WIDTH = (1.0 / 2.0)
    PADDLE_HEIGHT = (1.0 / 8.0)
    PADDLE_Y = 2.0
    BOTTOM_Y = 1.5
    BORDER_THICKNESS = 2.0
    BORDER_OFFSET = 0.1

    BALL_MOVE_SPEED = 100.0
    BALL_ANIM_SPEED = 3.0
    BALL_START_POS = (1.0, (2.0 + 0.5), 0)
    BALL_VXY = 2.0
    BLOCK_WIDTH = (1.78 / 3.5)
    BLOCK_HEIGHT = (1.0 / 3.5)
    BLOCK_X = 0.1
    BLOCK_Y = 4.5

    state = factory.create(screen_width, screen_height, tile_size)

    tiles.add_tile_def(state, ".", ("assets/img/tiles/grid_double.png", ))
    tiles.set_area(state, [["." for x in xrange(10)] for x in xrange(10)])

    entities_helpers.create_screen_wall(state,
                                        "000_screenbox",
                                        BORDER_THICKNESS,
                                        BORDER_OFFSET,
                                        BOTTOM_Y,
                                        color=(0, 0.15, 1))

    for row in xrange(5):
        for col in xrange(7):
            fix_row = row
            fix_col = col

            block_entity_name = ENT_BLOCK_BASE + "_%d_%d" % (col, row)
            color = (0.5, 0.2, 1) if ((row + col) % 2 == 0) else (0, 1, 0)
            entities.insert(state,
                            block_entity_name, {
                                "*": {
                                    "textures":
                                    (("rectangle", BLOCK_WIDTH, BLOCK_HEIGHT,
                                      color[0], color[1], color[2]), ),
                                },
                            }, (BLOCK_X + (fix_col * BLOCK_WIDTH), BLOCK_Y +
                                (fix_row * BLOCK_HEIGHT), 0),
                            collision=((("rectangle", 0, 0, BLOCK_WIDTH,
                                         BLOCK_HEIGHT), )))

    entities.insert(
        state,
        ENT_PADDLE, {
            "*": {
                "textures":
                (("rectangle", PADDLE_WIDTH, PADDLE_HEIGHT, 1, 1, 1), ),
            },
        }, (1.75, PADDLE_Y, 0),
        collision=((("rectangle", 0, 0, PADDLE_WIDTH, PADDLE_HEIGHT), )))

    entities.insert(
        state,
        ENT_BALL, {
            "*": {
                "textures":
                (("ellipse", PADDLE_HEIGHT, PADDLE_HEIGHT, 1, 1, 1), ),
            },
        },
        BALL_START_POS,
        collision=((("circle", (PADDLE_HEIGHT / 2.0), (PADDLE_HEIGHT / 2.0),
                     (PADDLE_HEIGHT / 2.0)), )))

    physical_mover.add(
        state,
        ENT_BALL,
        1,
        BALL_VXY,
        BALL_VXY,
        0,
        0,
        1,
        1,
        0,
        0,
        1,
        0,
    )

    collisions.set_handler(state, collision_handler)

    controls.add_joystick(state)

    controlled_mover.add(state, ENT_PADDLE, "joystick", 0.1, [
        BORDER_OFFSET, PADDLE_Y,
        (float(screen_width) / tile_size) - PADDLE_WIDTH - BORDER_OFFSET,
        PADDLE_Y
    ])

    return state
Exemplo n.º 2
0
def create(screen_width, screen_height, tile_size):
        state = factory.create(screen_width, screen_height, tile_size)

        BOTTOM_Y = 0.5
        BORDER_THICKNESS = 2.0
        BORDER_OFFSET = 0.1
        WALLS_COLOR = (0.3, 0.45, 1)
        tiles.add_tile_def(state, " ", ("assets/img/tiles/grid_double.png",))
        tiles.set_area(state, [[" " for x in xrange(10)] for x in xrange(10)])
        entities_helpers.create_screen_wall(state, "000_screenbox", BORDER_THICKNESS, BORDER_OFFSET, BOTTOM_Y, color=WALLS_COLOR)

        # collisions.set_handler(state, collision_handler)

        for i in xrange(4):
                objtype = random.randint(0, 2)
                ent_name = "%d" % i
                ent_mass = 1.0
                angle = random.randint(0, 20) - 10.0

                if objtype == 0:
                        ent_name = "square_" + ent_name
                        if i % 2 == 0:
                                tx = "assets/img/sprites/half_square.png"
                        else:
                                tx = "assets/img/sprites/half_square_2.png"

                        entities.insert(state,
                                        ent_name,
                                        {
                                         "*": {
                                               "textures": (tx,),
                                               },
                                         },
                                        (0.5 + i * 0.75, 5, angle,),
                                        collision=(("rectangle", 0, 0, 0.5, 0.5),)
                                        )
                elif objtype == 1:
                        ent_name = "circle_" + ent_name
                        if i % 2 == 0:
                                tx = "assets/img/sprites/half_ball.png"
                        else:
                                tx = "assets/img/sprites/half_ball_2.png"

                        entities.insert(state,
                                ent_name,
                                {
                                        "*": {
                                                "textures": (tx,),
                                        },
                                },
                                (0.5 + i * 0.75, 4.0, angle),
                                collision=(("circle", 0.25, 0.25, 0.25),))

                elif objtype == 2:
                        ent_mass = 2.0
                        ent_name = "rect_" + ent_name
                        if i % 2 == 0:
                                tx = "assets/img/sprites/one_by_half_rectangle.png"
                        else:
                                tx = "assets/img/sprites/one_by_half_rectangle_2.png"

                        entities.insert(state,
                                        ent_name,
                                        {
                                         "*": {
                                               "textures": (tx,),
                                               },
                                         },
                                        (0.5 + i * 0.75, 3.0, 90 + angle,),
                                        collision=(("rectangle", 0, 0, 1.0, 0.5),)
                                        )

                physical_mover.add (state,
                                    ent_name,
                                    ent_mass,
                                    0,
                                    0,
                                    0.0,
                                    YAPYG_STD_GRAVITY,
                                    YAPYG_STD_FRICTION,
                                    YAPYG_STD_INELASTICITY,
                                    0,
                                    YAPYG_STD_ROT_FRICTION,
                                    YAPYG_STD_ROT_DECAY,
                                    YAPYG_STD_STICKYNESS,
                                    )

        return state
Exemplo n.º 3
0
        def build(self):
                state = factory.create(screen_width, screen_height, tile_size)

                BOTTOM_Y = 0.5
                BORDER_THICKNESS = 2.0
                BORDER_OFFSET = 0.1
                WALLS_COLOR = (0.3, 0.45, 1)
                tiles.add_tile_def(state, " ", ("assets/img/tiles/grid_double.png",))
                tiles.set_area(state, [[" " for x in xrange(10)] for x in xrange(10)])
                entities_helpers.create_screen_wall(state, "000_screenbox", BORDER_THICKNESS, BORDER_OFFSET, BOTTOM_Y, color=WALLS_COLOR)

                # collisions.set_handler(state, collision_handler)

                show_collision = True # False
                speed_factor = 1.0
                target_is_physical = False

                if show_collision:
                        # circle collision
                        BOUNCE_GRAVITY = 0.0
                        BOUNCE_INELASTICITY = 0.999
                        BOUNCE_FRICTION = 0.999
                        BOUNCE_STICKYNESS = 0.5
                        ROT_FRICTION = 0.35
                        ROT_DECAY = 0.9
                        VX_1 = 0.0
                        VY_1 = -1.0
                else:
                        # Single circle
                        BOUNCE_GRAVITY = 0.0
                        BOUNCE_INELASTICITY = 0.9
                        BOUNCE_FRICTION = 0.9999
                        BOUNCE_STICKYNESS = 0.0
                        ROT_FRICTION = 0.35
                        ROT_DECAY = 0.9999
                        VX_1 = 0.5
                        VY_1 = -1.0
                VX_1 *= speed_factor
                VY_1 *= speed_factor

                entities.insert(state,
                                "c_1",
                                {
                                 "*": {
                                       "textures": ("assets/img/sprites/half_ball.png",),
                                       },
                                 },
                                (1.75, 5.0, 0.0,),
                                collision=(("circle", 0.25, 0.25, 0.25),)
                                )

                physical_mover.add(state,
                        "c_1",
                        1.0,
                        VX_1,
                        VY_1,
                        0.0,
                        BOUNCE_GRAVITY,
                        BOUNCE_FRICTION,
                        BOUNCE_INELASTICITY,
                        0,
                        ROT_FRICTION,
                        ROT_DECAY,
                        BOUNCE_STICKYNESS,
                        )

                if show_collision:
                        entities.insert(state,
                                        "c_2",
                                        {
                                         "*": {
                                               "textures": ("assets/img/sprites/half_ball_2.png",),
                                               },
                                         },
                                        (1.75, 4.0, 0.0,),
                                        collision=(("circle", 0.25, 0.25, 0.25),)
                                        )

                        if target_is_physical:
                                physical_mover.add(state,
                                        "c_2",
                                        1.0,
                                        0,
                                        0,
                                        0,
                                        BOUNCE_GRAVITY,
                                        BOUNCE_FRICTION,
                                        BOUNCE_INELASTICITY,
                                        0,
                                        ROT_FRICTION,
                                        ROT_DECAY,
                                        BOUNCE_STICKYNESS,
                                        )

                return ScreenWidget(state, debugging=False)
Exemplo n.º 4
0
def create(screen_width, screen_height, tile_size):
        ENT_PADDLE = "500_paddle"
        ENT_BALL = "500_ball"

        PADDLE_WIDTH = (1.0 / 2.0)
        PADDLE_HEIGHT = (1.0 / 8.0)
        PADDLE_Y = 2.0
        BOTTOM_Y = 1.5
        BORDER_THICKNESS = 2.0
        BORDER_OFFSET = 0.1

        BALL_MOVE_SPEED = 100.0
        BALL_ANIM_SPEED = 3.0
        BALL_START_POS = (1.0, (2.0 + 0.5), 0)
        BALL_VXY = 2.0
        BLOCK_WIDTH = (1.78 / 3.5)
        BLOCK_HEIGHT = (1.0 / 3.5)
        BLOCK_X = 0.1
        BLOCK_Y = 4.5

        state = factory.create(screen_width, screen_height, tile_size)

        tiles.add_tile_def(state, ".", ("assets/img/tiles/grid_double.png",))
        tiles.set_area(state, [["." for x in xrange(10)] for x in xrange(10)])

        entities_helpers.create_screen_wall(state, "000_screenbox", BORDER_THICKNESS, BORDER_OFFSET, BOTTOM_Y, color=(0, 0.15, 1))

        for row in xrange(5):
                for col in xrange(7):
                        fix_row = row
                        fix_col = col

                        block_entity_name = ENT_BLOCK_BASE + "_%d_%d" % (col, row)
                        color = (0.5, 0.2, 1) if ((row + col) % 2 == 0) else (0, 1, 0)
                        entities.insert(state,
                                block_entity_name,
                                {
                                        "*": {
                                                "textures": (("rectangle", BLOCK_WIDTH, BLOCK_HEIGHT, color[0], color[1], color[2]),),
                                        },
                                },
                                (BLOCK_X + (fix_col * BLOCK_WIDTH), BLOCK_Y + (fix_row * BLOCK_HEIGHT), 0),
                                collision=((("rectangle", 0, 0, BLOCK_WIDTH, BLOCK_HEIGHT),)))

        entities.insert(state,
                ENT_PADDLE,
                {
                        "*": {
                                "textures": (("rectangle", PADDLE_WIDTH, PADDLE_HEIGHT, 1, 1, 1),),
                        },
                },
                (1.75, PADDLE_Y, 0),
                collision=((("rectangle", 0, 0, PADDLE_WIDTH, PADDLE_HEIGHT),)))

        entities.insert(state,
                ENT_BALL,
                {
                        "*": {
                                "textures": (("ellipse", PADDLE_HEIGHT, PADDLE_HEIGHT, 1, 1, 1),),
                        },
                },
                BALL_START_POS,
                collision=(((
                        "circle",
                        (PADDLE_HEIGHT / 2.0),
                        (PADDLE_HEIGHT / 2.0),
                        (PADDLE_HEIGHT / 2.0)),))
                )

        physical_mover.add(state,
                ENT_BALL,
                1,
                BALL_VXY,
                BALL_VXY,
                0,
                0,
                1,
                1,
                0,
                0,
                1,
                0,
                )

        collisions.set_handler(state, collision_handler)

        controls.add_joystick(state)

        controlled_mover.add(state,
                ENT_PADDLE,
                "joystick",
                0.1,
                [BORDER_OFFSET, PADDLE_Y,
                (float(screen_width) / tile_size) - PADDLE_WIDTH - BORDER_OFFSET, PADDLE_Y]
                )

        return state
Exemplo n.º 5
0
def create(screen_width_px, screen_height_px, tile_size_px):
        BOTTOM_Y = 0.0
        BORDER_THICKNESS = 2.0
        BORDER_OFFSET = 0.1

        WALLS_COLOR = (0, 0.15, 1)

        joystick_props = controls.get_joystick_properties()
        origin_xy = (0, joystick_props["h"] * screen_height_px)
        state = factory.create(screen_width_px, screen_height_px, tile_size_px, origin_xy)

        controls.add_buttons(state, (("LEFT", on_left_button, "left", "big"),
                                     ("RIGHT", on_right_button, "right", "big")))

        tiles.add_tile_def(state, ".", ("assets/img/tiles/grid_double.png",))
        tiles.set_area(state, [["."] * 10] * 10)

        entities_helpers.create_screen_wall(state, "000_screenbox", BORDER_THICKNESS, BORDER_OFFSET, BOTTOM_Y,
                        top=False, # bottom=False,
                        color=WALLS_COLOR)

        ball_entity_name = "900_ball_0"

        BALL_SIZE = (1.0 / 4.0)
        CIRCLE_RADIUS = (BALL_SIZE / 2)
        filename = "assets/img/sprites/quarter_ball.png"
        mass = 1

        entities.insert(state,
                ball_entity_name,
                {
                        "*": {
                                "textures": (filename,),
                        },
                },
                (1.75, 4.3, 0,),
                collision=(("circle", CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS,),))

        physical_mover.add(state,
                ball_entity_name,
                mass,
                0,
                0,
                0,
                YAPYG_STD_GRAVITY,
                YAPYG_STD_FRICTION,
                YAPYG_STD_INELASTICITY,
                0,
                YAPYG_STD_ROT_FRICTION,
                YAPYG_STD_ROT_DECAY,
                YAPYG_STD_STICKYNESS,
                )

        ENT_FLIPPER_1 = "000_flipper_1"
        FLIPPER_X = 1.0
        FLIPPER_Y = 1.0
        FLIPPER_WIDTH = 1.0
        FLIPPER_HEIGHT = 0.25
        FLIPPER_ROTATION_OFFSET = -0.5
        FLIPPER_COLOR = (1.0, 0.0, 0.0)
        entities.insert(state,
                              ENT_FLIPPER_1,
                              {
                               "*": {
                                     "textures": (("rectangle", FLIPPER_WIDTH, FLIPPER_HEIGHT,
                                                   FLIPPER_COLOR[0], FLIPPER_COLOR[1], FLIPPER_COLOR[2]),),
                                     },
                               },
                              (FLIPPER_X, FLIPPER_Y, 0.0),
                              collision=((("rectangle", 0.0, 0.0, FLIPPER_WIDTH, FLIPPER_HEIGHT),))
                              )

        flipper_mover.add(state, ENT_FLIPPER_1,
                                 FLIPPER_WIDTH, FLIPPER_HEIGHT,
                                 FLIPPER_ROTATION_OFFSET,
                                 360.0
                                 )

        return state
Exemplo n.º 6
0
def create(screen_width, screen_height, tile_size):
        ENT_BOUNCE_BLOCK_1 = "000_block_1"
        ENT_BOUNCE_BLOCK_2 = "100_block_2"

        BOUNCE_VX = 0.0
        BOTTOM_Y = 0.5
        BORDER_THICKNESS = 2.0
        BORDER_OFFSET = 0.1

        WALLS_COLOR = (0.3, 0.45, 1)

        state = factory.create(screen_width, screen_height, tile_size)

        tiles.add_tile_def(state, " ", ("assets/img/tiles/grid_double.png",))
        tiles.set_area(state, [[" " for x in xrange(10)] for x in xrange(10)])

        entities_helpers.create_screen_wall(state, "000_screenbox", BORDER_THICKNESS, BORDER_OFFSET, BOTTOM_Y, color=WALLS_COLOR)

        BLOCK_SIZE = 2.75
        BLOCK_OFFSET = -0.15
        BLOCK_Y = 1.0

        entities.insert(state,
                ENT_BOUNCE_BLOCK_1,
                {
                        "*": {
                                "textures": (("rectangle", BLOCK_SIZE, BLOCK_SIZE, WALLS_COLOR[0], WALLS_COLOR[1], WALLS_COLOR[2]),),
                        }
                },
                (-1.5 + BLOCK_OFFSET, BLOCK_Y, 45.0),
                collision=((("rectangle", 0, 0, BLOCK_SIZE, BLOCK_SIZE),)))

        entities.insert(state,
                ENT_BOUNCE_BLOCK_2,
                {
                        "*": {
                                "textures": (("rectangle", BLOCK_SIZE, BLOCK_SIZE, WALLS_COLOR[0], WALLS_COLOR[1], WALLS_COLOR[2]),),
                        }
                },
                (2.75 + BLOCK_OFFSET, BLOCK_Y, 45.0),
                collision=((("rectangle", 0, 0, BLOCK_SIZE, BLOCK_SIZE),)))

        index = 0
        n_rows = 6
        n_columns = 4
        BALL_DISTANCE = (1.0 / 4.0)

        for column in xrange(n_columns):
                for row in xrange(n_rows):
                        ball_entity_name = "900_ball_%d" % index

                        if index % 2 == 0:
                                BALL_SIZE = (1.0 / 4.0)
                                CIRCLE_RADIUS = BALL_SIZE / 2
                                filename = "assets/img/sprites/quarter_ball.png"
                                mass = 1.0
                        else:
                                # index += 1
                                # continue
                                BALL_SIZE = (1.0 / 8.0)
                                CIRCLE_RADIUS = BALL_SIZE / 2
                                filename = "assets/img/sprites/eigth_ball.png"
                                mass = 0.25

                        entities.insert(state,
                                ball_entity_name,
                                {
                                        "*": {
                                                "textures": (filename,),
                                        },
                                },
                                (
                                        1.0 + (row * BALL_DISTANCE * 1.25),
                                        4.5 + (column * 1.25 * BALL_DISTANCE * 1.25),
                                        0,
                                ),
                                collision=(("circle", CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS,),))

                        physical_mover.add(state,
                                ball_entity_name,
                                mass,
                                BOUNCE_VX,
                                0,
                                0,
                                YAPYG_STD_GRAVITY,
                                YAPYG_STD_FRICTION,
                                YAPYG_STD_INELASTICITY,
                                0,
                                YAPYG_STD_ROT_FRICTION,
                                YAPYG_STD_ROT_DECAY,
                                YAPYG_STD_STICKYNESS,
                                )

                        index += 1

        return state