Your browser does not support the canvas element.

cPLPZRDVw
1 Plays Last modified: December 7, 2017
0

gary oak

{“game”:{“type”:”game script”,”start”:”# Enter the start code for your game here.\n\nimport math\n\n# ———————————————————————-\n# Win Function\n# ———————————————————————-\n\ndef win():\n playing = False\n game.quit_mixins(game.pc)\n destroy(game.pc)\n room_set(‘rm_win’)\n\n# ———————————————————————-\n# Infinite Scrolling Background System\n# ———————————————————————-\n\ndef make_background(sprite_names):\n bg_list = []\n layer_i = 0\n \n for sprite_name in sprite_names:\n bg_layer = []\n bg_list.append(bg_layer)\n bg_sprite = sprite_new(sprite_name)\n \n for i in range(0, 9):\n bg_obj = object_new(‘obj_bg_layer’)\n bg_obj.sprite = bg_sprite\n \n bg_row = game.math.floor(i \/ 3) – 1\n bg_col = i % 3 – 1\n \n bg_obj.x = game.math.floor(bg_col * (object_width(bg_obj) – 1))\n bg_obj.y = game.math.floor(bg_row * (object_height(bg_obj)- 1))\n bg_obj.z = -1 – layer_i\n \n bg_layer.append(bg_obj)\n \n layer_i += 1\n \n return bg_list\n\ndef tick_background(bg_list):\n for bg_layer in bg_list:\n for bg_obj in bg_layer:\n # Loop BG left -> right\n if screen_x(bg_obj.x) + object_width(bg_obj) \/ 2 left\n if screen_x(bg_obj.x) – object_width(bg_obj) \/ 2 > screen_width() \/ 2:\n bg_obj.x -= (object_width(bg_obj) – 1) * 3\n \n # Loop BG bottom -> top\n if screen_y(bg_obj.y) + object_height(bg_obj) \/ 2 bottom\n if screen_y(bg_obj.y) – object_height(bg_obj) \/ 2 > screen_height() \/ 2:\n bg_obj.y -= (object_height(bg_obj) – 1) * 3\n\n# ———————————————————————-\n# Mixin System\n# ———————————————————————-\n\n# Adds mixins to obj\ndef init_mixins(obj):\n obj.tick_hooks = []\n \ndef quit_mixins(obj):\n obj.tick_hooks = []\n \n# Call all tick hooks on an object\ndef tick_mixins(obj):\n for i in range(0, len(obj.tick_hooks)):\n obj.tick_hooks[i](obj)\n \n# Add a tick hook to an object – called by mixin init functions\ndef add_tick_hook(obj, tick_hook):\n obj.tick_hooks.append(tick_hook)\n\n# ———————————————————————-\n# Health Mixin\n# ———————————————————————-\n\ndef die(obj):\n playing = False\n game.quit_mixins(obj)\n destroy(obj)\n if obj.type == ‘obj_pc’:\n room_set(‘rm_lose’)\n\ndef take_damage(obj, obj2, amount):\n obj.hp -= amount\n obj.hurt = True\n if obj.hp_obj:\n obj.hp_obj.text.text = \”Health: \” + str(obj.hp)\n if obj.type == ‘obj_pc’:\n pos_dx = obj.x – obj2.x\n obj.kb_dx = obj.run_speed * game.sign(pos_dx)\n obj.kb_d = 0.5\n obj.kb_t = 0\n \n obj.dx = obj.kb_dx\n obj.dy = obj.jump_speed\n\ndef tick_health(obj):\n if obj.hp <= 0:\n game.die(obj)\n\ndef init_health(obj, hp, display):\n obj.hp = hp\n if display:\n obj.hp_obj = object_new('obj_health')\n else:\n obj.hp_obj = None\n game.add_tick_hook(obj, game.tick_health)\n\n# ———————————————————————-\n# Camera Follow Mixin\n# ———————————————————————-\n\ndef camera_follow_y(obj):\n if screen_y(obj.y) < -screen_height() \/ 2 + object_height(obj) \/ 2:\n camera_set(camera_x(), obj.y + screen_height() \/ 2 – object_height(obj) \/ 2)\n returnta\n \n cam_dy = screen_y(obj.y) + obj.overpan['y']\n \n correction = game.tick * obj.correction_speed['y'] * cam_dy\n if abs(correction) < 10:\n camera_move(0, cam_dy)\n else:\n camera_move(0, correction * game.tick)\n \ndef camera_follow_x(obj):\n cam_dx = screen_x(obj.x)\n cam_dx += obj.overpan['x']\n\n correction = game.tick * obj.correction_speed['x'] * cam_dx\n camera_move(correction * game.tick, 0)\n\ndef tick_camera_follow(obj):\n if obj.on_ground or screen_y(obj.y) < -screen_height() \/ 6:\n game.camera_follow_y(obj)\n game.camera_follow_x(obj)\n \ndef init_camera_follow(obj, correction_speed, overpan):\n camera_set(obj.x, obj.y)\n obj.correction_speed = correction_speed\n obj.overpan = overpan\n game.add_tick_hook(obj, game.tick_camera_follow)\n\n# ———————————————————————-\n# Velocity Mixin\n# ———————————————————————-\n\nMAX_SPEED = 800\n\ndef tick_velocity(obj):\n if obj.dy 0:\n obj.run_speed -= abs(obj.run_speed \/ 15)\n else:\n obj.run_speed += abs(obj.run_speed \/ 15)\n \n if key_is_pressed(‘left’):\n obj.run_speed -= 15\n if key_is_pressed(‘right’):\n obj.run_speed += 15\n if key_was_pressed(‘z’):\n if obj.on_ground:\n obj.dy = obj.jump_speed\n obj.on_ground = False\n if key_was_pressed(‘x’):\n obj.should_shoot = True\n\n if abs(obj.dx) > 0:\n obj.facing = game.sign(obj.dx)\n\n if obj.dx 0:\n# obj.facing = game.sign(obj.dx)\n# \n# if obj.dx = obj.max_shots:\n return\n \n shot = object_new(‘obj_basic_shot’)\n shot.x = obj.x + obj.facing * (object_width(obj) \/ 2 + 2)\n shot.y = obj.y\n shot.direction = obj.facing\n shot.ignore.append(obj.type)\n shot.ignore.append(‘obj_bg_layer’)\n shot.ignore.append(‘obj_health’)\n shot.ignore.append(‘obj_generictext’)\n shot.ignore.append(‘obj_win_zone’)\n shot.parent = obj\n obj.active_shots.append(shot)\n shot.direction = obj.facing\n\ndef tick_shooting(obj):\n if obj.should_shoot:\n game.shoot_from(obj)\n obj.should_shoot = False\n \ndef init_shooting(obj, max_shots):\n obj.active_shots = []\n obj.max_shots = max_shots\n game.add_tick_hook(obj, game.tick_shooting)\n \n# ———————————————————————-\n# Collision Mixin\n# ———————————————————————-\n\ndef handle_solid_collisions(obj):\n obj.on_ground = False\n skin_size = 2\n \n for solid_type in obj.solids:\n for obj2 in collision_check_skin_all(obj, solid_type, skin_size, skin_size):\n mpv = game.mpv(obj, obj2, skin_size, skin_size)\n \n # Vertical collision\n if abs(mpv[‘y’]) > 0:\n xpen = game.xpen(obj, obj2, skin_size, skin_size)\n \n # Need a minimum X penetration before handling, so that we can’t land or\n # bump our head on the edges of walls\n if xpen < 5:\n pass\n \n # Handle landing\n elif mpv['y'] < 0:\n if obj.dy 0:\n ypen = game.ypen(obj, obj2, skin_size, skin_size)\n \n # Need a minimum Y penetration before handling, so that we don’t get shoved\n # to the side when we land or bonk our head\n if ypen < 5:\n pass\n \n # Handle OBJ2 <- OBJ\n elif mpv['x'] OBJ2\n else:\n obj.x = obj2.x – (object_width(obj2) \/ 2 + object_width(obj) \/ 2)\n\ndef handle_enemy_collisions(obj):\n if obj.kb_t < obj.kb_d:\n obj.hurt = True\n obj.kb_t += game.tick\n obj.dx = obj.kb_dx\n \n else:\n obj.hurt = False\n for enemy_type in obj.enemies:\n for obj2 in collision_check_all(obj, enemy_type):\n game.take_damage(obj, obj2, 1)\n\ndef tick_collisions(obj):\n game.handle_solid_collisions(obj)\n game.handle_enemy_collisions(obj)\n\ndef init_collisions(obj, solids, enemies):\n obj.solids = solids\n obj.enemies = enemies\n obj.on_ground = False\n obj.hurt = False\n obj.kb_t = 0\n obj.kb_d = 0\n game.add_tick_hook(obj, game.tick_collisions)\n\n# ———————————————————————-\n# Utilities\n# ———————————————————————-\n\n# Compute the X Penetration (xpen) of two objects using the Minkowski Difference\ndef xpen(obj, obj2, skin_width, skin_height):\n md = game.minkowski(obj, obj2, skin_width, skin_height)\n \n if abs(md['L']) < abs(md['R']):\n return abs(md['L'])\n else:\n return abs(md['R'])\n \ndef ypen(obj, obj2, skin_width, skin_height):\n md = game.minkowski(obj, obj2, skin_width, skin_height)\n \n if abs(md['B']) < abs(md['T']):\n return abs(md['B'])\n else:\n return abs(md['T'])\n\n# Compute the Minimum Penetration Vector (MPV) of two objects relative to the first object\n# Basically, subtract the MPV from the first object's position, and the two objects will\n# no longer be overlapping\n# Assumes objects are colliding, results won't make sense if not\ndef mpv(obj1, obj2, skin_width, skin_height):\n md = game.minkowski(obj1, obj2, skin_width, skin_height)\n \n if abs(md['L']) < abs(md['R']):\n min_x = md['L']\n else:\n min_x = md['R']\n \n if abs(md['B']) < abs(md['T']):\n min_y = md['B']\n else:\n min_y = md['T']\n \n if abs(min_x) = 0:\n return 1\n else:\n return -1\n\n# ———————————————————————-\n# Start Game\n# ———————————————————————-\n\nroom_set(\”rm_level_01\”)\nplaytime = 0\nplaying = True”,”loop”:”# Enter the loop code for your game here.\n\nif playing:\n playtime += game.tick”},”rm_level_01″:{“type”:”room script”,”start”:”# Enter the start code for rm_level_01 here.\n\n# Mapping Primitives\n\nBLOCK_SIZE = 31\n\nspawn_x = 0\nspawn_y = 0\n\ndef move_horz(dx):\n spawn_x += dx * BLOCK_SIZE\n\ndef move_vert(dy):\n spawn_y += dy * BLOCK_SIZE\n\ndef blocks_horz(count):\n result = []\n dir = game.sign(count)\n \n for i in range(abs(count)):\n b = object_new(‘obj_nrm_block’)\n result.append(b)\n \n b.x = spawn_x + i * BLOCK_SIZE * dir\n b.y = spawn_y\n \n move_horz(count)\n return result\n \ndef blocks_vert(count):\n result = []\n dir = game.sign(count)\n \n for i in range(abs(count)):\n b = object_new(‘obj_nrm_block’)\n result.append(b)\n \n b.x = spawn_x\n b.y = spawn_y + i * BLOCK_SIZE * dir\n \n move_vert(count)\n return result\n \ndef enemy_gnd(rel_x, rel_y, patrol_L, patrol_R):\n e = object_new(‘obj_gnd_enemy’)\n e.x = spawn_x + rel_x * BLOCK_SIZE\n e.y = spawn_y + rel_y * BLOCK_SIZE\n e.patrol_L = spawn_x + (rel_x + patrol_L) * BLOCK_SIZE\n e.patrol_R = spawn_x + (rel_x + patrol_R) * BLOCK_SIZE\n return e\n \ndef win_zone(rel_x, rel_y):\n z = object_new(‘obj_win_zone’)\n z.x = spawn_x + rel_x * BLOCK_SIZE\n z.y = spawn_y + rel_y * BLOCK_SIZE\n return z\n \n# Major Sections\n \ndef section_01():\n blocks_horz(10)\n blocks_vert(1)\n blocks_horz(1)\n blocks_vert(1)\n blocks_horz(5)\n move_horz(2)\n blocks_horz(5)\n move_horz(2)\n blocks_horz(5)\n enemy_gnd(-3, 1, -2, 2)\n move_horz(2)\n blocks_horz(5)\n move_horz(2)\n blocks_vert(-2)\n blocks_horz(10)\n \ndef section_02():\n move_horz(2)\n blocks_horz(1)\n blocks_vert(1)\n blocks_horz(1)\n blocks_vert(1)\n blocks_horz(2)\n enemy_gnd(-2, 1, 0, 1)\n blocks_vert(2)\n blocks_horz(5)\n \ndef section_03():\n blocks_vert(-10)\n blocks_horz(5)\n move_vert(4)\n blocks_horz(10)\n move_horz(-10)\n move_vert(-4)\n move_horz(2)\n blocks_horz(3)\n move_horz(2)\n blocks_horz(3)\n move_horz(2)\n blocks_horz(2)\n enemy_gnd(-1, 1, 0, 0)\n blocks_vert(2)\n blocks_horz(2)\n blocks_vert(2)\n blocks_horz(2)\n \ndef section_04():\n move_horz(2)\n blocks_horz(1)\n move_horz(2)\n blocks_vert(2)\n enemy_gnd(0, 0, 0, 0)\n move_horz(3)\n move_vert(-2)\n blocks_horz(1)\n move_horz(2)\n blocks_vert(2)\n enemy_gnd(0, 0, 0, 0)\n move_horz(3)\n move_vert(-2)\n blocks_horz(1)\n move_horz(2)\n blocks_vert(2)\n enemy_gnd(0, 0, 0, 0)\n move_horz(2)\n blocks_vert(1)\n move_horz(2)\n blocks_vert(1)\n move_horz(3)\n blocks_vert(2)\n move_horz(2)\n move_vert(1)\n blocks_horz(20)\n win_zone(-1, 1)\n\npc = object_new(‘obj_pc’)\nbg = game.make_background([‘spr_bg_castle’])\n\ngame.pc = pc\n\nmove_vert(-4)\nmove_horz(-4)\nblocks_vert(20)\nmove_vert(-20)\n\nsection_01()\nsection_02()\nsection_03()\nsection_04()\n\n#bgm = sound_new(‘snd_bgm’)\n#sound_volume(10)\n#sound_loop(bgm)”,”loop”:”# Enter the loop code for rm_level_01 here.\n\ngame.tick_background(bg)\n\nif game.pc.y 0:\n animation_set(self, anim_jump)\n else:\n if abs(dx) > 40:\n animation_set(self, anim_walk)\n else:\n animation_set(self, anim_stand)”},”obj_nrm_block”:{“type”:”object script”,”start”:”# Enter the start code for obj_nrm_block here.\n\nsprite = sprite_new(\”spr_dirt_mid\”)”,”loop”:”# Enter the loop code for obj_nrm_block here.”},”spr_tiles”:{“type”:”image”,”uri”:”https:\/\/pixelpad.io\/wp-content\/uploads\/project_assets\/881\/67916\/spr_tiles.png”},”obj_bg_layer”:{“type”:”object script”,”start”:”# Enter the start code for obj_bg_layer here.”,”loop”:”# Enter the loop code for obj_bg_layer here.”},”obj_gnd_enemy”:{“type”:”object script”,”start”:”# Enter the start code for obj_gnd_enemy here.\n\nimport random\n\ngame.init_mixins(self)\ngame.init_shooting(self, 1)\ngame.init_health(self, 3, False)\n\nfacing = -1\nspeed = 75\n\nsprite = sprite_new(‘spr_snail’)\n\nfacing_player = False\ntime_since_last_shot = 0\nshot_delay = 0.4\n\nstopped = False\ntime_since_last_stop = 0\nnext_stop = random.randrange(4, 10)\nstop_duration = 1″,”loop”:”# Enter the loop code for obj_gnd_enemy here.\n\nif not facing_player and not stopped:\n x += speed * facing * game.tick\n if x = patrol_R:\n x = patrol_R – 1\n facing = -1\n sprite_xscale = 1\n\nplayer_dx = game.pc.x – self.x\nplayer_dy = game.pc.y – self.y\n\nif player_dx * facing > 0:\n facing_player = abs(player_dx) shot_delay:\n should_shoot = True\n time_since_last_shot = 0\nelse:\n time_since_last_shot = 0\n\nif stopped:\n time_stopped += game.tick\n if time_stopped >= stop_duration:\n stopped = False\n time_since_last_stop = 0\nelse:\n time_since_last_stop += game.tick\n if time_since_last_stop >= next_stop:\n stopped = True\n time_stopped = 0\n next_stop = random.randrange(4, 10)\n \ngame.tick_mixins(self)”},”obj_basic_shot”:{“type”:”object script”,”start”:”# Enter the start code for obj_basic_shot here.\n\nsprite = sprite_new(‘spr_tiles’, 2, 2)\nsprite.cell = 3\nsprite_width = 0.2\nsprite_height = 0.2\nsprite_rotation = 0\n\nalive = 0\nmax_alive = 2\n\nignore = [self.type]\ndx = 200″,”loop”:”# Enter the loop code for obj_basic_shot here.\n\nx += dx * direction * game.tick\n\n# If farther than 1 screen width from camera, self destruct\nif abs(screen_x(x)) >= screen_width():\n destroy(self)\n parent.active_shots.remove(self)\n \nalive += game.tick\n\n# If lasted longer than max lifespan, self destruct\nif alive >= max_alive:\n destroy(self)\n parent.active_shots.remove(self)\n \n# If colliding with anything not in ignore list, destroy self\nany_colls = False\nfor obj in collision_check_all(self):\n if obj == self:\n continue\n \n if self.ignore.index(obj.type) < 0:\n game.take_damage(obj, self, 1)\n any_colls = True\n \nif any_colls:\n destroy(self)\n parent.active_shots.remove(self)\n \nsprite_rotation += 360 * game.tick * direction"},"obj_health":{"type":"object script","start":"# Enter the start code for obj_health here.\n\ntext = text_new('sans-serif', 16)\ntext.text = 'Health: 10'\nz = 1000","loop":"# Enter the loop code for obj_health here.\n\nx = camera_x() – (screen_width() \/ 4 + 50)\ny = camera_y() + (screen_height() \/ 4 + 80)"},"rm_lose":{"type":"room script","start":"# Enter the start code for rm_lose here.\n\nyoulose = object_new('obj_generictext')\nyoulose.text.text = 'You Lose!'\nyoulose.text.size = 48\nyoulose.y = 100\n\ntryagain = object_new('obj_generictext')\ntryagain.text.text = 'Press [Z] to try again'\ntryagain.text.size = 24\ntryagain.y = -100","loop":"# Enter the loop code for rm_lose here.\n\nif key_is_pressed('z'):\n game.playing = True\n game.playtime = 0\n room_set('rm_level_01')"},"obj_generictext":{"type":"object script","start":"# Enter the start code for obj_generictext here.\n\ntext = text_new('sans-serif', 16)","loop":"# Enter the loop code for obj_generictext here."},"rm_win":{"type":"room script","start":"# Enter the start code for rm_win here.\n\nimport math\n\nyouwin = object_new('obj_generictext')\nyouwin.text.text = 'You Win!'\nyouwin.text.size = 48\nyouwin.y = 180\n\nplaytime = object_new('obj_generictext')\nplaytime.text.text = 'You reached the end in\\n' + math.floor(game.playtime * 100) \/ 100 + '\\nseconds!'\nplaytime.text.size = 32\n\ntryagain = object_new('obj_generictext')\ntryagain.text.text = 'Press [Z] to play again'\ntryagain.text.size = 24\ntryagain.y = -180","loop":"# Enter the loop code for rm_win here.\n\nif key_is_pressed('z'):\n game.playing = True\n game.playtime = 0\n room_set('rm_level_01')"},"obj_win_zone":{"type":"object script","start":"# Enter the start code for obj_win_zone here.\n\nsprite = sprite_new_box(32, 32)\n\nsprite_color = 'white'","loop":"# Enter the loop code for obj_win_zone here.\n\nif collision_check(self, 'obj_pc'):\n game.win()\n \nsprite_rotation += 360 * game.tick"},"snd_bgm":{"type":"audio","uri":"https:\/\/pixelpad.io\/wp-content\/uploads\/project_assets\/881\/67916\/snd_bgm.dat"},"spr_player_stand":{"type":"image","uri":"https:\/\/pixelpad.io\/wp-content\/uploads\/project_assets\/881\/67916\/spr_player_stand.png"},"spr_snail":{"type":"image","uri":"https:\/\/pixelpad.io\/wp-content\/uploads\/project_assets\/881\/67916\/spr_snail.png"},"spr_player_walk_sheet":{"type":"image","uri":"https:\/\/pixelpad.io\/wp-content\/uploads\/project_assets\/881\/67916\/spr_player_walk_sheet.png"},"spr_bg_castle":{"type":"image","uri":"https:\/\/pixelpad.io\/wp-content\/uploads\/project_assets\/881\/67916\/spr_bg_castle.png"},"spr_dirt_mid":{"type":"image","uri":"https:\/\/pixelpad.io\/wp-content\/uploads\/project_assets\/881\/67916\/spr_dirt_mid.png"},"spr_player_jump":{"type":"image","uri":"https:\/\/pixelpad.io\/wp-content\/uploads\/project_assets\/881\/67916\/spr_player_jump.png"},"spr_player_hurt":{"type":"image","uri":"https:\/\/pixelpad.io\/wp-content\/uploads\/project_assets\/881\/67916\/spr_player_hurt.png"}}

0
67916