S
Samus
Guest
Hello, so I'm working on a cool new game with online networking. I use DS_Grids to keep track of where the players and other objects in the game are and what their status is, things like that. So when it comes to simulating collisions between the different objects, I would loop through the DS_Grid for that kind of object and for the other kind of object involved, and plug whatever those values are into
or something like that to find out whether they have/will collide or not. That works great, but when there are a lot of different objects in the game and I'm checking for collisions with all of them, its going to get really cluttered. So I decided to make a script I could use over and over again for the various ds_grids involved:
The idea is that I can input the names of the two different grids and it will modify them. But as it turns out, it actually copies the grid into the variable I have inside the script, modifies that one, and leaves the original untouched. I have a workaround in mind, but its so complex I might as well not have the script. I figure there is a special function/command meant just for this that I just don't know about. Thanks to anyone who replies!
Code:
point_in_circle(yadayadayada)
Code:
///server_collision(grid1, grid2, xpos1, ypos1, xpos2, ypos2, i)
var grid1, grid2, xpos1, ypos1, xpos2, ypos2, i;
grid1 = argument[0];
grid2 = argument[1];
xpos1 = argument[2];
ypos1 = argument[3];
xpos2 = argument[4];
ypos2 = argument[5];
i = argument[6];
//Go through every item in the grid and check for collisions.
for(var j = 0; j < ds_grid_height(grid2); j ++;)
{
if(ds_grid_height(grid1) > i)
{
if(ds_grid_get(grid2, xpos2, i) != ds_grid_get(grid1, xpos1, j))
{
if(point_in_circle(ds_grid_get(grid2, xpos2, i), ds_grid_get(grid2, ypos2, i), ds_grid_get(grid1, xpos1, j), ds_grid_get(grid1, ypos1, j), 16))
{
if(ds_grid_height(grid2) > 1) ds_grid_delete_row(grid2, i);
else
{
ds_grid_destroy(grid2)
(grid2) = ds_grid_create(6, 0);
}
ds_grid_add(grid1, 8, j, -2);
}
}
}
}