Mario style: Jump on top of enemy to kill it

Get help using Construct 2

Post » Sat Sep 10, 2011 11:04 pm

Just wondering how I'd make the enemy die when I jump on top of it, but let me die when I hit the sides.

I just need a quick explanation of the code, can't for the life of me figure this out.
B
14
S
3
G
2
Posts: 37
Reputation: 1,893

Post » Sat Sep 10, 2011 11:25 pm

Maybe an event that says,

IF player.Y is > Monster.Y
AND IF player is overlapping monster
-Destroy monster

IF player.Y <= Monster.Y
AND IF player is overlapping monster
-Destroy player

etc etc etc Refine as needed :) Of course, if you don't have the monster or the player bump back on a bad contact, you will murder the player instantly regardless of health.

Also, my above sample doesn't take the angle of approach, so as long as the player is above and touching the monster, the monster is doomed.
B
3
S
2
G
1
Posts: 7
Reputation: 789

Post » Sat Sep 10, 2011 11:25 pm

A simple way:

+ Player collides with enemy
+ Player.Y < Enemy.Y (i.e. player is above enemy)
-> Player has jumped on enemy's head, kill enemy...

+ Player collides with enemy
+ Player.Y >= Enemy.Y (i.e. player is not above enemy)
-> Player has run in to enemy, take damage...
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,518

Post » Sat Sep 10, 2011 11:30 pm

Thanks guys, makes sense! :)
B
14
S
3
G
2
Posts: 37
Reputation: 1,893

Post » Sun Sep 11, 2011 12:07 am

This is roughly how I'd do it. Here's an explanation of how to do it:
Create a small black platform and an enemy. Let's call the platform "GoombaTop" and the enemy "Goomba". Set the hotspot of the "Goomba" sprite to a little above his head. Set the initial visibility of "GoombaTop" to invisible. Now, go to the event sheet. (We'll call your character "Mario", who should have platform behavior, and the ability to jump, using 8-Direction Movement, or however you know how to make him jump.)

Make this event: System->Every Tick.
Make this action for the above event: GoombaTop->Set Position->X: Goomba.X Y: Goomba.Y
(This makes it so that GoombaTop stays above Goomba's head.)

Make this event: Mario->On Collision With Another Object->GoombaTop
Make these actions for the above event: Goomba->Destroy
GoombaTop->Destroy
(This makes it so jumping on GoombaTop kills the Goomba)

Make this event: Goomba->On Collision With Another Object->Mario
Make these actions for the above event: Mario->Destroy
System->Wait->1.0 Seconds
System->Go To Layout->Layout 1
(This makes it so that if Mario makes contact with the side of Goomba, he dies.)

To make another Goomba, create "Goomba2" and "GoombaTop2", set the properties of "Goomba2" to those of "Goomba", set the properties of "GoombaTop2" to those of "GoombaTop", and create all of the same actions and events, except replacing "Goomba" with "Goomba2" and replacing "GoombaTop" with "GoombaTop2".


Hope this helped!!awesome8x2011-09-11 00:13:17
B
13
S
2
G
1
Posts: 14
Reputation: 1,111

Post » Sun Sep 11, 2011 1:15 am

@awesome8x, that's one way of doing it, but the other way saves you having to create and position those 'detector' objects.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,518

Post » Sun Nov 06, 2011 9:46 pm

Clever. But what happens, when the Player is major than the enemy?
B
14
S
2
G
6
Posts: 110
Reputation: 3,849

Post » Sun Nov 06, 2011 10:23 pm

this works

player platform "isfalling"
- on collison with enemy > destroy

http://dl.dropbox.com/u/36224287/platform_jumpkill.capxTom2012-01-15 19:39:19
ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028

Post » Sun Nov 06, 2011 10:24 pm

by "major" I understand "taller"
That's not an issue if you put the origin at feet level
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Nov 07, 2011 8:34 am

Damn. Your are right.
B
14
S
2
G
6
Posts: 110
Reputation: 3,849

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests