How do I shoot only one bullet

Get help using Construct 2

Post » Tue Mar 12, 2013 6:22 pm

I want to shoot only one bullet when I press a key, and only after the bullet leaves the layout and is destroyed to shoot another bullet, how can I do this?
B
3
Posts: 9
Reputation: 493

Post » Tue Mar 12, 2013 6:36 pm

create a variable that gets set to one when you shoot or when the bullet is spawned, have the bullet destroy outside of layout and set the variable back to 0. create a condition on the key press/shoot event that only fires if the variable is 0.

If none of that makes sense do the beginners tutorials and go through the manual first.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,428

Post » Tue Mar 12, 2013 7:55 pm

Cond: Bullet is on screen
ELSE
Keyb key is down: Spawn bullet
B
20
S
6
G
2
Posts: 157
Reputation: 3,109

Post » Tue Mar 12, 2013 8:02 pm

@silkc2 - Exactly right

However you could also:

Keyb key is down
(Sub) Cond: Bullet is NOT on screen: Spawn Bullet
B
26
S
5
G
5
Posts: 98
Reputation: 4,734

Post » Tue Mar 12, 2013 8:28 pm

Thank you very much! I used the variable implementation ideea. Thanks!
B
3
Posts: 9
Reputation: 493

Post » Tue Mar 12, 2013 10:44 pm

[QUOTE=Equinox80] @silkc2 - Exactly right

However you could also:

Keyb key is down
(Sub) Cond: Bullet is NOT on screen: Spawn Bullet[/QUOTE]

That was first thing I tried, wouldn't work though (something to do with the event not firing if there are no instances of the sprite).
B
20
S
6
G
2
Posts: 157
Reputation: 3,109

Post » Tue Mar 12, 2013 10:50 pm

I suggest doing the number comparison, so hasfired=+1 when fired 1 bullet, and when the bullet is destroyed it sets hasfired=-1 so it's zero.

This way you can setup multiple places where the bullet can be destroyed (on enemy hit) and speed up your firing like Megaman (megaman limited you to 3 bullets on screen, but if you were right next to an enemy or the screen edge you could spam bullets. A valuable mechanic for that game)

If you want a specific delay on the firing rather than if the bullet is onscreen, you can do a timer system in which you can only fire every so often.Thndr2013-03-12 22:50:49
B
15
S
4
G
4
Posts: 294
Reputation: 3,225

Post » Wed Mar 13, 2013 9:58 am

Well guys, there's more than one way to skin a cat but a friendly tip: You shouldn't really ever use variables unless you have to.

I've already done it the same way I posted and works exactly as you'd expect (I'm making a gauntlet type game).

Holding fire spawns a bullet. If it hits an enemy or goes off screen the next bullet spawns. This of course means you get the "faster" fire rate the closer your target, and when it's right next to you, basically bullet spam.
B
20
S
6
G
2
Posts: 157
Reputation: 3,109


Return to How do I....?

Who is online

Users browsing this forum: Ethan, makkancs, Marxally, Naightwolf, pierre244 and 15 guests