User Tools

Site Tools


en:guides:beginners:survival

This is an old revision of the document!


Part 19 - Survival

Keeping alive is key in a platformer. The monsters need to be a threat to our hero. If a monster touches our hero, he should explode in a shower of bits. That's game over.

For the explosion for our hero, let's use this object in the data/object folder:

Might seem an odd choice, but if 50 of these spawned over the hero in various stages of rotation and flew in several directions like sparks, it will be fairly effective. Start with the object and the graphic:

[SparkGraphic]
Texture = +.png
Pivot   = center
 
[SparkObject]
Graphic  = SparkGraphic
Speed    = (-350, -350, 0) ~ (350, -850, 0)
Color    = (255, 0, 0) ~ (255, 255, 255)
Rotation = 0 ~ 90
LifeTime = 2 ~ 4
Scale    = 0.5 ~ 1.0
Body     = SparkBody

Each SparkObject will fly up and out in a random direction, random colours, sizes, and a random lifetime. 50 at a time should look good. Next, make a body for it so that it will fall back to earth:

[SparkBody]
Dynamic  = true
PartList = SparkBodyPart
 
[SparkBodyPart]
Type  = box
Solid = false

A pretty simple body and part - affected by gravity but not set to collide with anything.

Finally, we'll make an empty hero exploder with a spawner that spawns out 50 SparkObject's:

[HeroExploder]
Spawner = HeroSpawner
 
[HeroSpawner]
Object          = SparkObject
WaveSize        = 50
WaveDelay       = 0.1
TotalObject     = 50

Before we can deal with the collision between monster and hero, we need to ensure the flags of the hero knows about monsters:

[HeroBodyPart]
Type        = box
Solid       = true
SelfFlags   = hero
CheckMask   = platforms # star # monster

Now to handle it in code:

if (orxString_Compare(recipientObjectName, "HeroObject") == 0 &&
    orxString_Compare(senderObjectName, "MonsterObject") == 0
){
    CreateExplosionAtObject(pstRecipientObject, "HeroExploder");
    orxObject_SetLifeTime(pstSenderObject, 0);
    orxObject_Enable(pstRecipientObject, orxFALSE);
}
 
if (orxString_Compare(senderObjectName, "HeroObject") == 0 &&
    orxString_Compare(recipientObjectName, "MonsterObject") == 0
){
    CreateExplosionAtObject(pstSenderObject, "HeroExploder");
    orxObject_SetLifeTime(pstRecipientObject, 0);
    orxObject_Enable(pstSenderObject, orxFALSE);
}

So if the hero and the monster touch, disable the hero and place a HeroExploder on top of him.

Compile and run it:

So there you go. The major elements of the game are now complete. Well done!

In our next and last chapter, we'll do a few housekeeping changes to flesh the game out.


Next: Part 20 – Text and Game Over.

en/guides/beginners/survival.1518583673.txt.gz · Last modified: 2018/02/14 00:47 (6 years ago) (external edit)