noorsalim
Member
I'm making a Turn-Based Strategy (TBS for short) game and want to use ds_grid to store data of the grid and manipulate it later.
Here is the basic code to create the grid and populate it with oNode objects:
Reading the manual, I know that there are built-in functions that allow us to get and set a circular radius of the grid data, as demonstrated in the image below:
What I want to achieve is, with my code above, to change the color of my oNode objects (stored in an array variable) to different color by utilizing this built-in disk shaped grid creation? Let's say I want to put this in global left mouse event, for the sake of discussion. So whenever the player tap left mouse button, the specified oNode objects will change it's color to yellow (currently it's white, see image below)
Here is how my game room looks like:
the white rectangle is the oNode object. This image below is what I (roughly) want to achieve for the moment:
Let me know if any of you guys need further explanation of my project to help answering my question!
--------------------------------------------------------------------------------------------------------------------------------------------------------
UPDATE 21 APR 2020 [SOLVED]
For the sake of you who may have the same problem, I've finally resolved this issue! Thanks to all of you replying to my post, really helpful!
Here is the screenshot of what I've achieved (actual one, not an edited image!):
Here is the code that I use in the Create event:
Here is the code that I use in the draw event:
Here is the basic code to create the grid and populate it with oNode objects:
GML:
///@desc Create the grid
global.grid = ds_grid_create(room_width/GRID_SIZE, room_height/GRID_SIZE);
global.map = undefined;
//create global.map objects, positioned neatly within the grid------------------------------------------
for(xx = 0; xx < ds_grid_width(global.grid); xx += 1){
for(yy = 0; yy < ds_grid_height(global.grid); yy += 1){
global.map[xx, yy] = instance_create_depth(xx * GRID_SIZE, yy * GRID_SIZE, 3, oNode);
global.map[xx, yy].gridX = xx; //store and set global.map instance's x position
global.map[xx, yy].gridY = yy; //store and set global.map instance's x position
}
}
What I want to achieve is, with my code above, to change the color of my oNode objects (stored in an array variable) to different color by utilizing this built-in disk shaped grid creation? Let's say I want to put this in global left mouse event, for the sake of discussion. So whenever the player tap left mouse button, the specified oNode objects will change it's color to yellow (currently it's white, see image below)
Here is how my game room looks like:
the white rectangle is the oNode object. This image below is what I (roughly) want to achieve for the moment:
Let me know if any of you guys need further explanation of my project to help answering my question!
--------------------------------------------------------------------------------------------------------------------------------------------------------
UPDATE 21 APR 2020 [SOLVED]
For the sake of you who may have the same problem, I've finally resolved this issue! Thanks to all of you replying to my post, really helpful!
Here is the screenshot of what I've achieved (actual one, not an edited image!):
Here is the code that I use in the Create event:
Code:
///@desc Set the grid
global.grid = ds_grid_create(room_width/GRID_SIZE, room_height/GRID_SIZE);
ds_grid_clear(global.grid, 0); //set all grid value to zero
//set disk value to 5
ds_grid_set_disk(global.grid, 10, 10, 3, 5);
GML:
for(xx = 0; xx < ds_grid_width(global.grid); xx += 1){
for(yy = 0; yy < ds_grid_height(global.grid); yy += 1){
//set color and draw rectangle with specified outline color
draw_set_colour(c_yellow);
draw_rectangle(xx * GRID_SIZE, yy * GRID_SIZE, (xx + 1) * GRID_SIZE, (yy + 1) * GRID_SIZE, true);
//draw disk with green color
if(global.grid[# xx,yy] == 5){
draw_set_colour(c_lime);
draw_rectangle(xx * GRID_SIZE, yy * GRID_SIZE, (xx + 1) * GRID_SIZE, (yy + 1) * GRID_SIZE, false);
}
}
}
Last edited: