M
Merrick
Guest
Hi folks,
Having a problem with creating an object that will move a set distance (one 32x32 space, no diagonals) then stop (like in most rogue-like games).
Here's the code I've been playing with(which isn't working, the object just keeps moving up when the key is pressed and doesn't stop). Clearly I'm not seeing something here:
if keyboard_check(vk_up)
{
if place_empty(x,y-32)
{
goal_y = y-32;
vspeed = -4;
if y = goal_y
{
vspeed = 0;
}
}
}
I've managed to achieve my goal using different code, but I found it difficult to implement into a turn-based rogue-like game. Here's the alternate code that I abandoned. Maybe some of you will see a way to make this work in a turn based rogue-like game. I sure couldn't.
if place_snapped(32,32) && vspeed = 0
{
hspeed = keyboard_check(vk_right)*4 -keyboard_check(vk_left)*4;
dx = lengthdir_x(speed,direction);
if (place_meeting(x+dx,y,obj_wall)) {speed = 0}
}
if place_snapped(32,32) && hspeed = 0
{
vspeed = keyboard_check(vk_down)*4 -keyboard_check(vk_up)*4;
dy = lengthdir_y(speed,direction);
if (place_meeting(x,y+dy,obj_wall)) {speed = 0}
if (vspeed != 0){global.step += 1;}
}
If anyone knows what I'm missing/doing wrong, particularly in that first set of code, I would greatly appreciated the help.
Cheers,
PS: Alternatively, I can successfully create rogue-like movement where the object just jumps to the next spot, but I'm aiming to make movement animations this time around, so that unfortunately isn't an option anymore.
Having a problem with creating an object that will move a set distance (one 32x32 space, no diagonals) then stop (like in most rogue-like games).
Here's the code I've been playing with(which isn't working, the object just keeps moving up when the key is pressed and doesn't stop). Clearly I'm not seeing something here:
if keyboard_check(vk_up)
{
if place_empty(x,y-32)
{
goal_y = y-32;
vspeed = -4;
if y = goal_y
{
vspeed = 0;
}
}
}
I've managed to achieve my goal using different code, but I found it difficult to implement into a turn-based rogue-like game. Here's the alternate code that I abandoned. Maybe some of you will see a way to make this work in a turn based rogue-like game. I sure couldn't.
if place_snapped(32,32) && vspeed = 0
{
hspeed = keyboard_check(vk_right)*4 -keyboard_check(vk_left)*4;
dx = lengthdir_x(speed,direction);
if (place_meeting(x+dx,y,obj_wall)) {speed = 0}
}
if place_snapped(32,32) && hspeed = 0
{
vspeed = keyboard_check(vk_down)*4 -keyboard_check(vk_up)*4;
dy = lengthdir_y(speed,direction);
if (place_meeting(x,y+dy,obj_wall)) {speed = 0}
if (vspeed != 0){global.step += 1;}
}
If anyone knows what I'm missing/doing wrong, particularly in that first set of code, I would greatly appreciated the help.
Cheers,
PS: Alternatively, I can successfully create rogue-like movement where the object just jumps to the next spot, but I'm aiming to make movement animations this time around, so that unfortunately isn't an option anymore.