How do I read all gamepad buttons on collision

0 favourites
  • 6 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • I am working on a stepmania type game.

    However, I want to use an 8-button gamepad as the input. Just the buttons.

    Each sprite that travels across the screen will have it's own button combination to press at the right time when it collides with the playbar (stepmania calls it "judgement row"). A button combination variable could be something like "00100101", showing buttons 3,6,and 8 should be pressed.

    When the sprite detects collision (or the playbar detects collision with a sprite), I want to read all 8 gamepad buttons at that time to see if the player is pressing the correct combination.

    How can I assign a button combination variable to each sprite?

    How can I read all 8 gamepad buttons on collision, and check them against the sprite's button combination variable?

  • Hi there. You'd probably want a function that checks all 8 for input every time rather than having "set" combinations. This allows you the flexibility to include any combination you want in future. The Function could be called with 8 parameters which map to your button combination, such as "10001000" in the example below:

    Variable "FailState" = 0

    ## You need a variable to judge whether or not the player has failed to do the correct combination. Any of the combination checks can register a fail which then gets passed to the next function which allocates points.

    "Combination" on collision with "JudgementRow"

    Run Once

    Call function "Judgement" (1,0,0,0,1,0,0,0)

    Function "Judgement"

    param0 = 1

    param1 = 0

    param2 = 0

    param3 = 0

    param4 = 1

    param5 = 0

    param6 = 0

    param7 = 0

    {

    set "FailState" to 0 ## Resetting the variable so the player doesn't inherit the result from last time.

    if function.param(0) = 1

    if button1 is NOT pressed

    set "FailState" to 1 ## The player has failed the combination.

    if function.param(1) = 1

    if button2 is NOT pressed

    set "FailState" to 1 ## The player has failed the combination.

    if function.param(2) = 1

    if button3 is NOT pressed

    set "FailState" to 1 ## The player has failed the combination.

    if function.param(3) = 1

    if button4 is NOT pressed

    set "FailState" to 1 ## The player has failed the combination.

    if function.param(4) = 1

    if button5 is NOT pressed

    set "FailState" to 1 ## The player has failed the combination.

    if function.param(5) = 1

    if button6 is NOT pressed

    set "FailState" to 1 ## The player has failed the combination.

    if function.param(6) = 1

    if button7 is NOT pressed

    set "FailState" to 1 ## The player has failed the combination.

    if function.param(7) = 1

    if button8 is NOT pressed

    set "FailState" to 1 ## The player has failed the combination.

    Call Function Points(FailState) # Passing Failstate to the Points function, which can be used to either subtract or remove points based on your gameplay logic.

    }

    If you wanted to improve this, you might consider the following:

    1) The player has failed the combination completely (all three buttons missed) - they get 0 points.

    2) The player has failed the combination by missing one of the three buttons - they should get SOME points.

    3) The player has passed the combination - they should get all the points.

    If you changed the variable above to "add +1" (instead of "set to 1") for each incorrect check then pass that number to the "Points", you can judge the degree of their success and failure.

  • [quote:3do3xrfs]Hi there. You'd probably want a function that checks all 8 for input every time rather than having "set" combinations. This allows you the flexibility to include any combination you want in future. The Function could be called with 8 parameters which map to your button combination

    For flexibility that is true, but I will have 9 sprites total and each will have their own button combination that will never change. For example:

    Sprite1 = 11111111

    Sprite2 = 01111111

    Sprite3 = 00111111

    Sprite4 = 10011111

    Sprite5 = 10001111

    Sprite6 = 01110111

    Sprite7 = 01110011

    Sprite8 = 01110001

    Sprite9 = 01111000

    Since I know each sprite's combination, is this still the best way?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Since I know each sprite's combination, is this still the best way?

    It remains best practice to write functions that are capable of checking any number of combinations. Not necessarily because it's best to have that flexibility, but more to do with being concise - one function to handle ALL combinations is good. Creating 9 separate chunks of code to deal with each combination = repetitive.

    The function can also be used, as I said before, be more granular about how you allocate points, or judge failure. If you are having any trouble writing out something similar to my first suggestion I could do a mockup in Construct 2 for you to look at.

  • I sent you a private message

  • I sent you a private message

    Hello,

    I'm not able to reply until I've earned 500 forum rep! Contact me on FB or Twitter via my profile if you like.

    Cheers

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