First person shooter - Mobile

Get help using Construct 2

Post » Fri Jan 11, 2013 12:06 am

Hey guys,

I'm creating a first person shooter, which resembles of Time Crisis, so it's a stationary enviroment in which enemies will come out of obstacles remaining invisible until so.

Here's the real thing:
I have set a sprite into the background so that I can catch missed shots, and therefore subtract a bullet from the gun magazine.

It works Ok, but when I hit on an enemy or on my Reload button, it also detects that I've hit on the background and therefore subtract an extra bullet.

Is there any way I could avoid this?

What I'm doing is the following:
Touch - On enemy touched -> Destroy it, subtract a bullet, etc.
Touch - On backgroundUsedForMissedShots touched -> subtract a bullet.
Touch - On ReloadButton touched -> set player.bullets to maxBullets.

So basically, I only want to run an action depending on where I have touched, but as I've said, if I hit on the Reload button, it counts as if I've shot, as it sets my bullets to 11.
B
6
S
1
Posts: 54
Reputation: 958

Post » Fri Jan 11, 2013 12:17 am

Have a global variable.

Have a blank or "Every tick" event before the events that checks for shots which sets the value of the global variable to 0. (it will "reset" to 0 every tick, it's important)

When you hit one of the other/top events, change the value of the global variable to 1.

Put your "miss shot" event last (the event that checks for hit on the background) and also check if the value of the global variable is 0.
If it is 0, it means no other element has been "shot" and so it's a misshot.
Otherwise, the event won't execute anyway.

This should work.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Fri Jan 11, 2013 12:20 am

global enemyHit = 0
global isReloading = 0

every tick (before all other events)
enemyhit = 0

+ On enemy touched
+ If isReloading = 0
-> ... your enemy touched actions
-> Set enemyHit = 1

+ On backgroundUsedForMissedShots touched
+ If isReloading = 0
+ If enemyHit = 0
-> subtract a bullet

+ On ReloadButton touch started
-> set player.bullets to maxBullets.
-> set isReloading to 1

+ On ReloadButton touch finished
-> set isReloading to 0

That should work..
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Fri Jan 11, 2013 12:53 am

That's great!

Thanks a lot, to you both!

So basically, what I'm doing here is getting the first thing I hit, the variable is turned, and it only acts once, right?
B
6
S
1
Posts: 54
Reputation: 958

Post » Fri Jan 11, 2013 1:01 am

Yep. The enemyHit variable.. that's set to 0 (to reset it) every tick before all other events. All events that rely on that condition won't be executed if the enemy touched has already triggered and set it to 1.

The reloading works different, as that sets the variable and remembers it. On touching the reload button, it's set to 1 and won't be set to 0 again until the player lifts their finger off the reload button, so the game can't give a false positive because the other events rely on it being 0.
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Fri Jan 11, 2013 1:19 am

Got it. So if I want to create a Pausing button, I would have to create a new variable "isPaused", and do the same, am I right?
B
6
S
1
Posts: 54
Reputation: 958

Post » Fri Jan 11, 2013 1:47 am

Correct! Bit more to it because of the "is pressed", since this will trigger the unpause event too as that will also be checking for "is pressed" and is also checking for isPaused = 1 which was set in the pause event. So we need another variable canpauseUnpause. Same kind of thing though.

global isPaused = 0
global canPauseUnpause = 1

+ every tick
-> set canPauseUnpause = 1

+ if pausedkey is pressed
+ if isPaused = 0
+ if canPauseUnpause = 1
-> set isPaused = 1
-> set timescale to 0
-> set canPauseUnpause = 0

+ if pausedkey is pressed
+ if isPaused = 1
+ if canPauseUnpause = 1
-> set isPaused = 0
-> set timescale to 1
-> set canPauseUnpause = 0

pausedkey being whatever key you assign to be the pause key.procrastinator2013-01-11 01:49:20
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Fri Jan 11, 2013 1:52 am

Couldn't I just do it with the "On any touch start", checking the user it touching the pause button, so I can completely avoid that "canPauseUnpause"?

This way, a single touch won't trigger the event more than once (as I'm only checking when it's first touched).
B
6
S
1
Posts: 54
Reputation: 958

Post » Fri Jan 11, 2013 1:57 am

Ah yeah soz, I was thinking of keyboard pausing. That's mostly what I'm used to. Yep disregard the canPauseUnpause crap ;)
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Fri Jan 11, 2013 2:12 am

Yeah, although I've done a couple of projects with Construct I'm not nearly good at it yet, that's why I was mainly asking :PMiyavi2013-01-11 02:12:29
B
6
S
1
Posts: 54
Reputation: 958

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 24 guests