• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

RTS help. Troops movement

S

samyak

Guest
Unlike a typical RTS, I want to move a troop from point 1 - point 2 - point 3- point 4 - ... - point n without the interference of the player when the troop starts moving. Conditions.

1. The player can direct the troops only once (when the game is paused). He can set up waypoints-> point 1, point 2, point 3, etc only once at a time. He can again create a new set of points when he pauses the game again.

2. There can be multiple troops of same type and multiple troops of various types.
 

Slyddar

Member
Maybe have a look at the ds_queue functions. You could add waypoints to it, and they could be just read in the order they were added. They then get removed from the queue when the object has moved to the target, and the next set of coordinates would get processed.
 
S

samyak

Guest
Maybe have a look at the ds_queue functions. You could add waypoints to it, and they could be just read in the order they were added. They then get removed from the queue when the object has moved to the target, and the next set of coordinates would get processed.
I used this. But the movement is not what I expect. I created 2 queues , one for X coordinates and one for Y coordinates..

if Troop_selected= 1 and o_cursor.clickleft and !place_meeting(x,y,o_cursor)
{
ds_queue_enqueue(moveorderX,o_cursor.x);
ds_queue_enqueue(moveorderY,o_cursor.y);

}

if !ds_queue_empty(moveorderX) and !ds_queue_empty(moveorderY)
{



if point_distance(x,y,ds_queue_head(moveorderX), ds_queue_head(moveorderY))<=30
{

xx = ds_queue_dequeue(moveorderX);
yy = ds_queue_dequeue(moveorderY);

}
move_towards_point(xx, yy, spd);
}
y

// EDIT 1: Just add
xx= ds_queue_head(moveorderX);
yy= ds_queue_head(moveorderY);

It will work.

edit 2: Found problem when there are two instances of 1 object
 
Last edited by a moderator:

Smiechu

Member
You can nest arrays in single ds_queue... you don't have to create separate ds for every parameter...
 
S

samyak

Guest
Just store the next target in the object as a variable, say targetx and targety. That way you only need 1 queue.
I don't think that can happen easily, because I am giving input of multiple coordinates before the object starts moving
 
Code:
list = ds_list_create();
list[| 0] = 10;
list[| 1] = 20;
list[| 2] = 13;
list[| 3] = 23;

var xx = list[| 0];
var yy = list[| 1];
if (point_distance(x,y,xx,yy) < 5) {
  repeat(2) {
     ds_list_delete(list,0);
  }
}
This is just one of many methods to store multiple coordinates in a single list. Another would be to store an array in each list position:
Code:
list[| 0] = [10,20];
list[| 1] = [13,23];

var pos_array = list[| 0];
var xx = pos_array[0];
var yy = pos_array[1];
if (point_distance(x,y,xx,yy) < 5) {
   ds_list_delete(list,0);
}
There's other methods as well, but it's relatively simple to do this. You don't even have to worry about a queue.
 
S

samyak

Guest
Code:
list = ds_list_create();
list[| 0] = 10;
list[| 1] = 20;
list[| 2] = 13;
list[| 3] = 23;

var xx = list[| 0];
var yy = list[| 1];
if (point_distance(x,y,xx,yy) < 5) {
  repeat(2) {
     ds_list_delete(list,0);
  }
}
This is just one of many methods to store multiple coordinates in a single list. Another would be to store an array in each list position:
Code:
list[| 0] = [10,20];
list[| 1] = [13,23];

var pos_array = list[| 0];
var xx = pos_array[0];
var yy = pos_array[1];
if (point_distance(x,y,xx,yy) < 5) {
   ds_list_delete(list,0);
}
There's other methods as well, but it's relatively simple to do this. You don't even have to worry about a queue.
I did it with the queue I had missed to store a value. I realized that when I woke up today. Earlier the object as only going to (0,0) But thanks, I got an alternate way.
 
S

samyak

Guest
Code:
list = ds_list_create();
list[| 0] = 10;
list[| 1] = 20;
list[| 2] = 13;
list[| 3] = 23;

var xx = list[| 0];
var yy = list[| 1];
if (point_distance(x,y,xx,yy) < 5) {
  repeat(2) {
     ds_list_delete(list,0);
  }
}
This is just one of many methods to store multiple coordinates in a single list. Another would be to store an array in each list position:
Code:
list[| 0] = [10,20];
list[| 1] = [13,23];

var pos_array = list[| 0];
var xx = pos_array[0];
var yy = pos_array[1];
if (point_distance(x,y,xx,yy) < 5) {
   ds_list_delete(list,0);
}
There's other methods as well, but it's relatively simple to do this. You don't even have to worry about a queue.
Does it work perfectly if I have two instances of the same object in one room?
 
S

samyak

Guest
Maybe have a look at the ds_queue functions. You could add waypoints to it, and they could be just read in the order they were added. They then get removed from the queue when the object has moved to the target, and the next set of coordinates would get processed.
Does it work perfectly if I have two instances of the same object in one room? I am finding it trouble some. If there are two instances, after the queue of one instance is empty, the other instance seems to follow the coordinates of the 1st instance
 
Each instance needs its own queue, it's not a global queue. Search for frostycats explanation on instances vs objects if you're confused.
 
Depends on how your game works. If you're going instance by instance you can just store the instance ID's of each instance you want to control in a list or a queue and then pop through as you give them command. Parenting might help here.
 
S

samyak

Guest
Depends on how your game works. If you're going instance by instance you can just store the instance ID's of each instance you want to control in a list or a queue and then pop through as you give them command. Parenting might help here.
1. I have to select one instance, then assign it waypoints,
2. Next, I select another instance of the same object (in the same turn) and assign it waypoints.
3. When pressed ENTER, both of them should start moving together.
 
S

samyak

Guest
Depends on how your game works. If you're going instance by instance you can just store the instance ID's of each instance you want to control in a list or a queue and then pop through as you give them command. Parenting might help here.
Instead of using two instances of same object, I even did this- I duplicated the object, and gave each of them a new queue for coordinates. Still, the same problem persists. Now I'm puzzled.

EDIT: It seems like when I select the second instance, the coordinates of second instance gets added to the queue of first instance
 
Last edited by a moderator:
Top