B
Blakester
Guest
Hello all!
Thank you for taking the time to read this.
What I'm trying to do is get the effect of an old school roguelike's turn based grid movement. Where I've hit a stumbling block, though, is that one of the NPCs that follows the player is moving one tile at a time (which is great!), but they move diagonally when I want all the moving objects to only move in 4-directions on the grid.
The way it works is that on each "turn" the player is given 3 Action Points (APs) and each tile he moves spends 1 AP. When they are out of APs, the NPC's turn starts and they are given 1 AP and this loops.
That said, I suppose moving diagonally might be fine (the way I have it worked out is that they just snap to their target location, like in old roguelikes), but they need to lose AP accordingly. If they move diagonally they shouldn't lose one AP; they should lose 2 APs.
Here's the code for the obj_Enemy:
Create Event-
Step Event-
I've tried using mp_grid_path, but I still can't find a way to track how many APs are spent on each tile; the obj_Enemy just goes immediately on top of the obj_Player. I'm open to any suggestions on pathfinding though, I'm just not too savvy on pathfinding so I'm probably doing it wrong, to be honest. My best results so far are on the code above though.
Thank you in advance, any help would be greatly appreciated!
-Blake
Thank you for taking the time to read this.
What I'm trying to do is get the effect of an old school roguelike's turn based grid movement. Where I've hit a stumbling block, though, is that one of the NPCs that follows the player is moving one tile at a time (which is great!), but they move diagonally when I want all the moving objects to only move in 4-directions on the grid.
The way it works is that on each "turn" the player is given 3 Action Points (APs) and each tile he moves spends 1 AP. When they are out of APs, the NPC's turn starts and they are given 1 AP and this loops.
That said, I suppose moving diagonally might be fine (the way I have it worked out is that they just snap to their target location, like in old roguelikes), but they need to lose AP accordingly. If they move diagonally they shouldn't lose one AP; they should lose 2 APs.
Here's the code for the obj_Enemy:
Create Event-
Code:
//Init Variables
ap = 0; //Don't start on Object's Turn
Code:
///Update
//Variables
ts = 10; //Tile Size
tx = obj_Player.x; //Target X
ty = obj_Player.y; //Target Y
//Movement
if !ap == 0
{
if place_empty(x + sign(tx-x)*ts,y + sign(ty-y)*ts)
{
x = x + sign(tx-x)*ts
y = y + sign(ty-y)*ts
}
ap -= 1;
if (ap == 0 && global.player_ap == 0)
{
global.player_ap = 3;
}
}
Thank you in advance, any help would be greatly appreciated!
-Blake