How do I make tap order?

0 favourites
  • 7 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • How do I make a mechanic that the player has to collide with objects in the order they appear and if not the player dies?

  • You need to assign a variable into the object player needed to collide with. You assign variables of these objects in a running number. (ex. 1st object created is assigned 1, 2nd object is assigned 2, etc.)

    You will also need to assign a variable to the player and assign a number that player needs to go for. (in the case, the 1st object, which has the variable value of 1, so you assign 1 to the player's variable, too.)

    When the collision occured between the player and the object, you checked for the numbers of both the player and the object. If both numbers are the same, you can destroy this object and assign the next number the player needs to go for, in this case 2. Else if the numbers are not the same, game over.

    Do you follow so far? If not, say so, and we can help you in finer details.

  • , no I don't get it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ok,

    [quote:3o5mx22n]You need to assign a variable into the object player needed to collide with. You assign variables of these objects in a running number. (ex. 1st object created is assigned 1, 2nd object is assigned 2, etc.)

    First, let's take care of the variables.

    Create a global variable called "runningNumber" and give it value of 1 in your event sheet.

    Create an instance variable for the object and call it indexNumber, set default value to 0.

    [quote:3o5mx22n]You will also need to assign a variable to the player and assign a number that player needs to go for. (in the case, the 1st object, which has the variable value of 1, so you assign 1 to the player's variable, too.)

    Since you want the player to go for the objects in the order they are created. We need to assign a number to these objects when these objects are created.

    In the object's On Create event, set the object's indexNumber to the global variable runningNumber. Then, add 1 to the global variable runningNumber.

    Why add 1 to the global variable runningNumber? This is so whenever another object that the player has to go for is created, it will have the succeeding number. (For example, when the first object is created, it will have indexNumber set to 1, the second object will have indexNumber as 2, and so on.)

    [quote:3o5mx22n]When the collision occured between the player and the object, you checked for the numbers of both the player and the object. If both numbers are the same, you can destroy this object and assign the next number the player needs to go for, in this case 2. Else if the numbers are not the same, game over.

    Now, the main crux. We have these objects created and each of them have indexNumber assigned in sequential order by the order they are created.

    Create an instance variable for the player, call it "nextIndex" and assign it a value of 1.

    Now, create a collision event for the player colliding with the object. In this collision event, you will check for the player's nextIndex and the object's IndexNumber. If these two numbers are equal, it means the player is touching the right object. Else, the player is touching the wrong object.

    From this logic, you can create Collision event like this:

    Player On collision with Object

    > if Player.nextIndex = Object.IndexNumber : > > > Add 1 to Player.nextIndex

    > > Object destroy

    > else

    > > Player destroy

    The first time the player collides with Object, if the object has IndexNumber of 1, which is the same as the value of the player's Nextindex, this implies the player is touching the first Object correctly. If the object the player touches does not have IndexNumber of 1, the player touches the wrong object and will be destroyed.

    Why do we put "Add 1 to Player.nextIndex" there? This is because the next Object the player should touch is 2. And the same logic from above can be applied. The player will survive as long as he keeps on touching the correct objects using these incremental numbers, but the player will be destroyed if he touches the incorrect object.

    Is this explanation better?

  • , what if I wanted to change the order to color, say red to blue to yellow to purple to green to white?

  • In that case, just create appropriate colored images, put each color separately into different animation of your Object sprite (ex. red image goes into "red" animation, blue goes into "blue", etc.), and set the appropriate animation accordingly in each Object in order.

    This way, it is like model view controller (google it up). You leave your logic be with those numbers comparison while leaving these colors separately from logic. The benefit is, suppose you wanna change color or want to change the whole charade to some other "visuals" completely, you can do so without modifying the events.

  • TwinBlazar thanks for your help. Although is there a capx I can use though?

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