I
its_Johnny
Guest
hi everyone,
My name is Johnny, its the first time I write on this forum.
I'm experiencing some problems on my game code and I hope that someone can help me:
since I coded the animations, my character does not move if the key arrows are pressed, while it moves only using space bar (it jumps and it can move left-right only during the jump, when it touches the floor it can't)
in addiction its sprite does not change its orientation altho it should (it always faces the same direction, altho it should face left while the left arrow key is pressed).
can you help me please? I'm supposed to finish this videogame for January to go to the university I want and I would really appreciate some help!
i include my code in case you need it, I'm pretty sure the problem is on the "animation" section (at the end) because if I delete it, the game just works fine; any help? thank you so so so much!
//get player imput
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_space);
//calculate movemet
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x,y+1,O_wall)) && (key_jump)
{
vsp = -7;
}
//horizontal collision
if (place_meeting(x+hsp,y,O_wall))
{
while (!place_meeting(x+sign(hsp),y,O_wall))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//vertical collision
if (place_meeting(x,y+vsp,O_wall))
{
while (!place_meeting(x,y+sign(vsp),O_wall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
//Animation
if (!place_meeting(x,y+1,O_wall))
{
sprite_index = S_playerA;
image_speed = 0;
if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
image_speed = 1;
if (hsp == 0)
{
sprite_index = S_player;
}
else
{
sprite_index = S_player_run
}
}
if (hsp != 0) image_xscale = sign(hsp);
image_xscale = 0.1;
My name is Johnny, its the first time I write on this forum.
I'm experiencing some problems on my game code and I hope that someone can help me:
since I coded the animations, my character does not move if the key arrows are pressed, while it moves only using space bar (it jumps and it can move left-right only during the jump, when it touches the floor it can't)
in addiction its sprite does not change its orientation altho it should (it always faces the same direction, altho it should face left while the left arrow key is pressed).
can you help me please? I'm supposed to finish this videogame for January to go to the university I want and I would really appreciate some help!
i include my code in case you need it, I'm pretty sure the problem is on the "animation" section (at the end) because if I delete it, the game just works fine; any help? thank you so so so much!
//get player imput
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_space);
//calculate movemet
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x,y+1,O_wall)) && (key_jump)
{
vsp = -7;
}
//horizontal collision
if (place_meeting(x+hsp,y,O_wall))
{
while (!place_meeting(x+sign(hsp),y,O_wall))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//vertical collision
if (place_meeting(x,y+vsp,O_wall))
{
while (!place_meeting(x,y+sign(vsp),O_wall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
//Animation
if (!place_meeting(x,y+1,O_wall))
{
sprite_index = S_playerA;
image_speed = 0;
if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
image_speed = 1;
if (hsp == 0)
{
sprite_index = S_player;
}
else
{
sprite_index = S_player_run
}
}
if (hsp != 0) image_xscale = sign(hsp);
image_xscale = 0.1;