User Tools

Site Tools


guides:beginners:exploding_monsters

Part 18 - Exploding Monsters

Time to have the monsters explode into bits of jelly when we shoot them. Another new asset:

Right click and save this image into the data/anim folder as “jelly.png”.

Every monster will explode into several of these jelly objects when shot.

Create graphics for the jelly frames:

[JellyGraphic]
Texture     = jelly.png
TextureSize = (32, 32, 0)
Pivot       = center
 
[JellyGraphic1@JellyGraphic]
TextureOrigin = (0,0,0)
 
[JellyGraphic2@JellyGraphic]
TextureOrigin = (32,0,0)
 
[JellyGraphic3@JellyGraphic]
TextureOrigin = (64,0,0)

Then an individual JellyObject:

[JellyObject]
Graphic      = JellyGraphic1
AnimationSet = JellyAnimationSet
Speed        = (-50, -50, 0) ~ (50, -50, 0)
Position     = (400, 0, 0)
Body         = JellyBody

Next to make the JellyAnimationSet:

[JellyAnimationSet]
AnimationList = JellyWobbleAnim
LinkList      = JellyWobbleLoop
 
[JellyWobbleAnim]
DefaultKeyDuration = 0.05
KeyData1           = JellyGraphic1
KeyData2           = JellyGraphic3
KeyData3           = JellyGraphic1
KeyData4           = JellyGraphic2
 
[JellyWobbleLoop]
Source      = JellyWobbleAnim
Destination = JellyWobbleAnim

Then the jelly needs a body. This is so the bits will bounce nicely over the platforms:

[JellyBody]
Dynamic  = true
PartList = JellyBodyPart
 
[JellyBodyPart]
Type        = sphere
Radius      = 10
Solid       = true
SelfFlags   = jelly
CheckMask   = platforms

Then let the platforms know about the jelly mask:

[PlatformBodyPart]
Type        = box
Solid       = true
SelfFlags   = platforms
CheckMask   = hero # monster # jelly

Test it by adding a JellyObject to the Scene section:

[Scene]
ChildList = PlatformObject # MiddlePlatformObject #
TopLeftPlatformObject # TopPlatformObject #
TopRightPlatformObject #
StarObject # JellyObject
TrackList = MonsterMakerTrack

Run it and a jelly with drop onto the platform:

Great. The next step is to create an explosion object. This will be an empty object that contains a spawner. The spawner will shoot out five jellys. These explosion objects can be placed on any monster for dramatic effect:

[JellyExploder]
Spawner         = JellySpawner
 
[JellySpawner]
Object          = JellyObject
WaveSize        = 5
WaveDelay       = 0.1
TotalObject     = 5

To test one of the these, remove the JellyObject from the Scene section and add the JellyExploder instead:

[Scene]
ChildList = PlatformObject # MiddlePlatformObject #
TopLeftPlatformObject # TopPlatformObject #
TopRightPlatformObject #
StarObject # JellyExploder
TrackList = MonsterMakerTrack

Run the game to test the exploder:

Great, we see a bunch of jelly blobs appear. Remove the JellyExploder from the Scene selector:

[Scene]
ChildList = PlatformObject # MiddlePlatformObject #
TopLeftPlatformObject # TopPlatformObject #
TopRightPlatformObject #
StarObject
TrackList = MonsterMakerTrack

Also remove the Position parameter from the JellyObject because these will soon be dynamically placed. Also change the Speed parameter to be more dramatic:

[JellyObject]
Graphic      = JellyGraphic1
AnimationSet = JellyAnimationSet
Speed        = (-50, -250, 0) ~ (50, -450, 0)
Body         = JellyBody

Next, we need to ensure that the BulletObject has a body and that it can collide with a monster:

[BulletObject]
Graphic  = BulletGraphic
LifeTime = 1.0
Scale    = 0.25
Body     = BulletBody
 
[BulletBody]
Dynamic  = false
PartList = BulletBodyPart
 
[BulletBodyPart]
Type        = box
Solid       = false
SelfFlags   = bullet
CheckMask   = monster

The bullets are not affected by gravity (Dynamic) nor do they bounce off other objects (Solid).

In order to make a monster explode, we can make a function in the code which will create a exploder object on top off a monster object, and then destroy the monster itself:

void CreateExplosionAtObject(orxOBJECT *object, orxSTRING exploderObjectName)
{
    if (object == orxNULL)
        return;
 
    orxVECTOR objectVector;
    orxObject_GetWorldPosition(object, &objectVector);
    objectVector.fZ = 0.0;
 
    orxOBJECT *explosion = orxObject_CreateFromConfig(exploderObjectName);
 
    orxObject_SetPosition(explosion, &objectVector);
}

We are passing in a named exploderObjectName so that we can use this function later for other exploders we'll make.

Now to use it. In the physics event, add a check for collision between a bullet and a monster and process it:

if (orxString_Compare(senderObjectName, "BulletObject") == 0){
    CreateExplosionAtObject(pstRecipientObject, "JellyExploder");
    orxObject_SetLifeTime(pstSenderObject, 0);
    orxObject_SetLifeTime(pstRecipientObject, 0);
}
 
if (orxString_Compare(recipientObjectName, "BulletObject") == 0){
    CreateExplosionAtObject(pstSenderObject, "JellyExploder");
    orxObject_SetLifeTime(pstSenderObject, 0);
    orxObject_SetLifeTime(pstRecipientObject, 0);
}

So in both cases, create the JellyExplosion on top of a monster, then destroy both the monster and the bullet that hit it.

Compile and run. You'll get some crazy jelly action all over the screen:

The jelly blobs never dissapear. Fix that by giving it a specific lifetime:

[JellyObject]
Graphic      = JellyGraphic1
AnimationSet = JellyAnimationSet
Speed        = (-50, -250, 0) ~ (50, -450, 0)
Body         = JellyBody
LifeTime     = 5


Next: Part 19 - The Hero's survival.

guides/beginners/exploding_monsters.txt · Last modified: 2016/12/31 02:37 (5 months ago) by sausage