Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Rd27 on Thu 17/08/2006 17:31:07

Title: Counting bullets
Post by: Rd27 on Thu 17/08/2006 17:31:07
Hi, my problem is this:

I am making a little firstperson shootergame for a practice and now my problem is that I don't know how can I make the game count bullets.

I wan't that the player has six bullets and when he has shoot six times, he has to reload the gun. The reload can be done before six time too.

I have understand that this is possible, but I just don't know how.

I tried to look in this tutorial, but I didn't quite understand it :
http://americangirlscouts.org/agswiki/index.php/GUI%2C_Inventory_%26_Menu#Adding_money_to_your_game

I am using the interaction cursor for shooting and acting as a finder.

It would be nice to use R button for reload.

Thanks for help.
Title: Re: Counting bullets
Post by: Ishmael on Thu 17/08/2006 18:48:06
Use variables. The scripting tutorial in the manual ought to teach now to handle those. You can use the IsKeyPressed command in the on_key_press global function with the keycode for R to find whenever it's pressed and the clip should reload.
Title: Re: Counting bullets
Post by: Nathan23 on Thu 17/08/2006 18:54:13
You need to create a Global variable at your main script and in the room where you want to use it you will need to export.. in the manual read about this "import" and "export"... for the "R" keycode the suggestion of Ishmael seems fine for me..
Title: Re: Counting bullets
Post by: Khris on Thu 17/08/2006 20:03:56
Quote from: Nathan23 on Thu 17/08/2006 18:54:13and in the room where you want to use it you will need to export..
No.

Besides, a GlobalInt will do nicely here.

You'd use something like this:
function shoot(int x, int y) {
Ã,  ... // place code here that handles the shot
Ã,  SetGlobalInt(1, GetGlobalInt(1)-1); // decrease ammo by one
}

function on_mouse_click(MouseButton button) {
Ã,  if (button==eMouseLeft) {
Ã,  Ã,  if (GetGlobalInt(1)>0) { // ammo left
Ã,  Ã,  Ã,  shoot(mouse.x, mouse.y);
Ã,  Ã,  }
Ã,  Ã,  else {
Ã,  Ã,  Ã,  PlaySound(?);Ã,  // empty click
Ã,  Ã,  }
Ã,  }
Ã,  ... // additional mouse_click handling
}

function on_key_press(int keycode) {
Ã,  ... // function keys, etc.
Ã,  if (keycode==82) SetGlobalInt(1, 6); // reload
}
Title: Re: Counting bullets
Post by: Rd27 on Tue 22/08/2006 14:17:03
Thanks everyone, it works now.