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

line (y +=vsp;) means that the engine will add our vertical speed to the Y coordinate. Enemy Script Create Event /// initialise variables dir = -1; movespeed = 3; grav = 0.2; hsp = 0; vsp = 0; These are the variables that will be called upon later in the step event. Step Event hsp = dir * movespeed; vsp += grav; The horizontal speed, hsp, is just the movespeed (3) times by its direction. The enemy’s vertical speed, vsp, is only affected by gravity. // horizontal collision if (place_meeting (x+hsp, y, obj_wall)) { while(!place_meeting (x+sign(hsp) ,y, obj_wall)) { x += sign(hsp); } hsp = 0; dir *= -1; } x += hsp; // 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 vertical and horizontal collisions of the wall with the enemy are so similar to that of the character that it can simply be reused with few changes. The main change is that when the character collides with a wall in the horizontal axis the enemy will change direction. 12 | P a g e