Counting bullets

Started by Rd27, Thu 17/08/2006 17:31:07

Previous topic - Next topic

Rd27

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.

Ishmael

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.
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Nathan23

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..

Khris

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:
Code: ags
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
}

Rd27

Thanks everyone, it works now.

SMF spam blocked by CleanTalk