RTS thing

F

frozenwisp

Guest
Ok so I need help with setting up markers for my units to go to.
when my units are selected and you right click your units move to there own invisible marker I want the markers when spawned to separate so my idea is. How do i get each marker to move left right up or down based on it positions and instance order.

Here is a picture of what I mean:


So the red marker is where I right clicked and the blue makers move to those positions based on the where the other markers are set understand that all the marker are the same object red is the same as blue the only different would be the ids or the instance order they where created in so my question is how would I go about separating them. I have a way to lock them on the grid I just need to know how to move them 32 pixels based on the order of the instances being created so that it can be speared one at a time.

Here is a in game shot:
 
B

bojack29

Guest
You could simply do loop until you have filled all the spots in a circlular check.
Code:
var a, b, c, mx, my, xx, yy;

mx = markerX;
my = markerY;

grid[# mx / 32, my / 32] = 1;//Filled

a = numOfSpotsToFill;
b = 0;//Angle
c = 1;//Length

do{
     xx = mx + lengthdir_x(c, b);
     yy = my + lengthdir_y(c, b);
     b += 45;
     if (b mod 360 == 0){
          c ++;
     }
     if (grid[# xx / 32, yy / 32] == 0){
          grid[# xx / 32, yy / 32] = 1;
          a --;
     }
}
until(a == 0);
I did something like this very similar in an RTS build I had managed.
 
Last edited by a moderator:
M

MaiNaym

Guest
You could simply do loop until you have filled all the spots in a circlular check.
Code:
var a, b, c, mx, my, xx, yy;

mx = markerX;
my = markerY;

grid[# mx / 32, my / 32] = 1;//Filled

a = numOfSpotsToFill;
b = 0;//Angle
c = 1;//Length

do{
     xx = mx + lengthdir_x(c, b);
     yy = my + lengthdir_y(c, b);
     b += 45;
     if (b mod 360 == 0){
          c ++;
     }
     if (grid[# xx / 32, yy / 32] == 0){
          grid[# xx / 32, yy / 32] = 1;
          a --;
     }
}
until(a == 0);
I did something like this very similar in an RTS build I had managed.
Hey Bojack, hope a year later is not too late to ask this!
Could you explain a little more about this grid method? Quite a bit of people are linking to this, and many others see it and are stumped.
It seems very clever and as if it would work exactly as people with an RTS in mind would like it to, but there are a few things that confuse some people a bit (most notably how you're creating this grid using "grid[# mx / 32, my / 32] = 1;". Can you give us some insight?
 
E

elementbound

Guest
The part of code you quoted does not create the grid. It just sets a cell in an already existing grid, to indicate that the spot you start from is filled already, and then you make circles around it.
Or, if you mean, how to create the grid, it's your levels dimensions divided by 32 ( that's why the mx/32, my/32 part ). It means that your cells are 32x32 in size.
 
B

bojack29

Guest
First off. I am looking at this code in retrospect to what I did perhaps a few years ago. And second I am not sure exactly if I used this particular area of code in the RTS build I made when I did something like this. For all I know this code may not even work as intended.

It seems whats going on is that cells are being filled in a sort of flower arrangement going clockwise in circular fashion. The 'b' variable could change to a smaller increment but that would be more costly cpu wise. I believe what Ivam attempting to do here is make a circular area filled with the value of '1'. Which could likely be much easier with the function ds_grid_fill_circle (or whatever the equivalent is) to do the exact same thing more efficiently.
 
Top