How do I make tap order?

Get help using Construct 2

Post » Sun May 01, 2016 12:53 pm

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?
B
25
S
6
G
4
Posts: 173
Reputation: 3,933

Post » Sun May 01, 2016 1:33 pm

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.
I got a game that you multiply, breath fire with two heads and brawl foes to oblivion with your clones: http://www.newgrounds.com/portal/view/660664 (use Chrome on Windows for best performance)

My sites:
http://twinblazar.deviantart.com
http://twinblazar.newgrounds.com
https://twitter.com/twinblazar
http://www.pixiv.net/member.php?id=15072448
B
30
S
11
G
11
Posts: 411
Reputation: 8,469

Post » Sun May 01, 2016 7:56 pm

@keroberos, no I don't get it.
B
25
S
6
G
4
Posts: 173
Reputation: 3,933

Post » Mon May 02, 2016 4:22 am

ok,

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.

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

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?
I got a game that you multiply, breath fire with two heads and brawl foes to oblivion with your clones: http://www.newgrounds.com/portal/view/660664 (use Chrome on Windows for best performance)

My sites:
http://twinblazar.deviantart.com
http://twinblazar.newgrounds.com
https://twitter.com/twinblazar
http://www.pixiv.net/member.php?id=15072448
B
30
S
11
G
11
Posts: 411
Reputation: 8,469

Post » Mon May 02, 2016 9:00 pm

@TwinBlazer, what if I wanted to change the order to color, say red to blue to yellow to purple to green to white?
B
25
S
6
G
4
Posts: 173
Reputation: 3,933

Post » Tue May 03, 2016 3:00 am

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.
I got a game that you multiply, breath fire with two heads and brawl foes to oblivion with your clones: http://www.newgrounds.com/portal/view/660664 (use Chrome on Windows for best performance)

My sites:
http://twinblazar.deviantart.com
http://twinblazar.newgrounds.com
https://twitter.com/twinblazar
http://www.pixiv.net/member.php?id=15072448
B
30
S
11
G
11
Posts: 411
Reputation: 8,469

Post » Tue May 03, 2016 7:56 pm

@TwinBlazar thanks for your help. Although is there a capx I can use though?
B
25
S
6
G
4
Posts: 173
Reputation: 3,933


Return to How do I....?

Who is online

Users browsing this forum: batto and 19 guests