• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

player not working

Y

Yvalson

Guest
if keyboard_check_pressed(vk_left && !vk_shift)
{
//hspeed = -5
sprite_index = Spr_Player_Walk
image_xscale = 1
}

else if keyboard_check_pressed(vk_left && vk_shift)
{
//hspeed = -8
sprite_index = Spr_Player_Run
image_xscale = 1
}

else if keyboard_check_pressed(vk_right && !vk_shift)
{
//hspeed = 5
sprite_index = Spr_Player_Walk
image_xscale = -1
}

else if keyboard_check_pressed(vk_right && vk_shift)
{
//hspeed = 8
sprite_index = Spr_Player_Run
image_xscale = -1
}

else if keyboard_check_pressed(vk_nokey)
{
//hspeed = 0
sprite_index = Spr_Player_Idle
image_xscale = 1
}

that's my code my player doesn't turn when pressing the right arrow key and also walks when pressing no key and
starts running when pressing left or right (standard sprite is Idle)
what's wrong
 
D

Deanaro

Guest
EDIT: fixed typo thank you Yvalson
the hspeed is in comments.
although this code repeats things unnecessarily.
You are checking for each possible scenario of input combinations when you can simply check each key separately and then do some calculations.
here is a simple way to do this:
Code:
//inputs
left = -keyboard_check_pressed(vk_left);
right = keyboard_check_pressed(vk_right);
sprint = keyboard_check_pressed(vk_shift);
//add left and right to get
move = left + right;
//calculate the hspeed
hspeed = move *(5 + sprint * 3);
//animation handler:
//first of we find out which speed the player is with a switch statement
switch abs(hspeed)
{
case 0:
     sprite_index = Spr_Player_Idle;
     break;
case 5:
     sprite_index = Spr_Player_Walk;
     break;
case 8:
     sprite_index = Spr_Player_Run;
     break;
}
//now we want to check which direction we are facing so we can use a switch statement once again
switch move
{
case -1:
     image_xscale =-1;
     break;
case 1:
     image_xscale = 1;
     break;
}
 
Last edited by a moderator:
Y

Yvalson

Guest
the hspeed is in comments.
although this code repeats things unnecessarily.
You are checking for each possible scenario of input combinations when you can simply check each key separately and then do some calculations.
here is a simple way to do this:
Code:
//inputs
left = -keyboard_check_pressed(vk_left);
right = keyboard_check_pressed(vk_right);
sprint = keyboard_check_pressed(vk_shift);
//add left and right to get
move = left + right;
//calculate the hspeed
hspeed = move *(5 + sprint * 3);
//animation handler:
//first of we find out which speed the player is with a switch statement
switch abs(hspeed)
{
case 0:
     sprite_index = Spr_Player_Idle;
     break;
case 5:
     sprite_index = Spr_Player_Walk;
     break;
case 8:
     sprite_index = Spr_Player_Run;
     break;
}
//now we want to check which direction we are facing so we can use a switch statement once again
switch move
{
case -1:
     image_xscale =-1;
     break;
case 1:
     image_xcale = 1;
     break;
}
thanks man I understand what you did gonna try it out right now
 
Y

Yvalson

Guest
the hspeed is in comments.
although this code repeats things unnecessarily.
You are checking for each possible scenario of input combinations when you can simply check each key separately and then do some calculations.
here is a simple way to do this:
Code:
//inputs
left = -keyboard_check_pressed(vk_left);
right = keyboard_check_pressed(vk_right);
sprint = keyboard_check_pressed(vk_shift);
//add left and right to get
move = left + right;
//calculate the hspeed
hspeed = move *(5 + sprint * 3);
//animation handler:
//first of we find out which speed the player is with a switch statement
switch abs(hspeed)
{
case 0:
     sprite_index = Spr_Player_Idle;
     break;
case 5:
     sprite_index = Spr_Player_Walk;
     break;
case 8:
     sprite_index = Spr_Player_Run;
     break;
}
//now we want to check which direction we are facing so we can use a switch statement once again
switch move
{
case -1:
     image_xscale =-1;
     break;
case 1:
     image_xcale = 1;
     break;
}
in case 1 from the direction facing part of the script image_xscale is wrong spelled for anyone reading this the script works but change it so it's spelled right
 
Top