Build a GameCreating Shatterfield

5  Crash and Lives

Goal

The rocks tumble and break. Now they can hurt you. By the end of this chapter, a rock that touches the Ship destroys it. You start with three lives, shown as tiny ships in the top left corner. Each new Ship arrives in the middle of the screen, blinking, and for 3 seconds nothing can touch it.

The game as it is at the end of this chapter. Click the game to play.

If your game and this chapter part ways, here is the chapter’s finished project. Open it and compare, or start Chapter 6 from it.

Shatterfield, Chapter 5 finishedZip of a Myth project · 5.0 MB

To open it, right-click the downloaded file, choose Extract All... and then Extract. Start Myth Engine, choose File › Open Project... and pick the .mythproj file in the new folder. Beside it, OFL.txt is the license of the project’s font, Press Start 2P.

5.1 The Idea

The Ship drifts too close to a big rock. They touch.

The Ship bursts apart in a spray of white, cyan and gold. A deep boom rolls out, with a second sound behind it, and the whole screen shakes. The rock breaks too, the way it would for a Shot, and its two halves tumble on through the place where the Ship was. Up in the top left corner, one of three tiny ships goes out.

For a moment, nothing. A new Ship appears in the middle of the screen. It blinks, solid and faint, solid and faint. Fly it straight into a rock while it blinks, and it passes through unharmed. Three seconds later the blinking stops, and from then on a touch counts.

That blinking Ship is the chapter’s idea. The touch is the same every time, and what changes is only how the Ship answers it.

You’ve met half of this before. In Chapter 1, Thrust Feedback hung a sign on its door, Coasting or Thrusting, and turned it as it worked. Ship Crash gets a sign too, and a rock’s touch is the knock. While the sign says Exposed, the Ship breaks, and while it says Shielded, nothing happens at all.

What’s new is who decides when the sign turns. Ship Shield keeps the time. It sends two messages, one as a new Ship appears and one 3 seconds later, and Ship Crash turns its sign as each one arrives.

Someone also has to count the lives, and send each new Ship 2.4 seconds after a crash. A Ship can’t send the next one. By then it’s gone. So this chapter makes Game Rules, an Object with no picture. It sits in the Scene for the whole game and looks after the game’s own business, starting with the lives.

5.2 The Plan

Here’s how the pieces work together, read from left to right.

  • A Ship appears -> Ship Shield sends shieldUp -> Ship Crash turns its sign to Shielded, and the Ship blinks.
  • 3 seconds later -> Ship Shield sends shieldDown -> Ship Crash turns its sign back to Exposed.
  • An Exposed Ship touches an Asteroid -> Ship Crash sends hit to that rock, explodes, sends shipDestroyed, and removes the Ship.
  • The game starts -> Lives and Respawn sets the lives to 3.
  • The message shipDestroyed arrives -> Lives and Respawn takes away a life, and if any are left, a new Ship comes 2.4 seconds later.
  • The lives change -> on each tiny ship, Life Icon asks Show Life Icon whether it should show.

5.3 Set Up

This chapter needs one picture, two sounds and one Global Variable. Life Icon Sprite is a tiny copy of the Ship. Ship Lost is the sound of losing one, and Ship Respawn the sound of a new one arriving. They’re already in your project.

Make lives the way you made areaWidth in Chapter 3. Open Ship Gun, press the + on its Globals card, and choose New Global…. It’s a Number, and its Default stays at 0. That’s no slip. Lives and Respawn gives it 3 the moment the game begins, so a game’s lives are written in one place only. PLACE THESE waits until Game Rules and the icons exist.

Set upWhat this chapter adds
ART (sprites, from the starter kit)
Life Icon Sprite
SOUNDS (from the starter kit)
Ship Lost
Ship Respawn
GLOBAL VARIABLES
$livesNumberstarts at 0
SCENE Space: PLACE THESE
ObjectXY
Game Rules024
Life Icon 10.93821.563
Life Icon 21.87521.563
Life Icon 32.81321.563
Life Icon 43.7521.563
Life Icon 54.68821.563

5.4 The Crash

First, the Ship learns to break.

5.4.1 Ship Explosion

A crash needs a bigger spray than a hyperspace jump. Ship Explosion is that spray. Its glowing dots come in six colors, from white and pale cyan through blue to gold, orange and a deep pink-red. They fly out fast, drag to a stop, and shrink away to nothing, all within a second.

Make it the way you made Impact Sparks in Chapter 3, line by line from its card. One line is new. Burst Count is how many dots the effect sprays when whoever bursts it names no number. Type 84.

Particle EffectShip Explosion
Emitter
Emission > Burst Count84
Emitter Shape > Emit Radius (m)0.313
Motion
Lifecycle > Each Particle Lives (ms)min 320, max 950
Motion > Speed (m/s)min 3.438, max 14.375
Forces > Dragx 1.45, y 1.45
Appearance
Appearance > Color SourceMultiple Colors
Appearance > Multiple Colors#FFFFFF, #9CECFF, #35B7FF, #FFD166, #FF7B45, #E24A63
Appearance > Glow1.9
Appearance Over Life > Scalestart 1.55, end 0
Appearance Over Life > Size Variation (0–1)0.65
Appearance Over Life > Starting RotationRandom Spin On

Burst Count is on the Emitter page, under Emission, and it starts at 24. On the Appearance page, two colors are there already, and Add Color, pressed four times, makes the other four.

Glow is the slider from Chapter 3. Stop it where the number beside it reads 1.9×. The rest is as it was for Impact Sparks, with Random Spin, the one switch under Starting Rotation, turned on.

5.4.2 Ship Crash

When the Ship touches a rock, Ship Crash decides what happens. Usually, it’s the end of the Ship.

Its When bar is Collision, with tag:Asteroid as its Object, so a rock of any size counts. Myth names that Event While Hitting Anything Tagged Asteroid, and that’s the heading on its card. It’s a different Event from Collision Enter, the one Shot Impact uses. Collision Enter runs once, at the first touch. The game moves in small steps, many each second, and Collision runs again every step, for as long as the touch lasts.

Why would that matter? Picture a new Ship blinking in right on top of a rock. The shield holds. Then the shield runs out with the rock still there, and that touch has to count. Collision Enter would miss it. The touch began while the Ship was shielded.

Here’s the chapter’s one hard idea, and it’s the sign from Chapter 1, one step further, so take it slowly. This Event has two Modes. Exposed is the one it starts with, and Shielded is the other. A touch arrives. Only the Mode on the sign answers it.

Thrust Feedback turned its sign partway through its own work. Ship Crash never does. It turns its sign only when a message arrives.

Exposed is the crash, start to finish, in four moves. It tells the rock, puts on a show, tells the game, and removes the Ship. The rock hears hit, the same message a Shot sends, so it breaks the way it would for a Shot.

The show is two bursts of light, two sounds, and a hard shake that lasts 0.45 seconds. The first burst is Ship Explosion, explosionCount of it: 90 dots, a few more than its own 84. A count the Logic names wins. The sounds are ExplosionLarge, the boom of a big rock breaking in Chapter 4, and Ship Lost.

After the show, shipDestroyed goes out with Trigger Custom Event, to anyone in the game who’s listening. Nothing listens yet. Game Rules will, in the next part.

Once the Ship is destroyed, it hears nothing more. So if two rocks touch it in the same moment, it still breaks only once.

The last two Events turn the sign. When shieldUp arrives, Switch Mode turns the collision Event to Shielded. When shieldDown arrives, it turns it back.

On the card, that Event shows up twice, once for each Mode, as Thrust Feedback’s did. It’s one Event.

Logic ComponentShip CrashAttach to: Ship

Touching an Asteroid destroys the Ship: it tells the Asteroid it was hit, explodes, and reports shipDestroyed.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
explosionCountNumberConstant90
crashSparkCountNumberConstant40
shakeNumberConstant0.022
shakeSecondsNumberConstant0.45
While Hitting Anything Tagged Asteroid
WhenCollisionObject: tag:Asteroid
ModeExposed (Starting Mode)
1Trigger Custom Event on Object
Applies To
other
Custom Event
hit
2Burst Particles
Particles
"Ship Explosion"
Count
@self.explosionCount
3Burst Particles
Particles
"Impact Sparks"
Count
@self.crashSparkCount
4Control Sound
Sound
"ExplosionLarge"
5Control Sound
Sound
"Ship Lost"
6Camera Shake
Intensity
@self.shake
Seconds
@self.shakeSeconds
7Trigger Custom Event
Custom Event
shipDestroyed
8Destroy Instance
While Hitting Anything Tagged Asteroid
WhenCollisionObject: tag:Asteroid
ModeShielded
(no Actions)
On Shield Up
WhenshieldUpCustom Event
1Switch Mode
Event
While Hitting Anything Tagged Asteroid
Mode
Shielded
On Shield Down
WhenshieldDownCustom Event
1Switch Mode
Event
While Hitting Anything Tagged Asteroid
Mode
Exposed

Now build it, from the top of the card. Make it with Add > Logic Component and Empty Logic Component. Its SHARED VARIABLES come first: four Numbers, each Constant, at the card’s Starting Values.

Type Collision into the Add Event window’s filter, and pick Collision itself, the first in the list. No second window opens. The new Event listens for Any Object. Open the Collision section on its block, as you did for Shot Impact, and pick Tagged Asteroid in the Collision Target list. Myth renames the Event to match the card’s heading.

One thing arrives on its own. The Components card down the left now lists self.collider. Myth adds it for a collision Event, and the card leaves it out. Leave it there.

The Modes go in the way Coasting and Thrusting did. Right-click Mode 1, choose Rename Mode…, and type Exposed. Then right-click the Event’s own block, choose New Mode…, and name the new one Shielded. Leave the Modes on One at a time, and the Starting Mode on Exposed, where it already is. Your hands know this now.

Exposed’s Actions go on its own line. Right-click the Exposed block, choose Add unattached Action here, and join each new block with Connect to sequence. Each one after that comes from a right-click on the last block of the line. In Trigger Custom Event on Object, pick Other in the Applies To list, under Event Context, and type hit, as in Shot Impact.

The two Burst Particles pick their effect from a list, and the two Control Sounds their sound. The card writes those names in quotes, such as “Ship Explosion”. In the list, pick Ship Explosion. Each Count box takes the card’s name for it, @self.explosionCount and then @self.crashSparkCount.

Both Control Sounds stay on Play, where their Operation starts, and Camera Shake takes the same two names as Break Apart’s. Then comes Trigger Custom Event, the one that tells the whole game. Type shipDestroyed into its Custom Event box as the card writes it, with no quotes. Destroy Instance comes last.

Shielded stays empty. That’s its whole job.

shieldUp and shieldDown are new Custom Events. Make each one the way you made hit in Chapter 4: type Custom into the Add Event window’s filter, pick Add Custom Event…, and type its name. Each gets one Switch Mode, from a right-click on its own Mode 1. Its Event list gives your collision Event as While Hitting Anything Tagged Asteroid · Ship Crash. Why Ship Crash? It isn’t on an Object yet, so its own name follows the dot. Pick it. Then pick Shielded in the Mode list, or Exposed for shieldDown.

Now attach Ship Crash to the Ship, below Ship Hyperspace, and its four Shared Variables join the Ship’s under Variables, at the card’s numbers. There’s nothing to type, and the Ship’s Changes card, at the end of The shield, lists none of them.

Nothing sends shieldUp or shieldDown yet, so until Ship Shield does, two parts from now, the sign stays on Exposed.

One quiet problem hides in Thrust Feedback. Hold Up as you crash. The Ship is gone, but the Thrust hum goes on and on. A looping sound doesn’t stop when its Object does. And the Released Event that stops it belonged to a Ship that isn’t there anymore.

So Thrust Feedback gets one more Event, Destroy. It runs once, as the Ship is removed, and stops the Thrust sound. Type Destroy into the Add Event window’s filter, and pick Destroy itself, above shipDestroyed. No second window opens, and Myth names it When Destroyed. Its Control Sound goes in from a right-click on its Mode 1. Pick Stop in the Operation list, and Thrust in the Sound list, as in Chapter 1. The rest is unchanged.

Logic ComponentThrust FeedbackAttach to: ShipAddDelete

While Up is held the Ship shows its thrust flame and the thrust sound loops.

Attach toAny Object
While Command Rotate and Thrust Controls Up Is Held
When2D Direction HeldCommand: Rotate-and-thrust ControlsDirection: Up
ModeCoasting (Starting Mode)
1Set Animation Clip
Clip
"Ship Sprite/Thrust"
2Control Sound
Operation
Loop
Sound
"Thrust"
3Switch Mode
Event
While Command Rotate and Thrust Controls Up Is Held
Mode
Thrusting
While Command Rotate and Thrust Controls Up Is Held
When2D Direction HeldCommand: Rotate-and-thrust ControlsDirection: Up
ModeThrusting
(no Actions)
When Command Rotate and Thrust Controls Up Is Released
When2D Direction ReleasedCommand: Rotate-and-thrust ControlsDirection: Up
1Set Frame
Frame
0
2Control Sound
Operation
Stop
Sound
"Thrust"
3Switch Mode
Event
While Command Rotate and Thrust Controls Up Is Held
Mode
Coasting
When Destroyed
WhenDestroy
1Control Sound
Operation
Stop
Sound
"Thrust"

Run the game, and fly into a rock.

The Ship bursts. The rock breaks under it, both sounds play, the screen shakes, and the Ship is gone. That’s all. Nothing comes back. The rocks drift on without you, as if nothing happened. Stop the game.

5.5 Another Ship

Now the game learns to give you another Ship.

5.5.1 Lives and Respawn

The count of lives belongs to the whole game, in the Global Variable lives. The Logic that looks after it goes on Game Rules. Game Rules is never destroyed, so it’s still there 2.4 seconds after a crash, when the next Ship is due.

Lives and Respawn waits for three moments. The first is Game Start, when the whole game begins, and right then $lives goes from 0 to startLives, 3.

The second moment is shipDestroyed, the news from Ship Crash. One life comes off, and an If asks whether any are left. If they are, a timer named respawnDelay starts, and it rings once, 2.4 seconds later. If none are left, nothing starts, and no Ship comes.

The third moment is that timer ringing. A new Ship appears in the middle of the screen, where the first one started, and the Ship Respawn sound plays.

Lives and Respawn never names the Ship itself. Its Object to Create is @self.ship, a Shared Variable that holds an Object, and Game Rules sets it to Ship.

Logic ComponentLives and RespawnAttach to: Game Rules

The game starts with startLives; each lost Ship costs one, and a new Ship comes after respawnSeconds while lives are left.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
shipObjectConstantNone
startLivesNumberConstant3
respawnSecondsNumberConstant2.4
When the Game Starts
WhenGame Start
1Change Variable
Variable
$lives
Value
@self.startLives
On Ship Destroyed
WhenshipDestroyedCustom Event
1Change Variable
Variable
$lives
Operator
-=
Value
1
2If$lives > 0
Then
3Start Recurring Timer
Timer Name
respawnDelay
Repeat Every (s)
@self.respawnSeconds
Ring Once
Yes
On the Respawn Delay Timer
WhenRecurring TimerTimer name: respawnDelay
1Create Instance
Object to Create
@self.ship
X
$areaWidth / 2
Y
$areaHeight / 2
Created As
newShip
2Control Sound
Sound
"Ship Respawn"

Make it like Ship Crash, its SHARED VARIABLES first, each one Constant. The first, ship, holds an Object, the way shot did in Chapter 2. Pick Object, far down the Type list, and leave its Starting Value, a button, at None. Game Rules fills it in. The other two, startLives and respawnSeconds, are Numbers.

Game Start is in the Add Event window’s filter, with no second window, and Myth names it When the Game Starts. Its Change Variable takes $lives in the Variable box, dollar sign and all. Its Value is @self.startLives.

shipDestroyed is already waiting in the Add Event window, because Ship Crash sends it. Type Destroy into the filter, and it’s there below Destroy. Its Change Variable takes one life away, and the card writes that as -= 1. Click the = on its block, pick -= · Subtract in the list, and type 1 into its Value.

The If works as in Chapter 4. Its condition is the one box on the If, so type $lives > 0 there. Start Recurring Timer goes on its True line, with Add inside Then, and joins it with Connect to sequence. Type its Timer Name bare, respawnDelay, then @self.respawnSeconds, and pick Yes in Ring Once.

For the third Event, type Recurring Timer into the filter. Two windows follow. In the first, pick Type a timer name…. In the second, type respawnDelay. Its block then reads Whenever the named respawnDelay timer fires.

In Create Instance, Object to Create is a list, with @self.ship in it. Position Relative To stays on World, where it starts. X and Y are small formulas. Type $areaWidth / 2 into X, half the screen’s width, and $areaHeight / 2 into Y. Created As already holds a name of Myth’s, so type newShip over it, as the card has it.

Control Sound has no Applies To, so the Create Instance before it changes nothing there. Pick Ship Respawn in its Sound list.

Make Game Rules with Add > Object, as an Empty Object, and attach Lives and Respawn. Then switch back to Components. Under Variables, ship’s Value is a button that reads None. Press it, and pick Ship. startLives and respawnSeconds keep the card’s 3 and 2.4, so the card lists only ship.

ObjectGame Rules
Logic
Lives and Respawn
Shared Variables
shipShip

Now place Game Rules, from PLACE THESE. With Place on, pick Game Rules under Predefined Objects, and click anywhere in the preview. It has no picture, so nothing shows there. But it’s in the Scene Explorer, the list on the right, under Objects. Pick Select, click Game Rules in that list, and type 0 and 24 into its World Position, the top left corner. It has to be in the Scene for its Logic to run.

Run the game, and crash.

The Ship bursts and is gone, and for 2.4 seconds the field is empty. At last the Ship Respawn sound plays, and a new Ship sits in the middle of the screen.

Now crash with Up held, and keep holding. The new Ship arrives with its flame already lit, humming and pushing forward from its first moment. Chapter 1 promised you this. That Ship never saw you press Up. But its sign starts on Coasting, like every new Ship’s. Coasting is Thrust Feedback’s answer for a Ship that isn’t thrusting yet, so it’s the one that lights the flame, starts the hum and turns the sign to Thrusting. With Up held, it does all that on the Ship’s very first step.

Crash once more. After the third crash, nothing comes back.

Did a new Ship appear right on top of a rock, and burst at once? That’s the next part.

5.6 The Shield

Now a new Ship gets a moment to breathe.

5.6.1 Ship Shield

A new Ship is shielded for shieldSeconds, 3 seconds, and it blinks the whole time. Ship Shield never turns Ship Crash’s sign itself. It sends two messages to its own Ship, and Ship Crash does the turning.

Everything starts in a Create Event. That runs for every new Ship, and for the one you placed at the start too. The Ship hears shieldUp, and its sign turns to Shielded. Two timers start. shieldBlink rings every blinkSeconds, 0.1 seconds, ten times a second. shieldTime rings once, when the shield is over.

The blink is a swap, and a swap needs a memory. Between one ring and the next, Ship Shield has to remember whether the Ship is see-through right now. It keeps that in a Data Structure, a small form of named fields that the Ship carries. This one is Ship Shield Data, with one field, isFaded, true or false.

Why not one more Shared Variable? Those are the Ship’s settings, the numbers you tune. isFaded changes ten times a second while the game runs. It’s Ship Shield’s own note to itself, and the form keeps it from one Event to the next.

Each time shieldBlink rings, an If looks at isFaded. When it’s true, the Ship turns solid again, and isFaded becomes false. Otherwise the Ship fades to fadedAlpha, 0.25, a quarter of its solid self, and isFaded becomes true. Solid, faint. Solid, faint.

When shieldTime rings, the blinking stops. The Ship is left solid, whichever way the last blink went, and shieldDown turns its sign back to Exposed.

The form comes first, because Ship Shield picks it from a list. Here is its card.

Data StructureShip Shield Data

Object Data of Logic "Ship Shield" (its state that lasts between Events).

isFadedBooleandefault false

Make it with Add > Data Structure. The Create Data Structure window asks only for its Name. Press Add Field, type isFaded over the field’s name, and pick Boolean in its Type list. Its Value turns into No, the card’s false. The passage on Data Structure cards has the rest.

Now Ship Shield itself.

Logic ComponentShip ShieldAttach to: Ship

A new Ship is shielded for shieldSeconds: it cannot crash, and it blinks.

Attach toAny Object
DATA STRUCTURES
Ship Shield Dataself.shipShieldData
SHARED VARIABLES
NameTypeKindStarting Value
shieldSecondsNumberConstant3
blinkSecondsNumberConstant0.1
fadedAlphaNumberConstant0.25
When Created
WhenCreate
1Trigger Custom Event on Object
Custom Event
shieldUp
2Start Recurring Timer
Timer Name
shieldBlink
Repeat Every (s)
@self.blinkSeconds
3Start Recurring Timer
Timer Name
shieldTime
Repeat Every (s)
@self.shieldSeconds
Ring Once
Yes
On the Shield Blink Timer
WhenRecurring TimerTimer name: shieldBlink
1Ifself.shipShieldData.isFaded == true
Then
2Set Alpha
3Change Component Value
Component Value
self.shipShieldData.isFaded
Value
false
4Otherwise
5Set Alpha
Alpha
@self.fadedAlpha
6Change Component Value
Component Value
self.shipShieldData.isFaded
Value
true
On the Shield Time Timer
WhenRecurring TimerTimer name: shieldTime
1Stop Recurring Timer
Timer Name
shieldBlink
2Set Alpha
3Trigger Custom Event on Object
Custom Event
shieldDown

Make Ship Shield like Ship Crash, with its three Shared Variables first, Numbers, each Constant. Then press the + on its Data Structures card, and pick Ship Shield Data under Existing Data Structures. The card’s row shows the name Myth gives it here, self.shipShieldData. Every box reads the field through that name.

The Create Event opens no second window. In Trigger Custom Event on Object, Applies To stays on Self, the Ship, and you type shieldUp into its Custom Event box. Both Start Recurring Timers take their Timer Names bare. The first leaves Ring Once on No, where it starts, and the second gets Yes. Each timer’s Event takes the same two windows as respawnDelay’s.

The If’s condition is its one box. Type self.shipShieldData.isFaded == true there.

Set Alpha comes first on the True line, with Add inside Then. Its Alpha starts at 1. That’s fully solid, so the card has no line under it. After it comes Change Component Value, from Add inside Then too, and its Component Value box takes the field’s whole path. Type self.shipShieldData.isFaded, and press Enter. Two more parts appear on the block, an = and a Value that already reads false. That’s the card’s false, so leave it.

Next, right-click the If and choose Add Else, and the Else appears beside it, on a line marked False. Its two Actions come from a right-click on the Else, with Add inside Else, and each joins with Connect to sequence. Set Alpha’s Alpha is @self.fadedAlpha. The Change Component Value takes the same path, and its Value is true. Type it over the false.

In the shieldTime Event, Set Alpha has no line on the card either. Leave its Alpha at the 1 it starts with.

Attach Ship Shield to the Ship, below Ship Crash, and its Shared Variables join the Ship’s at the card’s numbers. Something else comes with it. Under Attached Components, a Data Structures group now holds Ship Shield Data, the Ship’s own copy of the form. On the Ship’s Changes card, that’s the Data Structure line, From Logic Ship Shield. It’s green there, beside Ship Crash and Ship Shield.

ObjectShipAddDelete
Transform
Bounding Box > SizeX 2.4375, Y 3.0625
Collider
Shape and Transform > ShapeCircle
Shape and Transform > Radius0.594
Tags and Interactions > InteractionsCollide Only With
Tags and Interactions > Collide Only WithTagged Asteroid
Sprite
Scene Depth Draw Order20
SpriteShip Sprite
Transform > SizeX 2.4375, Y 3.0625
Data Structure
From LogicShip Shield
Data StructureShip Shield Data
Logic
Rotate-and-thrust Controls
Wrap Around World
Thrust Feedback
Ship Gun
Random Teleport
Ship Hyperspace
Ship Crash
Ship Shield
Shared Variables
topSpeed13.75
turnSpeed290
thrust13.125
coastDrag1.719
shotShot
maximumX > KindExpression
maximumX > Expression$areaWidth
minimumY0
maximumY > KindExpression
maximumY > Expression$areaHeight

Run the game. The Ship blinks in the middle of the screen from the very start. Fly it into a rock while it blinks, and it slides through. Wait. When the blinking stops, try again.

5.7 Lives in the Corner

Last, the game shows you how many lives you have left.

5.7.1 Show Life Icon

Five tiny ships sit in a row in the top left corner. Each one is an Object of its own, Life Icon 1 to Life Icon 5, and each has a number, its slot, from 1 to 5. An icon shows while you have at least that many lives. With three lives, icons 1, 2 and 3 show. Icons 4 and 5 wait out of sight, for the extra Ships Chapter 7 brings.

Four things in this part share one name, and it helps to tell them apart. Life Icon Sprite is the picture, and Life Icon 1 to 5 are the Objects that wear it. Life Icon, with no number, is the Logic Component they all run. And Show Life Icon is the rule they ask.

The rule itself is a Function, a small piece of Logic that does one job when it’s asked. Why not put it inside Life Icon? Life Icon asks from two Events, and a Function writes the rule once for both. Whoever asks hands it two things: an icon, and that icon’s slot. It compares the slot with $lives. The answer shows the icon, or hides it.

FunctionShow Life Icon

Shows the icon while the player has at least slot lives, and hides it otherwise.

PARAMETERS
NameTypeStarts at
iconObject
slotNumber1
ACTIONS
1If$lives >= slot
Then
2Set Visible
Applies To
icon
Visible
true
3Otherwise
4Set Visible
Applies To
icon
Visible
false

Make it with Add > Function, and the Create Function window asks only for its Name. The passage on Function cards has the rest.

Its PARAMETERS go on its Start block, with the + beside Parameters. The first, icon, holds an Object. In the Add Parameter window, type icon, and pick the Object near the very end of the Type list. The second, slot, is a Number, with a Default of 1.

There’s no Event. The canvas runs from Start to End. The If goes in from a right-click on Start, with Add unattached Action here, and joins the line with Connect to sequence. Its condition is its one box: $lives >= slot.

Set Visible goes on the True line, with Add inside Then. Its Applies To already reads icon, because in a Function that list holds the Function’s own Object Parameters. Its Visible is a Yes or No list, and it starts on No. The card’s true is Yes, so pick Yes.

The Else’s Set Visible comes from Add Else and Add inside Else, as in Ship Shield. Check that it reads icon, and leave its Visible on No, the card’s false.

5.7.2 Life Icon

Show Life Icon does nothing until someone asks it, and the Logic Component Life Icon asks at two moments.

The first is Create, when the icon appears. The second is a new kind of Event, Variable Changed, with the Global Variable lives in its When bar. It runs once, at the end of any step in which $lives changed. So an icon looks again only when there’s news.

Why both? Remember the 0 that $lives starts at? Game Start runs before any Object’s Create, so the lives are already 3 when the icons appear. The game’s first step ends at 3, and Variable Changed never sees a change. So Create is what sets the icons right at the start. Leave it out, and all five tiny ships sit in the corner until your first crash.

Both Events make the same call. Each one hands Show Life Icon this very icon, as icon, and its own number, as slot.

Logic ComponentLife IconAttach to: Life Icon 1, Life Icon 2, Life Icon 3, Life Icon 4, Life Icon 5

This reserve-ship icon shows while the player has at least slot lives.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
slotNumberConstant1
When Created
WhenCreate
1Show Life IconFunction
icon
self
slot
@self.slot
On Variable Changed · Lives
WhenVariable ChangedGlobal Variable: lives
1Show Life IconFunction
icon
self
slot
@self.slot

Its one Shared Variable, slot, is a Number, Constant, with a Starting Value of 1. Each icon sets its own.

To make the second Event, type Variable Changed into the Add Event window’s filter. A second window lists the Global Variables. Pick lives, and Myth names the Event On Variable Changed · Lives.

The call comes from the Action List’s Functions group, and the search box finds it if you type Show Life. Its two fields carry the Function’s own names. The icon list starts on self, the Object this Logic is on, and that’s the card’s self. Leave it. Type @self.slot into the slot box.

5.7.3 The Icons

Each icon is an Empty Object with one Sprite. Its picture is the Life Icon Sprite, but in the Add Sprite Component window, the Sprite list starts on the first picture, Ship Sprite. So pick Life Icon Sprite before you press Add Sprite. Its Draw Order is 900, far above the Ship’s 20, so a rock drifting through the corner passes behind the icons.

Make Life Icon 1 from its card, with Life Icon attached. Under Variables, its slot arrives at 1. That’s already right, so its card has no line for it.

ObjectLife Icon 1
Transform
Bounding Box > SizeX 0.875, Y 0.875
Sprite
Scene Depth Draw Order900
SpriteLife Icon Sprite
Transform > SizeX 0.875, Y 0.875
Logic
Life Icon

The other four are copies. Right-click Life Icon 1 in the Resources and choose Duplicate, four times over. Myth gives each copy the next free number, so they come out as Life Icon 2, 3, 4 and 5, the names on their cards. Each copy still has slot 1, so change that one Value under Variables. Here’s Life Icon 2. The other three match it, each with its own number in slot.

ObjectLife Icon 2
Transform
Bounding Box > SizeX 0.875, Y 0.875
Sprite
Scene Depth Draw Order900
SpriteLife Icon Sprite
Transform > SizeX 0.875, Y 0.875
Logic
Life Icon
Shared Variables
slot2

Now place all five, from PLACE THESE, in a row near the top, a little less than a meter apart. Find each one in the preview or in the Scene Explorer, and type its X and Y as the card has them.

Run the game. Three tiny ships sit in the corner, and when you crash, the third goes out.

Play it!

Watch for each of these. A rock or two drifting near the middle will help.

  • The game starts with three icons in the top left corner, and the Ship blinking in the middle.
  • While it blinks, the Ship passes through rocks unharmed. After 3 seconds, the blinking stops.
  • Now a rock that touches the Ship breaks. The Ship explodes in white, cyan and gold, both sounds play, and the screen shakes hard.
  • One icon goes out.
  • 2.4 seconds later, a new Ship appears in the middle, blinking, with the Ship Respawn sound.
  • Hold Up as you crash, and the Thrust hum stops with the Ship.
  • Keep holding Up until the next Ship comes. It arrives with its flame lit and the hum on, already moving.
  • Fly a blinking Ship onto a rock, and keep it there. That’s fiddly, so give it a few tries. The moment the blinking stops, the Ship bursts apart in the middle of the rock.
  • After the third crash, the last icon goes out and no Ship comes. The rocks drift on alone.
How it works

Ship Crash breaks the Ship and tells the game. Lives and Respawn counts, and sends another Ship while any lives are left. Ship Shield buys each new Ship 3 seconds. And the tiny ships in the corner show how many lives are left.

Underneath them is a way for two pieces of Logic to work together without reaching into each other. Ship Shield never touches Ship Crash’s sign. It only says when, and Ship Crash does the rest. One sends the news. The other decides what it means.

5.8 If It Didn’t Work

Something may be a little off the first time, and that’s normal. Run the game, watch what the Ship does, and take it one piece at a time.

The Ship flies through rocks and never crashes? Perhaps Ship Crash isn’t attached, or its sign is stuck on Shielded. Look in Ship Shield’s shieldTime Event for the Trigger Custom Event on Object that sends shieldDown. If it’s there, check that Ship Crash’s shieldDown Event turns the sign to Exposed. One more place to look is the Ship’s Collider. Its Collide Only With list needs Tagged Asteroid, as Chapter 4 left it.

Still no crash? Follow the lines on Ship Crash’s canvas. Exposed’s line should hold all eight Actions, and Shielded’s none. An Action on the wrong line went in from the other Mode’s right-click. Right-click it, choose Delete, and add it again from Exposed’s line, in the card’s order.

The Ship crashes while it’s still blinking? Ship Crash’s shieldUp Event should turn the sign to Shielded, and Shielded should have no Actions at all.

The Errors bar counts an error in Ship Shield? Look at the If’s box and at both Change Component Values. Each path should read self.shipShieldData.isFaded, spelled as the card spells it. If the spelling is right, check that Ship Shield Data is on Ship Shield’s Data Structures card.

No new Ship ever comes, and no icons show? Game Rules may not be in the Scene, and its Logic only runs there. Look for it in the Scene Explorer of Space, under Objects.

The icons work, but no new Ship ever comes? Open Game Rules, and look under Variables. ship’s Value should read Ship, not None. If it does, perhaps the timer rings for nobody. The Timer Name in Start Recurring Timer and the name on the Recurring Timer’s block must be the same word, respawnDelay. And Ring Once should be Yes, so the timer rings once for each crash.

The Thrust hum goes on after a crash? Look at Thrust Feedback’s Destroy Event. Its Control Sound should be joined, with Stop in its Operation list.

The new Ship never blinks, though rocks still pass through it for 3 seconds? Look at the shieldBlink Event. The Set Alpha on its False line should have @self.fadedAlpha as its Alpha. Left at 1, both answers make the Ship solid. If it’s right, check the timer’s name: the first Start Recurring Timer and the shieldBlink Event’s block must both say shieldBlink.

The Ship stays faint after the blinking stops? Look at the Set Alpha in the shieldTime Event, its step 2. Its Alpha should be 1.

The icons wear the Ship’s picture? The Add Sprite Component window kept its first picture. Select Sprite in each icon’s Attached Components, and pick Life Icon Sprite in its Sprite list.

The icons never change? Look at Life Icon’s second Event. Its When bar should be Variable Changed, with lives as its Global Variable. Then check Show Life Icon. Both its Set Visibles should apply to icon, and the one on the True line should be Yes.

Each of these is a small fix. Make it, run the game again, and you’re back with the chapter. The catch-up download in the Goal is this chapter, finished, if you’d like to compare.

Challenge

How forgiving should Shatterfield be? Open Game Rules, and under Variables, type 5 into startLives. The whole row of icons lights up. On the Ship, stretch Ship Shield’s shieldSeconds, and a new Ship gets a long, safe start. Or make the blink quicker or slower, with blinkSeconds. Find the pace that feels right to you. Chapter 6 starts from the cards’ numbers, so write down any of yours you’d like to keep. Then set them back: 3 lives, 3 seconds, and 0.1 for the blink.

Still stuck? Search the manual, or ask in the Myth Engine Discord (opens a new tab).

A Ship that can be lost. Lives to try again. Next, the field becomes a sector, and the rocks come in waves.