arcade game -problem

Started by Andrechan, Sun 27/08/2006 17:07:37

Previous topic - Next topic

Andrechan

Hi!
I'm making a classic game where you have to shoot at characters and make points.
This is the code in the repeatedly execute of the room
Code: ags


int i =0;
while(i<=19)
 { 
if((character[i].Room==1) &&(character[i].Moving==0))
{ 

character[i].x= Random(320);
character[i].y= Random(150)+50;

character[i].Walk(character[i].x+ Random(40)-Random(40),character[i].y+ Random(40)-Random(40),eNoBlock,eWalkableAreas);

}

i++;
}

characters appear at a random point of the screen, walk for a while and then disappear.
If you click on one of it then it runs the kill animation, it disappear and the score is updated.
The problem is:
with this code all the 20 characters are on the screen but my idea is that we start with say 5 characters and then they appear more and more with the passage of time. You have to kill them. If there are more than X characters on the screen then you loose.
How can I code it?
Also with my coding if you kill a character then it reappears immediately in another point of the screen so killing is all time wasted  :(


Ashen

#1
One way would be to use Timers.
Have the initial five or so characters you want start in the room, and have the others brought in on timers. When a charcter is shot, take them out of the room and reset their timer (by a freakish coincidence, you have 20 characters, and there are 20 Timers...).
Add a bit to rep_ex that checks the Timer and brings them back e.g. (untested):

Code: ags

int i =0;
while(i<=19) {
  if ((character[i].Room==1) && (character[i].Moving==0)) {// Char is in room, but not moving, so make them move
    character[i].Walk(character[i].x+ Random(40)-Random(40),character[i].y+ Random(40)-Random(40),eNoBlock,eWalkableAreas);
  }
  else if (character[i].Room != 1) { // Character is not in room
    if (IsTimerExpired(i)) {
      character[i].ChangeRoom(1, Random(320), Random(150)+50);
    }
  }
  i++;
}

EDIT:
You might have to use IsTimerExpired(i+1) - Timer indexes run 1 - 20 , not 0 - 19 as I thought.

You can also add another variable that gets updated if the character is in the room, e.g. (again, untested):

Code: ags

function GetChars() { // Call this in rep_ex, or combine it with the existing code there
  int ii, n;
  while (ii < 20) {
    if (character[ii].Room == 1) n++;
    ii++;
  }
  if (n > 15) { // or whatever value you want
    // Do 'Losing' stuff
  }
}

I know what you're thinking ... Don't think that.

Andrechan

Thanks a lot Ashen  :) I'll try it.

SMF spam blocked by CleanTalk