How do I Cycle Weapons?

0 favourites
  • 3 posts
From the Asset Store
Perfect for your zombie game! Animated from motion capture data Left, Right, Top Down!
  • Dear Constructtwoeans,

    My on couch co-op platform game is nearing its first Alpha stage after working hard for almost a year. At the moment, I'm implementing some of the final mechanics to make it a fully working build, representing all the core elements of the game.

    One of which is a mechanic that allows the players to pick up different weapons (swords, bows, guns etc) and items (shields, bombs, passive buff items etc) and steal them from one another. I'm struggling to implement this mechanic and would like to see how you would go about it.

    Let me first line out what the general idea is before giving you all a blow by blow.

    -----------------------

    Each player may hold, at any time, only ONE weapon and ONE item. Each weapon may be used to perform attacks or, if it is a melee weapon, be thrown at a 4 direction angle (up,down,left and right). Same goes for items, they may be used (shields block, bombs are placed and buffs are cast) or thrown for an alternative effect.

    Weapons and items can be stolen from enemies and other players by jumping on top of them (mario style). When jumped on from the front (i.e. the player is looking in the opposite direction that the enemy is looking) the enemy will drop its current weapon, which is vectorY'ed upwards. If jumped on from the back (i.e. the player is looking in the same direction as the enemy) the enemy will drop its current item which is vectorY'ed upwards.

    So here is the blow by blow and the problem I'm having

    1) Player has no weapon/item

    2) Player overlaps with weapon/item and presses "DownArrow" (for example)

    3) Weapon is "picked up", meaning it is set to the player sprite's "hand" image point and its angle adjusted etc

    So far so good...

    But here is where I get in trouble and would like some help:

    | |

    \ /

    \/

    4) Player ownes weapon/item

    5) Player overlaps with weapon/item and presses "DownArrow" again.

    6) The weapon held is "discarded" (vectored back and upwards, fade out into destroy in x seconds)

    7) The weapon on the floor is picked up, insert step 3, rinse repeat.

    In short: I would like for each player to be able to cycle from 1)no weapon 2)weapon 3)new weapon using only one pick up key.

    As always, thank you all ever so much for reading and I look forward to your input.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Read some guides about instances.

    instances (set 0 for no weapon / 1 for weapon / 2 for new weapon)

    or boolean (false for no weapon / true for weapon)

    then add an instance check on the peer -> if the player has already a weapon or not

    And sorry if i'm not big of a help, just bought construct 2 some days ago, so i'm not experienced at all.

  • I'd use an instance variable, heldWeapon or something, that is initially set as -1 and, when the player picks a weapon, it's set with the UID of the weapon instance he picked (making it easier to destroy afterwards). Also, when picking a weapon, you would check if heldWeapon is greater than -1 and, in that case, you would destroy the held weapon (using its UID) before picking the new one. If you have some kind of drop action it would trigger the destruction routine and set heldWeapon back to -1.

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