示例#1
0
def create(screen_width_px, screen_height_px, tile_size_px):
        # If there is an on-screen joystick
        # (there may not be one needed for non-mobile or other platforms)
        # set the drawing origin to above it (WORK IN PROGRESS, this needs a
        # cleaner solution).
        joystick_props = controls.get_joystick_properties()
        origin_xy = (0, joystick_props["h"] * screen_height_px)

        # Create the actual game state object that stores all information that yapyg needs.
        state = factory.create(screen_width_px, screen_height_px, tile_size_px, origin_xy)

        # Enable the joystick.
        controls.add_joystick(state)

        # Request buttons
        controls.add_buttons(state, (("Fire", on_fire_button, "right", "big"),))

        # Create some tiles to use for our game area. Individual tiles are referred to by strings.
        # Each tile can be composed by layering several images over each other
        if not DEBUG_MODE:
                floor_tile = "assets/img/tiles/dirtysquares.png"
        else:
                floor_tile = "assets/img/tiles/grid_double.png"

        tiles.add_tile_def(state, "x", (floor_tile,))
        if DEBUG_MODE:
                TILE_SIZE = 1.0
                tiles.add_tile_def(state, "#", ("assets/img/tiles/plain.png",), (("rectangle", 0, 0, TILE_SIZE, TILE_SIZE),))

        # Special wall tile import helper.
        if not DEBUG_MODE:
                tiles_helpers.load_walls(state, "", floor_tile, "assets/img/tiles/bricks_walls.png")
        else:
                tiles_helpers.load_walls(state, "", floor_tile, "assets/img/tiles/grid_quad_walls.png")

        # The tile map is made as a list of lists.
        tiles.set_area(state,
                [ ['<', '-', '-', '>', '<', '-', '-', '-', '-', '>'],
                  ['(', '.', ',', ')', '(', '.', '_', '_', ',', ')'],
                  ['(', ')', '(', ')', '(', ')', '<', '>', '(', ')'],
                  ['[', ']', '(', ')', '(', ')', '(', ')', '[', ']'],
                  ['<', '-', ';', ')', '(', ')', '(', ':', '-', '>'],
                  ['(', 'x', 'x', ')', '(', ')', '(', '.', '_', ']'],
                  ['(', 'x', 'x', ':', ';', ')', '(', ':', '-', '>'],
                  ['(', '.', '_', '_', ',', ')', '(', 'x', 'x', ')'],
                  ['(', ':', '-', '-', ';', ':', ';', 'x', 'x', ')'],
                  ['[', '_', '_', '_', '_', '_', '_', '_', '_', ']']]
                  )

        collisions.set_handler(state, collision_handler)

        # Font is 16x32 px size
        text.load_font(state, FONT_NAME, "assets/img/fonts/%s.png" % FONT_NAME, 16, 32)

        user.set_data(state, USERDATA_SCORE, 0)
        text.create_text_entity(state, ENT_TEXT_SCORE, get_score_text(state), FONT_NAME, (0, 0, 0), screen_relative=True)

        user.set_data(state, USERDATA_HEALTH, 100)
        text.create_text_entity(state, ENT_TEXT_HEALTH, get_health_text(state), FONT_NAME,
                (screen_width_px / tile_size_px / 2.0, 0, 0), screen_relative=True)

        # We create the ENT_MAN entity which has 2 different sprite representations: standing and walking.
        # The idle sprite is the default sprite, since it starts with an asterisk (*).

        # The animation of the sprites is defined by a list of images that will be played in order,
        # then repeated, where the playback speed is defined individually for the sprite as well.

        # We define the starting coordinates (in "map coordinates", which are relative to tile size, not pixels!), here [1,1],
        # the rotation amount of the entity (0 here) and an offset for drawing the sprite to the actual position,
        # here [0.25, 0.25].
        MAN_SIZE = 1.0 / 2.0 # 64 px = 128 px tile / 2
        MAN_RADIUS = MAN_SIZE / 2.0
        MAN_OFFSET = -MAN_RADIUS # entity position defines the center of the sprite (sprite drawn left+lower of position)
        if not DEBUG_MODE:
                man_idle_textures = (
                                     "assets/img/sprites/man_idle/0.png",
                                     "assets/img/sprites/man_idle/1.png",
                                     "assets/img/sprites/man_idle/2.png",
                                     "assets/img/sprites/man_idle/3.png",
                                     "assets/img/sprites/man_idle/1.png",
                                     "assets/img/sprites/man_idle/0.png",
                                     "assets/img/sprites/man_idle/3.png",
                                     "assets/img/sprites/man_idle/2.png",
                                     )
                man_walk_textures = (
                                     "assets/img/sprites/man_walk/1.png",
                                     "assets/img/sprites/man_walk/2.png",
                                     "assets/img/sprites/man_walk/3.png",
                                     )
        else:
                man_idle_textures = (
                                     "assets/img/sprites/half_ball.png",
                                     )
                man_walk_textures = (
                                     "assets/img/sprites/half_ball.png",
                                     )

        entities.insert(state,
                        ENT_MAN,
                        {
                         "*idle": {
                                   "textures": man_idle_textures,
                                   "speed": 333.0,
                                   },
                         "walk": {
                                  "textures": man_walk_textures,
                                  "speed" : 150.0,
                                  },
                         },
                        (1.0, 1.0, 0),
                        (MAN_OFFSET, MAN_OFFSET),
                        collision=(("circle", MAN_RADIUS, MAN_RADIUS, MAN_RADIUS,),),
                        )

        # A pile of coins
        COINS_SIZE = 1.0 / 2.0 # 64 px = 128 px tile / 2
        COINS_RADIUS = COINS_SIZE / 2.0
        COINS_OFFSET = -COINS_RADIUS
        if not DEBUG_MODE:
                coin_textures = ("assets/img/sprites/coins/0.png",
                                 "assets/img/sprites/coins/1.png",
                                 "assets/img/sprites/coins/2.png",
                                 "assets/img/sprites/coins/1.png",
                                 )
        else:
                coin_textures = ("assets/img/sprites/half_ball_2.png",)
        entities.insert(state,
                        "%s_1" % (ENT_PREFIX_COINS),
                        {
                         "*": {
                               "textures": coin_textures,
                               "speed": 150.0,
                               },
                         },
                        (1.0, 7.0, 0),
                        (COINS_OFFSET, COINS_OFFSET),
                        collision=(("circle", COINS_RADIUS, COINS_RADIUS, COINS_RADIUS,),),
                        )

        GHOST_SIZE = 1.0
        GHOST_RADIUS = GHOST_SIZE / 2.0
        GHOST_OFFSET = -(GHOST_RADIUS)
        if not DEBUG_MODE:
                ghost_textures = (
                                  "assets/img/sprites/ghost/1.png",
                                  "assets/img/sprites/ghost/2.png",
                                  "assets/img/sprites/ghost/3.png",
                                  "assets/img/sprites/ghost/2.png",
                                )
        else:
                ghost_textures = ("assets/img/sprites/full_ball.png",)

        entities.insert(state,
                        ENT_GHOST,
                        {
                         "*": {
                                   "textures": ghost_textures,
                                   "speed": 200.0,
                                   },
                         },
                        (1.0, 3.0, 0),
                        (GHOST_OFFSET, GHOST_OFFSET), # sprite appears lower and more left of actual entity position
                        collision=(("circle", GHOST_RADIUS, GHOST_RADIUS, GHOST_RADIUS,),),
                        )

        # We add a mover that will translate joystick movement to moving the man around the area.
        # This particular mover needs the source of control, a factor for the strength of the movement,
        # the allowed range for the movement, what sprites to use for idle and moving state and if to
        # rotate the entity to the movement direction.
        controlled_mover.add(state,
                             ENT_MAN,
                             "joystick",
                             0.03,
                             (0, 0, 10.0, 10.0),
                             ("*idle", "walk"),
                             True
                             )

        view.set_viewer(state, relative_viewer.create(state, ENT_MAN))

        start_ghost_movement(state, None)

        # The state object is finished.
        return state
示例#2
0
文件: demo_car.py 项目: rkibria/yapyg
def create(screen_width_px, screen_height_px, tile_size_px):
        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)

        user.set_data(state, "n_barrels", 0)
        user.set_data(state, "n_barriers", 0)

        controls.add_joystick(state)
        controls.add_buttons(state, (("Fire", on_fire_button, "right", "big"),))

        floor_tile = "assets/img/tiles/dirt_ground.png"
        tiles.add_tile_def(state, ' ', (floor_tile,))
        tiles_helpers.load_walls(state, "", floor_tile, "assets/img/tiles/bricks_walls.png")
        tiles_helpers.load_walls(state, "/", "assets/img/tiles/grass.png", "assets/img/tiles/bricks_walls.png")
        tiles.add_tile_def(state, '|', (floor_tile, "assets/img/tiles/road-I.png",))
        tiles.add_tile_def(state, '~', (floor_tile, "assets/img/tiles/road-h.png",))
        tiles.add_tile_def(state, 'L', (floor_tile, "assets/img/tiles/road-cnr-bl.png",))
        tiles.add_tile_def(state, 'T', (floor_tile, "assets/img/tiles/road-cnr-tl.png",))
        tiles.add_tile_def(state, 'J', (floor_tile, "assets/img/tiles/road-cnr-br.png",))
        tiles.add_tile_def(state, 'j', (floor_tile, "assets/img/tiles/road-cnr-ur.png",))
        tiles.add_tile_def(state, '/', ("assets/img/tiles/grass.png",))
        tiles.add_tile_def(state, 't', ("assets/img/tiles/grass.png", "assets/img/tiles/tree.png"))
        tiles.set_area(state,
                 [
                  ['t', '/' , 't' , '/' , 't' , '/' , 't' , '/' , 't' , '/' , 't' , '/' , 't' , '/' , 't' , '/' , 't' , '/' , 't' , '/'],
                  ['/', '/.', '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/,', '/'],
                  ['t', '/)', '<' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '>' , '/(', 't'],
                  ['/', '/)', '(' , 'T' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , 'j' , ')' , '/(', '/'],
                  ['t', '/)', '(' , '|' , '.' , '_' , '_' , '_' , '_' , '_' , '_' , '_' , '_' , '_' , '_' , ',' , '|' , ')' , '/(', 't'],
                  ['/', '/)', '(' , '|' , ')' , '/<', '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/>', '(' , '|' , ')' , '/(', '/'],
                  ['t', '/)', '(' , '|' , ')' , '/(', '/' , 't' , '/' , 't' , '/' , 't' , '/' , 't' , '/)', '(' , '|' , ')' , '/(', 't'],
                  ['/', '/)', '(' , '|' , ')' , '/(', 't' , '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/)', '(' , '|' , ')' , '/(', '/'],
                  ['t', '/)', '(' , '|' , ')' , '/(', '/' , '/' , '/' , '/' , '/' , '/' , '/' , 't' , '/)', '(' , '|' , ')' , '/(', 't'],
                  ['/', '/)', '(' , '|' , ')' , '/(', 't' , '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/)', '(' , '|' , ')' , '/(', '/'],
                  ['t', '/)', '(' , '|' , ')' , '/(', '/' , '/' , '/' , '/' , '/' , '/' , '/' , 't' , '/)', '(' , '|' , ')' , '/(', 't'],
                  ['/', '/)', '(' , '|' , ')' , '/(', 't' , '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/)', '(' , '|' , ')' , '/(', '/'],
                  ['t', '/)', '(' , '|' , ')' , '/(', '/' , '/' , '/' , '/' , '/' , '/' , '/' , 't' , '/)', '(' , '|' , ')' , '/(', 't'],
                  ['/', '/)', '(' , '|' , ')' , '/(', 't' , '/' , 't' , '/' , 't' , '/' , 't' , '/' , '/)', '(' , '|' , ')' , '/(', '/'],
                  ['t', '/)', '(' , '|' , ')' , '/[', '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/]', '(' , '|' , ')' , '/(', 't'],
                  ['/', '/)', '(' , '|' , ':' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , '-' , ';' , '|' , ')' , '/(', '/'],
                  ['t', '/)', '(' , 'L' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , '~' , 'J' , ')' , '/(', 't'],
                  ['/', '/)', '[' , '_' , '_' , '_' , '_' , '_' , '_' , '_' , '_' , '_' , '_' , '_' , '_' , '_' , '_' , ']' , '/(', '/'],
                  ['t', '/:', '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/;', '/'],
                  ['/', 't' , '/' , 't' , '/' , 't' , '/' , 't' , '/' , 't' , '/' , 't' , '/' , 't' , '/' , 't' , '/' , 't' , '/' , 't'],
                  ['/', '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/' , '/'],
                 ]
                 )
        play_area_origin = (2.0, 3.0)

        # text.load_font(state, FONT_NAME, "assets/img/fonts/%s.png" % FONT_NAME, 16, 32)

        entities.insert(state,
                        ENT_PLAYER_CAR,
                        {
                         "*": {
                                   "textures": (
                                                "assets/img/sprites/car/0.png",
                                                ),
                                   "speed": 0.0,
                                   },
                         "+": {
                                   "textures": (
                                                "assets/img/sprites/car/1.png",
                                                ),
                                   "speed": 0.0,
                                   },
                         "-": {
                                   "textures": (
                                                "assets/img/sprites/car/2.png",
                                                ),
                                   "speed": 0.0,
                                   },
                         },
                        (play_area_origin[0] + 1.5, play_area_origin[1] + 6.0, 0),
                        (-0.125, -0.25),
                        collision=(("rectangle", 0.0, 0.0, 0.25, 0.5),),
                        )

        view.set_viewer(state, relative_viewer.create(state, ENT_PLAYER_CAR))

        control_phys_mover.add(state,
                           ENT_PLAYER_CAR,
                           1.0,
                           0,
                           0,
                           0,
                           0,
                           0.9, # IDX_MOVERS_PHYSICAL_FRICTION
                           0.001, # YAPYG_STD_INELASTICITY,
                           0,
                           YAPYG_STD_ROT_FRICTION,
                           YAPYG_STD_ROT_DECAY,
                           YAPYG_STD_STICKYNESS,
                           dir_factor=0.005,
                           pos_accel=12.0,
                           neg_accel=4.0,
                           rest_sprite="*",
                           pos_sprite="+",
                           neg_sprite="-"
                           )

        for i in xrange(7):
                add_barrel(state, play_area_origin[0] + 0.5, play_area_origin[1] + 2.0 + 2.0 * i)

        for i in xrange(7):
                add_barrel(state, play_area_origin[0] + 15.25, play_area_origin[1] + 2.0 + 2.0 * i)

        for i in xrange(8):
                add_barrier(state, play_area_origin[0] + 0.5 - 0.125, play_area_origin[1] + 1.0 + 2.0 * i, 90.0)

        for i in xrange(8):
                add_barrier(state, play_area_origin[0] + 1.0 + 0.125 + 2.0 * i, play_area_origin[1] + 0.5, 0.0)

        for i in xrange(7):
                add_barrier(state, play_area_origin[0] + 1.0 + 0.125 + 2.0 * i, play_area_origin[1] + 15.25, 0.0)

        for i in xrange(7):
                add_barrel(state, play_area_origin[0] + 2.0 + 0.125 + 2.0 * i, play_area_origin[1] + 15.25)

        for i in xrange(6):
                add_barrel(state, play_area_origin[0] + 2.0 + 0.25 + 2.0 * i, play_area_origin[1] + 13.5)

        for i in xrange(6):
                add_barrier(state, play_area_origin[0] + 3.0 + 0.25 + 2.0 * i, play_area_origin[1] + 13.5, 0.0)

        for i in xrange(7):
                add_barrel(state, play_area_origin[0] + 2.0 + 0.125 + 2.0 * i, play_area_origin[1] + 0.5)

        for i in xrange(8):
                add_barrier(state, play_area_origin[0] + 15.25 - 0.125, play_area_origin[1] + 1.0 + 2.0 * i, 90.0)

        for i in xrange(1, 6):
                add_barrel(state, play_area_origin[0] + 2.25, play_area_origin[1] + 2.0 + 2.0 * i)
                add_barrel(state, play_area_origin[0] + 13.5, play_area_origin[1] + 2.0 + 2.0 * i)

        for i in xrange(6):
                add_barrier(state, play_area_origin[0] + 2.25 - 0.125, play_area_origin[1] + 3.0 + 2.0 * i, 90.0)
                add_barrier(state, play_area_origin[0] + 13.5 - 0.125, play_area_origin[1] + 3.0 + 2.0 * i, 90.0)

        for i in xrange(6):
                add_barrel(state, play_area_origin[0] + 2.25 + 2.0 * i, play_area_origin[1] + 2.25)
                add_barrier(state, play_area_origin[0] + 3.25 - 0.125 + 2.0 * i, play_area_origin[1] + 2.25, 0.0)

        timer.create(state, on_timer, 100)

        return state
示例#3
0
文件: demo_tiles.py 项目: hanez/yapyg
def create(screen_width, screen_height, tile_size):
    state = factory.create(screen_width, screen_height, tile_size)

    tiles.add_tile_def(state, " ", ("assets/img/tiles/grass.png", ))
    tiles.add_tile_def(
        state, "+",
        ("assets/img/tiles/grass.png", "assets/img/tiles/brown_ground.png"))
    tiles.add_tile_def(
        state, "t",
        ("assets/img/tiles/grass.png", "assets/img/tiles/tree.png"))

    tiles_helpers.load_walls(state, "", "assets/img/tiles/grass.png",
                             "assets/img/tiles/bricks_walls.png")

    area_strings = (
        "      +           ",
        "      +           ",
        "      +           ",
        "      +           ",
        "      +           ",
        "      +           ",
        "      +           ",
        "      +           ",
        "      +.____,     ",
        "      +)<-->(     ",
        "      +)(tt)(     ",
        "      +)(tt)(     ",
        "      +)[__](     ",
        "      +:----;     ",
        "      +           ",
        "      +           ",
        "      +           ",
        "      +           ",
        "      +           ",
    )
    area = tiles_helpers.strings_to_chars(area_strings)
    tiles.set_area(state, area)

    entities.insert(
        state, "man", {
            "idle": {
                "textures": (
                    "assets/img/sprites/man_idle/0.png",
                    "assets/img/sprites/man_idle/1.png",
                    "assets/img/sprites/man_idle/2.png",
                    "assets/img/sprites/man_idle/3.png",
                    "assets/img/sprites/man_idle/1.png",
                    "assets/img/sprites/man_idle/0.png",
                    "assets/img/sprites/man_idle/3.png",
                    "assets/img/sprites/man_idle/2.png",
                ),
                "speed":
                333.0,
            },
            "walk": {
                "textures": (
                    "assets/img/sprites/man_walk/1.png",
                    "assets/img/sprites/man_walk/2.png",
                    "assets/img/sprites/man_walk/3.png",
                ),
                "speed":
                150.0,
            },
        }, (7.0, 5.0, 0), (0.25, 0.25))

    start_movement(state, None)

    view.set_viewer(state, relative_viewer.create(state, "man", [-1.5, -2.5]))

    return state
示例#4
0
def create(screen_width_px, screen_height_px, tile_size_px):
    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)

    user.set_data(state, "n_barrels", 0)
    user.set_data(state, "n_barriers", 0)

    controls.add_joystick(state)
    controls.add_buttons(state, (("Fire", on_fire_button, "right", "big"), ))

    floor_tile = "assets/img/tiles/dirt_ground.png"
    tiles.add_tile_def(state, ' ', (floor_tile, ))
    tiles_helpers.load_walls(state, "", floor_tile,
                             "assets/img/tiles/bricks_walls.png")
    tiles_helpers.load_walls(state, "/", "assets/img/tiles/grass.png",
                             "assets/img/tiles/bricks_walls.png")
    tiles.add_tile_def(state, '|', (
        floor_tile,
        "assets/img/tiles/road-I.png",
    ))
    tiles.add_tile_def(state, '~', (
        floor_tile,
        "assets/img/tiles/road-h.png",
    ))
    tiles.add_tile_def(state, 'L', (
        floor_tile,
        "assets/img/tiles/road-cnr-bl.png",
    ))
    tiles.add_tile_def(state, 'T', (
        floor_tile,
        "assets/img/tiles/road-cnr-tl.png",
    ))
    tiles.add_tile_def(state, 'J', (
        floor_tile,
        "assets/img/tiles/road-cnr-br.png",
    ))
    tiles.add_tile_def(state, 'j', (
        floor_tile,
        "assets/img/tiles/road-cnr-ur.png",
    ))
    tiles.add_tile_def(state, '/', ("assets/img/tiles/grass.png", ))
    tiles.add_tile_def(
        state, 't',
        ("assets/img/tiles/grass.png", "assets/img/tiles/tree.png"))
    tiles.set_area(state, [
        [
            't', '/', 't', '/', 't', '/', 't', '/', 't', '/', 't', '/', 't',
            '/', 't', '/', 't', '/', 't', '/'
        ],
        [
            '/', '/.', '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/_',
            '/_', '/_', '/_', '/_', '/_', '/_', '/_', '/,', '/'
        ],
        [
            't', '/)', '<', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
            '-', '-', '-', '-', '>', '/(', 't'
        ],
        [
            '/', '/)', '(', 'T', '~', '~', '~', '~', '~', '~', '~', '~', '~',
            '~', '~', '~', 'j', ')', '/(', '/'
        ],
        [
            't', '/)', '(', '|', '.', '_', '_', '_', '_', '_', '_', '_', '_',
            '_', '_', ',', '|', ')', '/(', 't'
        ],
        [
            '/', '/)', '(', '|', ')', '/<', '/-', '/-', '/-', '/-', '/-', '/-',
            '/-', '/-', '/>', '(', '|', ')', '/(', '/'
        ],
        [
            't', '/)', '(', '|', ')', '/(', '/', 't', '/', 't', '/', 't', '/',
            't', '/)', '(', '|', ')', '/(', 't'
        ],
        [
            '/', '/)', '(', '|', ')', '/(', 't', '/', '/', '/', '/', '/', '/',
            '/', '/)', '(', '|', ')', '/(', '/'
        ],
        [
            't', '/)', '(', '|', ')', '/(', '/', '/', '/', '/', '/', '/', '/',
            't', '/)', '(', '|', ')', '/(', 't'
        ],
        [
            '/', '/)', '(', '|', ')', '/(', 't', '/', '/', '/', '/', '/', '/',
            '/', '/)', '(', '|', ')', '/(', '/'
        ],
        [
            't', '/)', '(', '|', ')', '/(', '/', '/', '/', '/', '/', '/', '/',
            't', '/)', '(', '|', ')', '/(', 't'
        ],
        [
            '/', '/)', '(', '|', ')', '/(', 't', '/', '/', '/', '/', '/', '/',
            '/', '/)', '(', '|', ')', '/(', '/'
        ],
        [
            't', '/)', '(', '|', ')', '/(', '/', '/', '/', '/', '/', '/', '/',
            't', '/)', '(', '|', ')', '/(', 't'
        ],
        [
            '/', '/)', '(', '|', ')', '/(', 't', '/', 't', '/', 't', '/', 't',
            '/', '/)', '(', '|', ')', '/(', '/'
        ],
        [
            't', '/)', '(', '|', ')', '/[', '/_', '/_', '/_', '/_', '/_', '/_',
            '/_', '/_', '/]', '(', '|', ')', '/(', 't'
        ],
        [
            '/', '/)', '(', '|', ':', '-', '-', '-', '-', '-', '-', '-', '-',
            '-', '-', ';', '|', ')', '/(', '/'
        ],
        [
            't', '/)', '(', 'L', '~', '~', '~', '~', '~', '~', '~', '~', '~',
            '~', '~', '~', 'J', ')', '/(', 't'
        ],
        [
            '/', '/)', '[', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_',
            '_', '_', '_', '_', ']', '/(', '/'
        ],
        [
            't', '/:', '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/-',
            '/-', '/-', '/-', '/-', '/-', '/-', '/-', '/;', '/'
        ],
        [
            '/', 't', '/', 't', '/', 't', '/', 't', '/', 't', '/', 't', '/',
            't', '/', 't', '/', 't', '/', 't'
        ],
        [
            '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/', '/',
            '/', '/', '/', '/', '/', '/', '/'
        ],
    ])
    play_area_origin = (2.0, 3.0)

    # text.load_font(state, FONT_NAME, "assets/img/fonts/%s.png" % FONT_NAME, 16, 32)

    entities.insert(
        state,
        ENT_PLAYER_CAR,
        {
            "*": {
                "textures": ("assets/img/sprites/car/0.png", ),
                "speed": 0.0,
            },
            "+": {
                "textures": ("assets/img/sprites/car/1.png", ),
                "speed": 0.0,
            },
            "-": {
                "textures": ("assets/img/sprites/car/2.png", ),
                "speed": 0.0,
            },
        },
        (play_area_origin[0] + 1.5, play_area_origin[1] + 6.0, 0),
        (-0.125, -0.25),
        collision=(("rectangle", 0.0, 0.0, 0.25, 0.5), ),
    )

    view.set_viewer(state, relative_viewer.create(state, ENT_PLAYER_CAR))

    control_phys_mover.add(
        state,
        ENT_PLAYER_CAR,
        1.0,
        0,
        0,
        0,
        0,
        0.9,  # IDX_MOVERS_PHYSICAL_FRICTION
        0.001,  # YAPYG_STD_INELASTICITY,
        0,
        YAPYG_STD_ROT_FRICTION,
        YAPYG_STD_ROT_DECAY,
        YAPYG_STD_STICKYNESS,
        dir_factor=0.005,
        pos_accel=12.0,
        neg_accel=4.0,
        rest_sprite="*",
        pos_sprite="+",
        neg_sprite="-")

    for i in xrange(7):
        add_barrel(state, play_area_origin[0] + 0.5,
                   play_area_origin[1] + 2.0 + 2.0 * i)

    for i in xrange(7):
        add_barrel(state, play_area_origin[0] + 15.25,
                   play_area_origin[1] + 2.0 + 2.0 * i)

    for i in xrange(8):
        add_barrier(state, play_area_origin[0] + 0.5 - 0.125,
                    play_area_origin[1] + 1.0 + 2.0 * i, 90.0)

    for i in xrange(8):
        add_barrier(state, play_area_origin[0] + 1.0 + 0.125 + 2.0 * i,
                    play_area_origin[1] + 0.5, 0.0)

    for i in xrange(7):
        add_barrier(state, play_area_origin[0] + 1.0 + 0.125 + 2.0 * i,
                    play_area_origin[1] + 15.25, 0.0)

    for i in xrange(7):
        add_barrel(state, play_area_origin[0] + 2.0 + 0.125 + 2.0 * i,
                   play_area_origin[1] + 15.25)

    for i in xrange(6):
        add_barrel(state, play_area_origin[0] + 2.0 + 0.25 + 2.0 * i,
                   play_area_origin[1] + 13.5)

    for i in xrange(6):
        add_barrier(state, play_area_origin[0] + 3.0 + 0.25 + 2.0 * i,
                    play_area_origin[1] + 13.5, 0.0)

    for i in xrange(7):
        add_barrel(state, play_area_origin[0] + 2.0 + 0.125 + 2.0 * i,
                   play_area_origin[1] + 0.5)

    for i in xrange(8):
        add_barrier(state, play_area_origin[0] + 15.25 - 0.125,
                    play_area_origin[1] + 1.0 + 2.0 * i, 90.0)

    for i in xrange(1, 6):
        add_barrel(state, play_area_origin[0] + 2.25,
                   play_area_origin[1] + 2.0 + 2.0 * i)
        add_barrel(state, play_area_origin[0] + 13.5,
                   play_area_origin[1] + 2.0 + 2.0 * i)

    for i in xrange(6):
        add_barrier(state, play_area_origin[0] + 2.25 - 0.125,
                    play_area_origin[1] + 3.0 + 2.0 * i, 90.0)
        add_barrier(state, play_area_origin[0] + 13.5 - 0.125,
                    play_area_origin[1] + 3.0 + 2.0 * i, 90.0)

    for i in xrange(6):
        add_barrel(state, play_area_origin[0] + 2.25 + 2.0 * i,
                   play_area_origin[1] + 2.25)
        add_barrier(state, play_area_origin[0] + 3.25 - 0.125 + 2.0 * i,
                    play_area_origin[1] + 2.25, 0.0)

    timer.create(state, on_timer, 100)

    return state
示例#5
0
def create(screen_width, screen_height, tile_size):
        state = factory.create(screen_width, screen_height, tile_size)

        tiles.add_tile_def(state, " ", ("assets/img/tiles/grass.png",))
        tiles.add_tile_def(state, "+", ("assets/img/tiles/grass.png", "assets/img/tiles/brown_ground.png"))
        tiles.add_tile_def(state, "t", ("assets/img/tiles/grass.png", "assets/img/tiles/tree.png"))

        tiles_helpers.load_walls(state, "", "assets/img/tiles/grass.png", "assets/img/tiles/bricks_walls.png")

        area_strings = (
                "      +           ",
                "      +           ",
                "      +           ",
                "      +           ",
                "      +           ",
                "      +           ",
                "      +           ",
                "      +           ",
                "      +.____,     ",
                "      +)<-->(     ",
                "      +)(tt)(     ",
                "      +)(tt)(     ",
                "      +)[__](     ",
                "      +:----;     ",
                "      +           ",
                "      +           ",
                "      +           ",
                "      +           ",
                "      +           ",
                )
        area = tiles_helpers.strings_to_chars(area_strings)
        tiles.set_area(state, area)

        entities.insert(state, "man",
                {
                        "idle": {
                                "textures": (
                                        "assets/img/sprites/man_idle/0.png",
                                        "assets/img/sprites/man_idle/1.png",
                                        "assets/img/sprites/man_idle/2.png",
                                        "assets/img/sprites/man_idle/3.png",
                                        "assets/img/sprites/man_idle/1.png",
                                        "assets/img/sprites/man_idle/0.png",
                                        "assets/img/sprites/man_idle/3.png",
                                        "assets/img/sprites/man_idle/2.png",
                                        ),
                                "speed": 333.0,
                        },
                        "walk": {
                                "textures": (
                                        "assets/img/sprites/man_walk/1.png",
                                        "assets/img/sprites/man_walk/2.png",
                                        "assets/img/sprites/man_walk/3.png",
                                        ),
                                "speed" : 150.0,
                        },
                }, (7.0, 5.0, 0), (0.25, 0.25))

        start_movement(state, None)

        view.set_viewer(state, relative_viewer.create(state, "man", [-1.5, -2.5]))

        return state