T
TomKai
Guest
Hi everybody, I need some help !
The game I'm working on is a grid based tactical rpg, and even if I'm managing the rpg part well enough I have some trouble figuring out the tactical movement part.
Here a quick summary of what I'm looking to do :
- When you select a unit, every square in it's movement range gets highlighted.
- You can then click on one of these squares to move to it, without diagonals
- You should not be able to go to a square inside of your range if the path to get there is longer than your range
- When you move, "movement points" are used and your range shortens
To accomplish this I created a ds_grid and stored every wall inside. Then I call this script when my unit is selected :
The ds_gird this returns is then used to display where I can move using squares and to allow movement using mp_ functions. And here's the result with a range of 3 cells :
Could someone help me with this mess ? Please ?
The game I'm working on is a grid based tactical rpg, and even if I'm managing the rpg part well enough I have some trouble figuring out the tactical movement part.
Here a quick summary of what I'm looking to do :
- When you select a unit, every square in it's movement range gets highlighted.
- You can then click on one of these squares to move to it, without diagonals
- You should not be able to go to a square inside of your range if the path to get there is longer than your range
- When you move, "movement points" are used and your range shortens
To accomplish this I created a ds_grid and stored every wall inside. Then I call this script when my unit is selected :
Code:
// Script Movement_grid
// Takes an origin (x,y) on the grid and a movement range, an returns a movement grid
var x_origin = argument0; // Position on the grid
var y_origin = argument1;
var range = argument2; // Remaining movement points
var mo_grid = ds_grid_create(2*range+1,2*range+1);
var xx, yy, xo, yo;
for(var i = 0; i < 2*range+1; i++)
{
for(var j = 0; j < 2*range+1; j++)
{
xx = (x_origin - range + i) * global.cell_size;
yy = (y_origin - range + j) * global.cell_size;
xo = x_origin * global.cell_size;
yo = y_origin * global.cell_size;
if(mp_grid_path(o_master.map_grid,o_master.map_navigate,xo,yo,xx,yy,false))
{
mp_grid_path(o_master.map_grid,o_master.map_navigate,xo,yo,xx,yy,false);
if( path_get_length(o_master.map_navigate) <= (range * global.cell_size)+1 )
{
mo_grid[# i,j] = true;
}
}
else
{
mo_grid[# i,j] = false;
}
}
}
return mo_grid;
ds_grid_destroy(mo_grid);
Could someone help me with this mess ? Please ?