Mario style: Jump on top of enemy to kill it

Forum Home Forum Home > Construct 2 General > How do I....?
 Post Reply Post Reply Page  12>
Author
1,338 Rep
Post Options Post Options   Quote Dabbijo Quote  Post ReplyReply Direct Link To This Post Topic: Mario style: Jump on top of enemy to kill it
    Posted: 10 Sep 2011 at 11:04pm
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.
Back to Top
489 Rep
Post Options Post Options   Quote LeadDiet Quote  Post ReplyReply Direct Link To This Post Posted: 10 Sep 2011 at 11:25pm
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.
Back to Top

Scirra Developer
84,357 Rep
Post Options Post Options   Quote Ashley Quote  Post ReplyReply Direct Link To This Post Posted: 10 Sep 2011 at 11:25pm
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...
Back to Top
1,338 Rep
Post Options Post Options   Quote Dabbijo Quote  Post ReplyReply Direct Link To This Post Posted: 10 Sep 2011 at 11:30pm
Thanks guys, makes sense! :)
Back to Top
881 Rep
Post Options Post Options   Quote awesome8x Quote  Post ReplyReply Direct Link To This Post Posted: 11 Sep 2011 at 12:07am
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!!

Edited by awesome8x - 11 Sep 2011 at 12:13am
Back to Top

Scirra Developer
84,357 Rep
Post Options Post Options   Quote Ashley Quote  Post ReplyReply Direct Link To This Post Posted: 11 Sep 2011 at 1:15am
@awesome8x, that's one way of doing it, but the other way saves you having to create and position those 'detector' objects.
Back to Top
2,156 Rep
Post Options Post Options   Quote TastyBytes Quote  Post ReplyReply Direct Link To This Post Posted: 06 Nov 2011 at 9:46pm
Clever. But what happens, when the Player is major than the enemy?
Back to Top
4,415 Rep
Post Options Post Options   Quote vtrix Quote  Post ReplyReply Direct Link To This Post Posted: 06 Nov 2011 at 10:23pm
this works

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

http://dl.dropbox.com/u/36224287/platform_jumpkill.capx

Edited by Tom - 15 Jan 2012 at 7:39pm
Back to Top
11,720 Rep
Post Options Post Options   Quote Yann Quote  Post ReplyReply Direct Link To This Post Posted: 06 Nov 2011 at 10:24pm
by "major" I understand "taller"
That's not an issue if you put the origin at feet level
Back to Top
2,156 Rep
Post Options Post Options   Quote TastyBytes Quote  Post ReplyReply Direct Link To This Post Posted: 07 Nov 2011 at 8:34am
Damn. Your are right.
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down