Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: R4L on Sun 27/03/2005 00:57:08

Title: AGS Shoot em' up problem
Post by: R4L on Sun 27/03/2005 00:57:08
Im currently making an AGS shoot em up. (Sorry, no screenies yet). So far, I have the current point values for certain targets and a timer that tells how much time you have left. The only prolem I have is managing ammo. How can I manage ammo? (Max bullets 10) Any help appreciated. Thanks!
Title: Re: AGS Shoot em' up problem
Post by: Ishmael on Sun 27/03/2005 02:00:16
GetGlobalInt
SetGlobalint

in the holy Manual, for starts. ;)
Title: Re: AGS Shoot em' up problem
Post by: R4L on Sun 27/03/2005 02:21:50
But if I set a global int, what can I do to handle if the player clicks again to shoot? I had some thoughts, but I am not sure if it would work.
Title: Re: AGS Shoot em' up problem
Post by: Ashen on Sun 27/03/2005 04:02:31
I think you could use:
GlobalInt 1 to store the amount of ammo the player has in their 'clip', e.g.:

SetGlobalInt (1, 10);

To set the amount in the 'clip' to start, or to reset it on reload. Then, when the player fires:

//on Fire (maybe in on_mouse_click?)
if (GetGlobalInt(1) > 0) {
   SetGlobalInt (1, GetGlobalInt (1) - 1); // Have bullets left, so decrease bullet count
  //Whatever else you want to happen  // e.g. ProcessClick (mouse.x, mouse.y, MODE_SHOOT);
}
else Display ("You need to reload!"); // No bullets left, so display reload message


And, use a second GlobalInt (GlobalInt 2) to track how much ammo the player has stored:

//on Reload (probably in on_key_press?)
if (GetGlobalInt(2) > (10 - GetGlobalInt(1)) { // Have enough ammo in store to fill clip
  int ammo = 10 - GetGlobalInt(1); // 'ammo' = amount needed to fill clip
  SetGlobalInt (2, GetGlobalInt (2) - ammo) ; // Take 'ammo' from store
  SetGlobalInt (1, 10); // Reload clip
}
else if (GetGlobalInt (2) > 0) { // Have some ammo, but not a full clip
  int ammo = getGlobalInt (2); // 'ammo' = amount left in store
  SetGlobalInt (1, GetGlobalInt (1) + ammo); // Reload clip as much as possible
  SetGlobalInt (2, 0); // Empty store
}
else Display ("You're out of ammo!"); // Nothing left


Or, of course, create your own clip and stored ints.
Title: Re: AGS Shoot em' up problem
Post by: podthepunk on Sun 27/03/2005 14:20:16
try to use the inventory!

you could show every Bullet as image in your inventory, and everytime you shoot, you lose an inventory item.

I cant tell the scripting codes but its an idea.
Title: Re: AGS Shoot em' up problem
Post by: R4L on Sun 27/03/2005 16:14:11
Hey Ashen thats a good idea. Thanks for the help you guys! Pod your idea might work too.
Title: Re: AGS Shoot em' up problem
Post by: MillsJROSS on Mon 28/03/2005 19:26:00
One question, would be, whether your changing rooms constantly. Because if you're staying one room for the most part, a GlobalInt isn't really needed, unless you want to transfer how many bullets you have to the next room. Using GlobalInts is fine, but I try to avoid typing GetGlobalInt, SetGlobalInt, when I can make a local integer which is easier to type with. If you're switching rooms, constantly, though, GlobalInts are the way to go. You're going to need at least one to keep track of how many bullets you have at the change in a room.

The only reason I bring this up, is I think, although I can't test right not to be sure, that using local variables, should process faster than using GlobalInts. I can't attest to the correctness of the statement, but it's generally easier for the system to keep track of local variables over Global ones.

-MillsJROSS