First person shooter - Mobile

0 favourites
From the Asset Store
Make your own spaceship game with this fully customizable set.
  • 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.

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

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

  • 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?

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

  • 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?

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

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

  • Ah yeah soz, I was thinking of keyboard pausing. That's mostly what I'm used to. Yep disregard the canPauseUnpause crap ;)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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 :P

  • Sometimes, if you don't ask, you'll never know! And some things can take too long trying to figure it out on your own. At least you may have learned something new for your future projects :)

  • That's for sure.

    When I'm in doubt, I usually post it in the forums (after doing a search), so anyone can help me with it, and so if anyone has the same problem, they can take advantage of the topic.

    While doing so, I'm also trying to solve my issue in 1000 different ways, haha.

  • Also, people will most likely have encountered the same problem, so will have the answers. Sometimes it's not worth trying to reinvent the wheel 1000 times ;p

  • Well, Pause system implemented.

    I remember it took me ages to do it on my previous project due to that it's impossible (or I haven't thought of if in another way) without the System - Else sub-event, and I didn't know of it >.<

  • Yeah Else works nicely, but having Construct Classic experience, I tend to avoid Else ;)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)