obj_hero on create:
Código: Selecionar todos
/// initialize variables
grav = 1;
spd = 4;
jspd = 12;
hspd = 0;
vspd = 0;
Código: Selecionar todos
/// hero physics
var rkey = keyboard_check("vk_right")
var lkey = keyboard_check("vk_left")
var jkey = keyboard_check("vk_up")
// check is ground
if (place_meeting(x, y+1, obj_floor)){
vspd = 0;
// jumping
if (jkey){
vspd = -jspd;
}
} else{
// gravity
if(vspd < 10){
vspd += grav;
}
}
// moving right
if(rkey){
hspd = spd;
}
//moving left
if(lkey){
hspd = -spd;
}
//check for not moving
if((!rkey && !lkey) || (rkey && lkey)){
hspd = 0;
}
// horizontal collisions
if (place_meeting(x+hspd, y, obj_floor)){
while(!place_meeting(x+sign(hspd), y, obj_floor)){
x+= sign(hspd);
}
hspd = 0;
}
//move horizontally
x += hspd;
// vertical collisions
if (place_meeting(x, y+vspd, obj_floor)){
while(!place_meeting(x, y+sign(vspd), obj_floor)){
y += sign(vspd);
}
vspd = 0;
}
//move vertically
y += vspd;