• 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!

Windows Hi I have problem withe the my player control

N

neryt

Guest

Hi I have problem withe the my player control. it is working but when i colide the wall and have
pressed
Key W & Key A or Key W & Key S or Key S & Key A or Key S & Key D . player stop moving and i need relase one key to move . in Wall object i only mark as SOLID . if i make in physics it is working but rest of my stuff in game after physics is ON not working corect . If any one now how to make his work i will be very glad :) // I don't want to making this game in physics setings . Game movment is like Binding of Isac

thanks in advance

if (!gamepad_is_connected(0)) {

/// player movment

if (keyboard_check(ord("W"))) { sprite_index = s_player_up_1; direction = 90; y -= global.move_speed ; }

if (keyboard_check(ord("S"))) { sprite_index = s_player_down_1; direction = 270;y += global.move_speed ; }

if (keyboard_check(ord("A"))) { sprite_index = s_player_left_poprawione_bf_1; direction = 180 ;x -= global.move_speed ; }

if (keyboard_check(ord("D"))) { sprite_index = s_player_right_1; direction = 270 ;x += global.move_speed ; }

if (keyboard_check(ord("W"))) and (keyboard_check(ord("A"))) { global.move_speed = 5 ; }
else if (keyboard_check(ord("W"))) and (keyboard_check(ord("D"))) { global.move_speed = 5 ; }
else if (keyboard_check(ord("S"))) and (keyboard_check(ord("A"))) { global.move_speed = 5 ; }
else if (keyboard_check(ord("S"))) and (keyboard_check(ord("D"))) { global.move_speed = 5 ; }


else {global.move_speed = 5 ;}

}
 

obscene

Member
Five things.

1. Ow, my eyes. Thanks for the colorful post but it's not necessary.
2. You don't need to check if a gamepad is connected before checking keyboard controls.
3. Checking keyboard controls is slow. You are checking each key 3 times in the same frame. That's 12 key checks to check 4 keys. That will slow your game down. Check a key, assign its value to a variable and then use that variable when you need to know if the key is pressed.
4. So no matter what.... pressing keys, not pressing keys, you set global.move_speed to 5. So the last 5 lines of your code are pointless.
5. If you press A and W at the same time, you are moving left by 5 and then right by 5 every frame (cancelling each other out). The question is what do you want to happen if you are pressing both keys? You COULD use an else statement (ie, if A else if W) which will make the first key dominant as W will not be checked if A is pressed.
 

rIKmAN

Member
Haven't got time to look at your code - I'm on my phone and the red text is hard to read against the background - but maybe this series will help you going forward with your game...

 
N

neryt

Guest
Five things.

1. Ow, my eyes. Thanks for the colorful post but it's not necessary.
2. You don't need to check if a gamepad is connected before checking keyboard controls.
3. Checking keyboard controls is slow. You are checking each key 3 times in the same frame. That's 12 key checks to check 4 keys. That will slow your game down. Check a key, assign its value to a variable and then use that variable when you need to know if the key is pressed.
4. So no matter what.... pressing keys, not pressing keys, you set global.move_speed to 5. So the last 5 lines of your code are pointless.
5. If you press A and W at the same time, you are moving left by 5 and then right by 5 every frame (cancelling each other out). The question is what do you want to happen if you are pressing both keys? You COULD use an else statement (ie, if A else if W) which will make the first key dominant as W will not be checked if A is pressed.

So the last 5 liines in code i used to get angle 45 so che walking for example up and rght = angle 45
 

obscene

Member
Maybe that's what you think you were doing, but that code sets global.move_speed to 5 and nothing else no matter what you're pressing. You can replace every single bit of that code with one line...

global.move_speed = 5;
 
N

neryt

Guest
Maybe that's what you think you were doing, but that code sets global.move_speed to 5 and nothing else no matter what you're pressing. You can replace every single bit of that code with one line...

global.move_speed = 5;

So now it is working almost correct but i can't walk in 45 degre angle
i read that

lengthdir_x(len,dir ) ;
lengthdir_y(len,dir ) ;

it is for this moovment but i don't now how tu set up




if (!gamepad_is_connected(0)) {

var up_key = keyboard_check(ord("W")) ;
var down_key = keyboard_check(ord("S")) ;
var left_key = keyboard_check(ord("A")) ;
var right_key =keyboard_check(ord("D")) ;
/// player movment

if (up_key) { sprite_index = s_player_up_1; direction = 90; y -= global.move_speed ; }

else if (down_key) { sprite_index = s_player_down_1; direction = 270;y += global.move_speed ; }

else if (left_key) { sprite_index = s_player_left_poprawione_bf_1; direction = 180 ;x -= global.move_speed ; }

else if (right_key) { sprite_index = s_player_right_1; direction = 270 ;x += global.move_speed ; }

}
 

obscene

Member
You only need to use else for your opposite directions.

Left else Right
Up else Down

Instead of...

Up else Down else Left else Right
 
N

neryt

Guest
Not working correct sill i think i need to add ths lengthdir_x(len,dir ) ;
lengthdir_y(len,dir ) ;
 
Top