Jump to content


Photo

firstRTS game..


  • Please log in to reply
3 replies to this topic

#1 SlipknLov

SlipknLov

    GMC Member

  • GMC Member
  • 236 posts
  • Version:GM8

Posted 27 February 2012 - 07:57 AM

First off, I've gone looking through a few RTS examples, they seem a bit too complicated for my level of experience.
My problems:
-> Gatherers (sometimes) get stuck in the resources when trying to go back to the base
-> Gatherers do not continue to next nearest resource when the current is finished

my [step] event for the Gatheres (objCitizen1)
//CLICKING ON ROCKS
if selected==1 then
{
 if mouse_check_button_pressed(mb_right) then
 { //gathering: 0=none 1=wood 2=food 3=rock
  if instance_place(mouse_x,mouse_y,objRock) then
   {
    i=instance_place(mouse_x,mouse_y,objRock);
    gathering=3;
   }
  else
   { if (!gathering==0) then {gathering=0}
    else
   {
    movepointx=mouse_x;
    movepointy=mouse_y;
    alarm[0]+=distance_to_point(movepointx,movepointy)+30;
    if movingtopoint==0 then
    { movingtopoint=1; }
   }
  }
 }
}

if movingtopoint=1 then
{ //MOVE TO MOUSE CLICK POINT
 mp_potential_step(movepointx,movepointy,1,false);
} 

if (gathering==3) then
 {
  if instance_exists(i) then
  {
    ib=instance_nearest(x,y,objBase);

   if rock>=rockmax then
    { mp_potential_step(ib.x,ib.y,1,false); } //go to resouce
   else
    { mp_potential_step(i.x,i.y,1,false); }   //return to base

  if (!movingtopoint==0) then { movingtopoint=0; }
   if 
   (   place_meeting(x+1,y  ,i) //left
    or place_meeting(x+1,y-1,i) //topleft
    or place_meeting(x  ,y-1,i) //top
    or place_meeting(x+1,y-1,i) //topright
    or place_meeting(x-1,y  ,i) //right
    or place_meeting(x+1,y+1,i) //bottomright
    or place_meeting(x  ,y+1,i) //bottom
    or place_meeting(x-1,y+1,i) //bottomleft
   ) then
 {
  x=xprevious; y=yprevious;
  if gatherable=1 then
  {
   alarm[1]=rocktime;
   gatherable=0;
   
   if rock<rockmax
   {
    rock+=1;
    if i.rock>0 then
   { i.rock-=1 } else { i=instance_nearest(x,y,objRock); }
   }
  }
 }
}
} 
 if 
   (   place_meeting(x+1,y  ,objBase) //left
    or place_meeting(x+1,y-1,objBase) //topleft
    or place_meeting(x  ,y-1,objBase) //top
    or place_meeting(x+1,y-1,objBase) //topright
    or place_meeting(x-1,y  ,objBase) //right
    or place_meeting(x+1,y+1,objBase) //bottomright
    or place_meeting(x  ,y+1,objBase) //bottom
    or place_meeting(x-1,y+1,objBase) //bottomleft
   ) then
 {
  if rock>=0 then
  {
   global.rock+=rock;
   rock=0;
  }
}
Any available help is appreciated.

Edited by SlipknLov, 05 March 2012 - 03:01 AM.

  • 0

#2 SlipknLov

SlipknLov

    GMC Member

  • GMC Member
  • 236 posts
  • Version:GM8

Posted 29 February 2012 - 10:56 PM

*BUMP*
I'm hoping someone can also help me make my units build buildings.
I don't know where i would start for that..
  • 0

#3 SlipknLov

SlipknLov

    GMC Member

  • GMC Member
  • 236 posts
  • Version:GM8

Posted 05 March 2012 - 03:00 AM

bump
  • 0

#4 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2295 posts
  • Version:GM7

Posted 05 March 2012 - 07:29 AM

As for getting stuck in resources, I'd perhaps just make the gatherer stop right before the resource and do his mining animation? (use masks so it looks like he's mining on the rock without actually colliding in code with it, use distance_to_object to check if you're close enough to stop). I wouldn't get too complicated with collision checking for an RTS in game maker as you have very little processing power to work with. Ideally all those large place_meeting blocks would be replaced each with a single distance_to_object each.

As for not going to the next rock, after it's finished, that's because you do not add this again after changing i to the nearest rock:

movepointx=mouse_x;
movepointy=mouse_y;
alarm[0]+=distance_to_point(movepointx,movepointy)+30;
if movingtopoint==0 then { movingtopoint=1; }

Lastly, I would use "gathering != 0" to check the variable rather than "!gathering ==0" as the latter doesn't mean quite what you think it means and just coincidentally works.

Edited by greep, 05 March 2012 - 07:39 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users