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)]) # controls.add_joystick(state) for x in xrange(100): for y in xrange(100): ball_entity_name = "ball_%d_%d" % (x, y) entities.insert( state, ball_entity_name, { "*": { "textures": ( "assets/img/sprites/half_ball.png", "assets/img/sprites/half_ball_2.png", ), "speed": 100.0, }, }, ( x * 0.5 - 0.25, y * 0.5 - 0.25, 0, ), ) return state
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)
def add_barrier(state, x, y, r): barrier_count = user.get_data(state, "n_barriers") barrier_entity_name = "barrier_%d" % barrier_count user.set_data(state, "n_barriers", barrier_count + 1) entities.insert(state, barrier_entity_name, { "*": { "textures": ("assets/img/sprites/barrier.png",), }, }, ( x, y, r, ), collision=(("rectangle", 0.0, 0.0, 0.5, 0.125),)) physical_mover.add(state, barrier_entity_name, 0.5, 0, 0, 0, 0, 0.92, YAPYG_STD_INELASTICITY, 0, YAPYG_STD_ROT_FRICTION, YAPYG_STD_ROT_DECAY, YAPYG_STD_STICKYNESS, )
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)
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)]) # controls.add_joystick(state) for x in xrange(100): for y in xrange(100): ball_entity_name = "ball_%d_%d" % (x, y) entities.insert(state, ball_entity_name, { "*": { "textures": ("assets/img/sprites/half_ball.png", "assets/img/sprites/half_ball_2.png", ), "speed" : 100.0, }, }, ( x * 0.5 - 0.25, y * 0.5 - 0.25, 0, ), ) return state
def add_barrier(state, x, y, r): barrier_count = user.get_data(state, "n_barriers") barrier_entity_name = "barrier_%d" % barrier_count user.set_data(state, "n_barriers", barrier_count + 1) entities.insert(state, barrier_entity_name, { "*": { "textures": ("assets/img/sprites/barrier.png", ), }, }, ( x, y, r, ), collision=(("rectangle", 0.0, 0.0, 0.5, 0.125), )) physical_mover.add( state, barrier_entity_name, 0.5, 0, 0, 0, 0, 0.92, YAPYG_STD_INELASTICITY, 0, YAPYG_STD_ROT_FRICTION, YAPYG_STD_ROT_DECAY, YAPYG_STD_STICKYNESS, )
def add_barrel(state, x, y): barrel_count = user.get_data(state, "n_barrels") barrel_entity_name = "barrel_%d" % barrel_count user.set_data(state, "n_barrels", barrel_count + 1) entities.insert(state, barrel_entity_name, { "*": { "textures": ("assets/img/sprites/barrel.png",), }, }, ( x, y, 0, ), collision=(("circle", (1.0 / 4.0) / 2.0, (1.0 / 4.0) / 2.0, (1.0 / 4.0) / 2.0,),)) physical_mover.add(state, barrel_entity_name, 0.01, 0, 0, 0, 0, 0.92, YAPYG_STD_INELASTICITY, 0, YAPYG_STD_ROT_FRICTION, YAPYG_STD_ROT_DECAY, YAPYG_STD_STICKYNESS, )
def do_shot_boom(state, pos): entities.insert(state, "shot_boom", SHOT_BOOM_SPRITEDEF, pos, SHOT_BOOM_SPRITEOFFSET, play_once=True, )
def do_ghost_boom(state, pos): entities.insert(state, "ghost_boom", GHOST_BOOM_SPRITEDEF, pos, GHOST_BOOM_SPRITEOFFSET, play_once=True, )
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 )
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) controls.add_joystick(state) controls.add_buttons(state, (("Fire", None, "right", "big"),)) n_x = (screen_width_px / 256) + 1 n_y = (screen_height_px / 256) + 2 for x in xrange(n_x): for y in xrange(n_y): entity_name = star_name(x, y) textures_tuple = ("assets/img/sprites/stars.png",) if DEBUG_MODE: color = (float(x) / n_x, float(y) / n_y, 0) textures_tuple = (("rectangle", 2, 2, color[0], color[1], color[2]),) entities.insert(state, entity_name, { "*": { "textures": textures_tuple, "speed": 0, }, }, ((x * 2), (y * 2), 0) ) entities.insert(state, ENT_SHIP, { "*idle": { "textures": ( "assets/img/sprites/ship_idle/0.png", "assets/img/sprites/ship_idle/1.png", ), "speed": 100, }, "thrust": { "textures": ( "assets/img/sprites/ship_thrust/0.png", "assets/img/sprites/ship_thrust/1.png", ), "speed" : 50, }, }, (1, 1, 0) ) start_stars_movement(state, None) controlled_mover.add(state, ENT_SHIP, "joystick", 0.03, (0, 0, 3.25, 1.0), ("*idle", "thrust"), False ) return state
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) controls.add_joystick(state) controls.add_buttons(state, (("Fire", None, "right", "big"), )) n_x = (screen_width_px / 256) + 1 n_y = (screen_height_px / 256) + 2 for x in xrange(n_x): for y in xrange(n_y): entity_name = star_name(x, y) textures_tuple = ("assets/img/sprites/stars.png", ) if DEBUG_MODE: color = (float(x) / n_x, float(y) / n_y, 0) textures_tuple = (("rectangle", 2, 2, color[0], color[1], color[2]), ) entities.insert(state, entity_name, { "*": { "textures": textures_tuple, "speed": 0, }, }, ((x * 2), (y * 2), 0)) entities.insert( state, ENT_SHIP, { "*idle": { "textures": ( "assets/img/sprites/ship_idle/0.png", "assets/img/sprites/ship_idle/1.png", ), "speed": 100, }, "thrust": { "textures": ( "assets/img/sprites/ship_thrust/0.png", "assets/img/sprites/ship_thrust/1.png", ), "speed": 50, }, }, (1, 1, 0)) start_stars_movement(state, None) controlled_mover.add(state, ENT_SHIP, "joystick", 0.03, (0, 0, 3.25, 1.0), ("*idle", "thrust"), False) return state
def build(self): state = factory.create(SCREEN_LOGICAL_WIDTH, SCREEN_LOGICAL_HEIGHT, TILE_SIZE) tiles.add_tile_def(state, '+', ("../demo/assets/img/tiles/grid_simple.png",)) tiles.set_area(state, [["+"] * 9] * 9) entities.insert(state, "ball", { "*": { "textures": ("../demo/assets/img/sprites/full_ball.png",), }, }, (0, 0, 0,), pos_offset=(0.5, 0.5), ) return ScreenWidget(state, debugging=True)
def do_exhaust(state, pos): entities.insert(state, ENT_PLAYER_CAR_EXHAUST, { "*": { "textures": ("assets/img/sprites/exhaust/0.png", "assets/img/sprites/exhaust/1.png", "assets/img/sprites/exhaust/2.png", "assets/img/sprites/exhaust/1.png", ), "speed": 50.0, }, }, pos, (-0.125, -0.125), play_once=True, )
def do_exhaust(state, pos): entities.insert( state, ENT_PLAYER_CAR_EXHAUST, { "*": { "textures": ( "assets/img/sprites/exhaust/0.png", "assets/img/sprites/exhaust/1.png", "assets/img/sprites/exhaust/2.png", "assets/img/sprites/exhaust/1.png", ), "speed": 50.0, }, }, pos, (-0.125, -0.125), play_once=True, )
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)
def build(self): state = factory.create(SCREEN_LOGICAL_WIDTH, SCREEN_LOGICAL_HEIGHT, TILE_SIZE) tiles.add_tile_def(state, '+', ("../demo/assets/img/tiles/grid_simple.png", )) tiles.set_area(state, [["+"] * 9] * 9) entities.insert( state, "ball", { "*": { "textures": ("../demo/assets/img/sprites/full_ball.png", ), }, }, ( 0, 0, 0, ), pos_offset=(0.5, 0.5), ) return ScreenWidget(state, debugging=True)
def create_collision_box( state, base_name, pos, size, thickness, top=True, bottom=True, left=True, right=True, color=(1, 1, 1) ): """ TODO """ ENT_TOPWALL = base_name + "_top" ENT_LEFTWALL = base_name + "_left" ENT_RIGHTWALL = base_name + "_right" ENT_BOTTOMWALL = base_name + "_bottom" horizontal_wall_width = size[0] vertical_wall_height = size[1] if bottom: entities.insert( state, ENT_BOTTOMWALL, {"*": {"textures": (("rectangle", horizontal_wall_width, thickness, color[0], color[1], color[2]),)}}, (pos[0], pos[1], 0), collision=((("rectangle", 0, 0, horizontal_wall_width, thickness),)), ) if left: entities.insert( state, ENT_LEFTWALL, {"*": {"textures": (("rectangle", thickness, vertical_wall_height, color[0], color[1], color[2]),)}}, (pos[0], pos[1], 0), collision=((("rectangle", 0, 0, thickness, vertical_wall_height),)), ) if top: entities.insert( state, ENT_TOPWALL, {"*": {"textures": (("rectangle", horizontal_wall_width, thickness, color[0], color[1], color[2]),)}}, (pos[0], pos[1] + vertical_wall_height - thickness, 0), collision=((("rectangle", 0, 0, horizontal_wall_width, thickness),)), ) if right: entities.insert( state, ENT_RIGHTWALL, {"*": {"textures": (("rectangle", thickness, vertical_wall_height, color[0], color[1], color[2]),)}}, (pos[0] + horizontal_wall_width - thickness, pos[1], 0), collision=((("rectangle", 0, 0, thickness, vertical_wall_height),)), )
def add_barrel(state, x, y): barrel_count = user.get_data(state, "n_barrels") barrel_entity_name = "barrel_%d" % barrel_count user.set_data(state, "n_barrels", barrel_count + 1) entities.insert(state, barrel_entity_name, { "*": { "textures": ("assets/img/sprites/barrel.png", ), }, }, ( x, y, 0, ), collision=(( "circle", (1.0 / 4.0) / 2.0, (1.0 / 4.0) / 2.0, (1.0 / 4.0) / 2.0, ), )) physical_mover.add( state, barrel_entity_name, 0.01, 0, 0, 0, 0, 0.92, YAPYG_STD_INELASTICITY, 0, YAPYG_STD_ROT_FRICTION, YAPYG_STD_ROT_DECAY, YAPYG_STD_STICKYNESS, )
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
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)
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
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
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
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
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
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
def create_collision_box(state, base_name, pos, size, thickness, top=True, bottom=True, left=True, right=True, color=(1, 1, 1)): """ TODO """ ENT_TOPWALL = base_name + "_top" ENT_LEFTWALL = base_name + "_left" ENT_RIGHTWALL = base_name + "_right" ENT_BOTTOMWALL = base_name + "_bottom" horizontal_wall_width = size[0] vertical_wall_height = size[1] if bottom: entities.insert(state, ENT_BOTTOMWALL, { "*": { "textures": (( "rectangle", horizontal_wall_width, thickness, color[0], color[1], color[2], ), ), }, }, (pos[0], pos[1], 0), collision=((("rectangle", 0, 0, horizontal_wall_width, thickness), ))) if left: entities.insert(state, ENT_LEFTWALL, { "*": { "textures": (( "rectangle", thickness, vertical_wall_height, color[0], color[1], color[2], ), ), }, }, (pos[0], pos[1], 0), collision=((("rectangle", 0, 0, thickness, vertical_wall_height), ))) if top: entities.insert(state, ENT_TOPWALL, { "*": { "textures": (( "rectangle", horizontal_wall_width, thickness, color[0], color[1], color[2], ), ), }, }, (pos[0], pos[1] + vertical_wall_height - thickness, 0), collision=((("rectangle", 0, 0, horizontal_wall_width, thickness), ))) if right: entities.insert( state, ENT_RIGHTWALL, { "*": { "textures": (( "rectangle", thickness, vertical_wall_height, color[0], color[1], color[2], ), ), }, }, (pos[0] + horizontal_wall_width - thickness, pos[1], 0), collision=((("rectangle", 0, 0, thickness, vertical_wall_height), )))
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
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
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
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
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