MaxCampbell
Member
Hello, I'm a brand new programmer who's been doing his best to learn the basics of code logic to make my platformer game. I've already got basic movement implemented, but am having trouble figuring out how to instantly stop movement/acceleration in one direction when both arrow keys are being pressed at the same time. Additionally, I'm unable to get the "right" movement to override the "left" (just the other way around). Could anyone help me with these issues? Currently, the final "do" statement is intended to stop movement while both movement keys are pressed but I apparently haven't resolved it correctly and it crashes my project.
Here's the relevant code:
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);
hsp = 0;
vsp = 0;
grv = 0.4;
aSpeed = 0.3;
dSpeed = 0.9;
mSpeed = 6;
Step:
if(key_left){
hsp = Approach(hsp,-mSpeed,aSpeed);
}else if(key_right){
hsp = Approach(hsp,mSpeed,aSpeed);
}else{
hsp = Approach(hsp,0,dSpeed);
}
if(key_left)&&(key_right){
do {mSpeed = 0
}
until(key_left)&&(!key_right)||(key_right)&&(!key_left)
}
I'm almost positive it could also be more optimized so I'm open to constructive criticism. I'm very untrained but eager to learn.
Thanks!
Here's the relevant code:
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);
hsp = 0;
vsp = 0;
grv = 0.4;
aSpeed = 0.3;
dSpeed = 0.9;
mSpeed = 6;
Step:
if(key_left){
hsp = Approach(hsp,-mSpeed,aSpeed);
}else if(key_right){
hsp = Approach(hsp,mSpeed,aSpeed);
}else{
hsp = Approach(hsp,0,dSpeed);
}
if(key_left)&&(key_right){
do {mSpeed = 0
}
until(key_left)&&(!key_right)||(key_right)&&(!key_left)
}
I'm almost positive it could also be more optimized so I'm open to constructive criticism. I'm very untrained but eager to learn.
Thanks!
Last edited: