{"assets":{"script":[{"Game":{"type":"game script","start":"from datetime import datetime\r\n\r\nself.start_time = datetime.now();\r\nself.time = 0;\r\n\r\nset_room('Level1')","loop":"from datetime import datetime\r\nself.time = (datetime.now() - self.start_time);"}},{"Player":{"type":"object script","start":"#Player start\n\nself.WIDTH = 90;\nself.HEIGHT = 90;\n\nself.STATE_IDLE = 0;\nself.STATE_RUNNING = 1;\nself.STATE_JUMPING = 2;\n\nself.animation_state = self.STATE_IDLE;\n\nself.vel_x = 0;\nself.vel_y = 0;\n\nself.Animation_Idle = new_animation(new_sprite(\"Player_Idle.png\", 1, 11), 15, 0, 10);\nself.Animation_Run = new_animation(new_sprite(\"Player_Run.png\", 1, 12), 15, 0, 11);\nset_animation(self, self.Animation_Idle);\n","loop":"import math;\n\n################################################################################\n# Constants.\n\n# The amount of downward acceleration to apply per frame.\nGRAVITY_Y = -0.98;\n\n# How fast the user moves left / right. The higher the number\n# the faster the player moves. However, if this number is too high\n# the collision system may get weird.\nMOVE_SPEED = 4;\n\n# How much force to apply when jumping. The higher the number\n# the higher the jump. However, if this number is too high\n# the collision system may get weird.\nJUMP_FORCE = 16;\n\n################################################################################\n# Setup animation state (see end of frame for animation state resolution). We\n# only want to call set_animation if the animation has changed (because calling\n# set_animation with the same animation hangs the animation). So we run our\n# various movement / collision logic to determine a new animation state,\n# and compare it against the previous animation state to determine if\n# a new animation needs to start playing. (Search \"Resolve Animation\" at\n# the end of this file).\n\n# Set the new animation state to the previous one. If this doesn't change\n# by the end of the player update (loop) then we don't do anything\n# (eg. no need to change from idle -> running or idle -> jump, ...etc.).\nnewAnimationState = self.animation_state;\n\n################################################################################\n# Apply forces (movement, jumping, gravity) to the player sprite.\n\n# Track if the player is moving a certain direction. This is useful if we need\n# more context as to which animations to play (eg. running if we are on ground).\nisMovingLeft = False;\nisMovingRight = False;\n\n# Left / Right movement.\nif key_is_pressed('a'): # Left\n isMovingLeft = True;\n \n # Set the sprite's velocity to move left.\n self.vel_x = -MOVE_SPEED;\n\n # Make sprite face left.\n self.scaleX = -1;\n \n # Set the animation state to running (if not jumping).\n if(self.animation_state != self.STATE_JUMPING):\n newAnimationState = self.STATE_RUNNING;\nelif key_is_pressed('d'): # Right\n isMovingRight = True;\n \n # Set the sprite's velocity to move right.\n self.vel_x = +MOVE_SPEED;\n\n # Make sprite face right.\n self.scaleX = 1;\n\n # Set the animation state to running (if not jumping).\n if(self.animation_state != self.STATE_JUMPING):\n newAnimationState = self.STATE_RUNNING;\nelse:\n # We are not moving left or right. So if we are not\n # in a jumping state, set the animation to idle.\n if(self.animation_state != self.STATE_JUMPING):\n newAnimationState = self.STATE_IDLE;\n\n # We are not longer moving left or right, but our\n # vel_x may still be fully active. Slow down our vel_x\n # by some amount every frame (makes the player look like\n # they are sliding to slow down). The higher the value\n # the quicker they slow down. Values <= 1 are not advised.\n self.vel_x /= 1.1;\n\n# Jumping.\nif key_is_pressed(' '):\n # Do not jump (again) if we are already jumping.\n if(self.animation_state != self.STATE_JUMPING):\n # Apply upward jump force to vel_y and force\n # our animation state to jumping (no matter what).\n # Jump cancels both idle / running animations.\n self.vel_y += JUMP_FORCE;\n newAnimationState = self.STATE_JUMPING;\n\n# Apply gravity.\nself.vel_y += GRAVITY_Y;\n\n# Apply our velocity to the player's (x, y) position. Note that the velocity\n# is essentially the aggregate forces from moving, jumping and gravity all\n# being applied to our new position.\nself.x += self.vel_x;\nself.y += self.vel_y;\n\n################################################################################\n# Process collisions - We gather all of our collisions, and we process them\n# one at a time. Depending on where the block is relative to the player, we\n# process collisions for one side (edge) of the block (left, right, top, bottom).\n# This lets us support not just ground collisions, but wall collisions and\n# ceiling collisions.\n\n# The player's sprite is just a box. These values represent the various\n# edge values for the right, left, top, bottom values of the sprite box.\nplayer_right_edge = self.x + (self.WIDTH / 2);\nplayer_left_edge = self.x - (self.WIDTH / 2);\nplayer_top_edge = self.y + (self.HEIGHT / 2);\nplayer_bottom_edge = self.y - (self.HEIGHT / 2);\n\n# Process (ALL) collisions on by one.\ncollisions = get_collision_list(self, 'Block');\nfor block in collisions:\n block_right = (block.x + block.WIDTH / 2);\n block_left = (block.x - block.WIDTH / 2);\n block_top = (block.y + block.HEIGHT / 2);\n block_bottom = (block.y - block.HEIGHT / 2);\n\n # Calculate the absolute depth of collision from all four sides.\n right_collision_length = abs(player_left_edge - block_right);\n left_collision_length = abs(player_right_edge - block_left);\n top_collision_length = abs(player_bottom_edge - block_top);\n bottom_collision_length = abs(player_top_edge - block_bottom);\n\n # Determine the direction of this collision. The smallest collision\n # depth (relative to right, left, top, bottom) determines which\n # side is the dominant collision side. The logic looks crazy, but\n # if you look closely, we are just figuring out the smallest\n # XYZ_collision_length (that we calculated right above) and\n # selecting that side.\n right_collision = False;\n left_collision = False;\n top_collision = False;\n bottom_collision = False;\n if(right_collision_length < left_collision_length):\n if(top_collision_length < bottom_collision_length):\n if(right_collision_length < top_collision_length):\n right_collision = True;\n else:\n top_collision = True;\n else:\n if(right_collision_length < bottom_collision_length):\n right_collision = True;\n else:\n bottom_collision = True;\n else:\n if(top_collision_length < bottom_collision_length):\n if(left_collision_length < top_collision_length):\n left_collision = True;\n else:\n top_collision = True;\n else:\n if(left_collision_length < bottom_collision_length):\n left_collision = True;\n else:\n bottom_collision = True;\n\n # If we've collided against the right side of a block.\n if(right_collision):\n self.x = block_right + (self.WIDTH / 2);\n\n # If we've collided against the left side of a block.\n elif(left_collision):\n self.x = block_left - (self.WIDTH / 2);\n\n # If we've collided against the bottom side of a block (eg. jumping).\n elif(bottom_collision):\n self.y = block_bottom - (self.HEIGHT / 2);\n\n # If we've collided against the top side of a block (eg. falling).\n elif(top_collision):\n self.y = block_top + (self.HEIGHT / 2);\n\n # Zero out our hight velocity. We've essentially hit a floor block,\n # so this effectively cancels out any gravity that's accumulating.\n self.vel_y = 0.0;\n\n if((isMovingLeft == False) and (isMovingRight == False)):\n # If we are only falling (and not moving right / left) we can\n # set our animation to idle.\n newAnimationState = self.STATE_IDLE;\n else:\n # We are moving left / right, and we've hit the ground (so no\n # longer jumping) - so we set our animation to running.\n newAnimationState = self.STATE_RUNNING;\n\n################################################################################\n# Resolve Animation. We've processed our movement / collision logic, and can\n# determine if a new animation needs to be playing.\n\nif(newAnimationState != self.animation_state):\n if(newAnimationState == self.STATE_JUMPING):\n set_animation(self, self.Animation_Run);\n elif(newAnimationState == self.STATE_RUNNING):\n set_animation(self, self.Animation_Run);\n elif(newAnimationState == self.STATE_IDLE):\n set_animation(self, self.Animation_Idle);\n self.animation_state = newAnimationState;\n\n################################################################################"}},{"Block":{"type":"object script","start":"#Block start\n\nself.sprite = sprite('Block_Grass.png');\nself.WIDTH = 96;\nself.HEIGHT = 96;","loop":"#Block loop\n\n"}},{"Background":{"type":"object script","start":"#Background start\n\n","loop":"#Background loop\n\n"}}],"room":[{"Level1":{"type":"room script","start":"#Level1 start\n\n################################################################################\n\n# Each '1' represents a block.\ntileData = [\n [0,0,0,0,0,0,0,0,0,0],\n [0,0,0,0,0,0,1,0,0,0],\n [0,0,0,0,0,1,1,0,0,1],\n [1,0,0,1,0,0,0,0,1,1],\n [1,1,0,1,1,0,0,0,0,1],\n [1,1,1,1,1,1,1,1,1,1],\n];\n\n################################################################################\n\nSCREEN_WIDTH = 900;\nSCREEN_HEIGHT = 540;\nSCREEN_HALF_WIDTH = SCREEN_WIDTH / 2;\nSCREEN_HALF_HEIGHT = SCREEN_HEIGHT / 2;\n\n################################################################################\n\n# Background.\nbackground = Background();\nbackground.sprite = sprite('Background.jpg');\n\n# Generate map data.\nfor y in range(len(tileData)):\n for x in range(len(tileData[y])):\n block_type = tileData[y][x];\n if(block_type == 1):\n block = Block();\n block.x = -SCREEN_HALF_WIDTH + x * block.WIDTH;\n block.y = SCREEN_HALF_HEIGHT - y * block.HEIGHT;\n\n################################################################################\n\nplayer = Player();\n\n################################################################################\n\ntext(\"Controls: A = Left, D = Right, Space = Jump\", - SCREEN_WIDTH / 2, - SCREEN_HEIGHT / 2)\n\n################################################################################","loop":"#Level1 loop\n\n"}}],"texture":[{"Player_Idle.png":{"type":"image","uri":"https://s3.us-west-1.amazonaws.com/media.pixelpad.io/__ASSET__.20122.226977.1616387956.Player_Idle.png"}},{"Player_Run.png":{"type":"image","uri":"https://s3.us-west-1.amazonaws.com/media.pixelpad.io/__ASSET__.20122.226977.1616397404.Player_Run.png"}},{"Player_Jump.png":{"type":"image","uri":"https://s3.us-west-1.amazonaws.com/media.pixelpad.io/__ASSET__.20122.226977.1616388176.Player_Jump.png"}},{"Background.jpg":{"type":"image","uri":"https://s3.us-west-1.amazonaws.com/media.pixelpad.io/__ASSET__.20122.226977.1616388351.Background.jpg"}},{"Block_Grass.png":{"type":"image","uri":"https://s3.us-west-1.amazonaws.com/media.pixelpad.io/__ASSET__.20122.226977.1616388551.Block_Grass.png"}}],"sound":[],"function":[]}}