Пример #1
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/grid_double.png", ))
    tiles.set_area(state, [["." for x in xrange(10)] for x in xrange(10)])

    text.load_font(state, "DroidSansMonoDotted32x64",
                   "assets/img/fonts/DroidSansMonoDotted32x64.png", 32, 64)
    text.load_font(state, "DroidSansMonoDotted16x32",
                   "assets/img/fonts/DroidSansMonoDotted16x32.png", 16, 32)
    text.load_font(state, "DroidSansMonoDotted12x24",
                   "assets/img/fonts/DroidSansMonoDotted12x24.png", 12, 24)
    text.load_font(state, "DroidSansMonoDotted10x16",
                   "assets/img/fonts/DroidSansMonoDotted10x16.png", 10, 16)
    text.load_font(state, "DroidSansMonoDotted8x12",
                   "assets/img/fonts/DroidSansMonoDotted8x12.png", 8, 12)

    entities.insert(
        state, "500_text_1", {
            "*": {
                "textures": (("text", "This is text\nSecond line",
                              "DroidSansMonoDotted16x32"), ),
            },
        }, (1, 2, 0))

    start_movement(state, None)

    entities.insert(
        state, "500_text_2", {
            "*": {
                "textures":
                (("text",
                  "Lorem ipsum dolor sit amet, consectetur adipisici elit,\n"
                  "sed eiusmod tempor incidunt ut labore et dolore magna aliqua.\n"
                  "Ut enim ad minim veniam, quis nostrud exercitation ullamco\n"
                  "laboris nisi ut aliquid ex ea commodi consequat. Quis aute\n"
                  "iure reprehenderit in voluptate velit esse cillum dolore eu\n"
                  "fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non\n"
                  "proident, sunt in culpa qui officia deserunt mollit anim id\n"
                  "est laborum.", "DroidSansMonoDotted8x12"), ),
            },
        }, (0, 4, 0))

    entities.insert(state, "500_text_3", {
        "*": {
            "textures": (("text", "Title", "DroidSansMonoDotted10x16"), ),
        },
    }, (0, 5, 0))

    entities.insert(state, "500_text_4", {
        "*": {
            "textures": (("text", "Chapter", "DroidSansMonoDotted12x24"), ),
        },
    }, (0, 5.5, 0))

    entities.insert(
        state, "500_text_time", {
            "*": {
                "textures":
                (("text", get_time_string(), "DroidSansMonoDotted32x64"), ),
            },
        }, (0.0, 0.5, 0))

    timer.create(state, on_timer, 1000)

    return state
Пример #2
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
Пример #3
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/grid_double.png",))
        tiles.set_area(state, [["." for x in xrange(10)] for x in xrange(10)])

        text.load_font(state, "DroidSansMonoDotted32x64", "assets/img/fonts/DroidSansMonoDotted32x64.png", 32, 64)
        text.load_font(state, "DroidSansMonoDotted16x32", "assets/img/fonts/DroidSansMonoDotted16x32.png", 16, 32)
        text.load_font(state, "DroidSansMonoDotted12x24", "assets/img/fonts/DroidSansMonoDotted12x24.png", 12, 24)
        text.load_font(state, "DroidSansMonoDotted10x16", "assets/img/fonts/DroidSansMonoDotted10x16.png", 10, 16)
        text.load_font(state, "DroidSansMonoDotted8x12", "assets/img/fonts/DroidSansMonoDotted8x12.png", 8, 12)

        entities.insert(state,
                "500_text_1",
                {
                        "*": {
                                "textures": (("text", "This is text\nSecond line", "DroidSansMonoDotted16x32"),),
                        },
                },
                (1, 2, 0))

        start_movement(state, None)

        entities.insert(state,
                "500_text_2",
                {
                        "*": {
                                "textures": (("text", 
                                                "Lorem ipsum dolor sit amet, consectetur adipisici elit,\n"
                                                "sed eiusmod tempor incidunt ut labore et dolore magna aliqua.\n"
                                                "Ut enim ad minim veniam, quis nostrud exercitation ullamco\n"
                                                "laboris nisi ut aliquid ex ea commodi consequat. Quis aute\n"
                                                "iure reprehenderit in voluptate velit esse cillum dolore eu\n"
                                                "fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non\n"
                                                "proident, sunt in culpa qui officia deserunt mollit anim id\n"
                                                "est laborum.",
                                        "DroidSansMonoDotted8x12"),),
                        },
                },
                (0, 4, 0))

        entities.insert(state,
                "500_text_3",
                {
                        "*": {
                                "textures": (("text", "Title", "DroidSansMonoDotted10x16"),),
                        },
                },
                (0, 5, 0))

        entities.insert(state,
                "500_text_4",
                {
                        "*": {
                                "textures": (("text", "Chapter", "DroidSansMonoDotted12x24"),),
                        },
                },
                (0, 5.5, 0))

        entities.insert(state,
                "500_text_time",
                {
                        "*": {
                                "textures": (("text", get_time_string(), "DroidSansMonoDotted32x64"),),
                        },
                },
                (0.0, 0.5, 0))

        timer.create(state, on_timer, 1000)

        return state