The Adventures of Tokk Project Report Raphael Leon 31 may 2014 | Page 11

These variables tell the character what keyboard buttons will effect its movement. This states that the “right arrow” moves right (it is equal to +1), the “left arrow” moves left (it is equal to -1) and the “space bar” jumps. // react to imputs move = key_left + key_right; hsp = move * movespeed; As only one key is usually pressed “move” equals “key_left” + “key_right” which means “move” will either be +1 or -1 (or 0 if both or neither is pressed). Our horizontal speed, hsp, is equal to “-1 X 4” if the left key is pressed causing the character to move left and the opposite is true if the right key is pressed. if (vsp < 10) vsp += grav; if (place_meeting (x, y+1, obj_wall)) { vsp = key_jump * -jumpspeed } The first line of code makes gravity affect the player. The next line states that if the character is grounded (“x, y+1, obj_wall” asks the computer whether one pixel below the character is a wall), vertical speed, vsp, can equal +1 when the space bar is pressed times by -7 (jumpspeed) resulting in a jump. // horizontal collision if (place_meeting (x+hsp, y, obj_wall)) { while(!place_meeting (x+sign(hsp) ,y, obj_wall)) { x += sign(hsp); } hsp = 0; } x +=hsp; The first three lines tell the character to see whether it is about to collide with the object_wall and if it is to prepare for a collision when it does. The last line (x +=hsp;) means that the engine will add our horizontal speed to the Y coordinate. // vertical collision if (place_meeting (x, y+vsp, obj_wall)) { while(!place_meeting (x, y+sign(vsp), obj_wall)) { y += sign(vsp); } vsp = 0; } y += vsp; The first three lines tell the character to see whether it is about to collide with the object_wall and if it is, to prepare for a collision when it does. The last 11 | P a g e