Build a GameCreating Shatterfield

Appendix A — Logic Reference

Every Logic Component and Function in Shatterfield, as it is in the finished game. Each entry stands on its own: read what it does, see what it needs, and build it from its card into your own game. A card’s Shared Variables and Per Instance Variables are the values you can change. A Shared Variable holds one value for the whole Object, under Variables in its Properties. A Per Instance Variable holds one for each placement in the Scene.

A.1 Rotate-and-Thrust Controls

Comes whole from Myth’s templates. Built in Chapter 1, The Ship Flies.

Logic ComponentRotate-and-thrust ControlsAttach to: Ship

Left and Right turn the Ship and Up thrusts it forward; it keeps its momentum, slowing by coastDrag, up to topSpeed.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
topSpeedNumberConstant6.875
turnSpeedNumberConstant260
thrustNumberConstant9.688
coastDragNumberConstant0
Built in: this Logic Component comes whole from the engine's template.
You add it and set its Variables on the Object; you do not build its Events.

A.2 Thrust Feedback

Built in Chapter 1, The Ship Flies.

Logic ComponentThrust FeedbackAttach to: Ship

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"
On Game Paused
WhengamePausedCustom Event
1Control Sound
Operation
Stop
Sound
"Thrust"
On Game Resumed
WhengameResumedCustom Event
1Set Frame
Frame
0
2Switch Mode
Event
While Command Rotate and Thrust Controls Up Is Held
Mode
Coasting

A.3 Wrap Around World

Comes whole from Myth’s templates. Built in Chapter 1, The Ship Flies.

Logic ComponentWrap Around WorldAttach to: Ship, Shot, Asteroid Large, Asteroid Medium, Asteroid Small, Saucer Orb, Saucer Lance, Title Asteroid

An Object that leaves the screen comes back at the opposite edge, drawn across the edge while it passes.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
seamlessEdgesBooleanConstantYes
Built in: this Logic Component comes whole from the engine's template.
You add it and set its Variables on the Object; you do not build its Events.

A.4 Motion Facing

Comes whole from Myth’s templates. Built in Chapter 2, Shots.

Logic ComponentMotion FacingAttach to: Shot

The Object turns to point the way it is moving.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
facingOffsetNumberConstant0
Built in: this Logic Component comes whole from the engine's template.
You add it and set its Variables on the Object; you do not build its Events.

A.5 Ship Gun

Built in Chapter 2, Shots.

Logic ComponentShip GunAttach to: Ship

Fire launches a Shot from the Ship's nose, with a cooldown and a limit on Shots in flight.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
shotObjectConstantNone
shotSpeedNumberConstant20
muzzleDistanceNumberConstant1.188
fireCooldownSecondsNumberConstant0.11
maxShotsNumberConstant4
When Fire Is Pressed
WhenCommand PressedCommand: Fire
1Check Cooldown Ready
Action Name
isGunReady
Cooldown Key
fireCooldown
2Check Instance Count
Action Name
hasRoomForShot
Object
@self.shot
Operator
<
Value
@self.maxShots
3IfisGunReady.value == true && hasRoomForShot.value == true
Then
4Create Instance
Object to Create
@self.shot
Position Relative To
Self
Y
@self.muzzleDistance
Launch Speed
@self.shotSpeed
Launch Angle
90
Angle Relative To
Creator
Created As
newShot
5Control Sound
Sound
"Fire"
6Start Cooldown
Cooldown Key
fireCooldown
Seconds
@self.fireCooldownSeconds

A.6 Shot Lifetime

Built in Chapter 2, Shots.

Logic ComponentShot LifetimeAttach to: Shot

A Shot disappears lifeSeconds after it is fired.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
lifeSecondsNumberConstant0.85
When Created
WhenCreate
1Start Recurring Timer
Timer Name
shotLife
Repeat Every (s)
@self.lifeSeconds
Ring Once
Yes
On the Shot Life Timer
WhenRecurring TimerTimer name: shotLife
1Destroy Instance

A.7 Random Teleport

Comes whole from Myth’s templates. Built in Chapter 3, Hyperspace.

Logic ComponentRandom TeleportAttach to: Ship

Moves the Ship to a random place in the play area whenever it hears randomTeleport.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
minimumXNumberConstant0
maximumXNumberConstant25
minimumYNumberConstant5.25
maximumYNumberConstant24
Built in: this Logic Component comes whole from the engine's template.
You add it and set its Variables on the Object; you do not build its Events.

A.8 Ship Hyperspace

Built in Chapter 3, Hyperspace.

Logic ComponentShip HyperspaceAttach to: Ship

Hyperspace jumps the Ship to a random place on screen and stops it, at most once every cooldownSeconds.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
cooldownSecondsNumberConstant1.2
sparkCountNumberConstant36
When Hyperspace Is Pressed
WhenCommand PressedCommand: Hyperspace
1Check Cooldown Ready
Action Name
isHyperspaceReady
Cooldown Key
hyperspaceCooldown
2IfisHyperspaceReady.value == true
Then
3Burst Particles
Particles
"Impact Sparks"
Count
@self.sparkCount
4Control Sound
Sound
"Hyper"
5Trigger Custom Event on Object
Custom Event
randomTeleport
6Set Velocity
X Velocity
0
Y Velocity
0
7Burst Particles
Particles
"Impact Sparks"
Count
@self.sparkCount
8Start Cooldown
Cooldown Key
hyperspaceCooldown
Seconds
@self.cooldownSeconds

A.9 Asteroid Drift

Built in Chapter 4, Asteroids.

Logic ComponentAsteroid DriftAttach to: Asteroid Large, Asteroid Medium, Asteroid Small, Title Asteroid

A new Asteroid starts on a random tumble pose and turn, spins, and drifts in a random direction.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
minSpeedNumberConstant1.406
maxSpeedNumberConstant2.656
maxSpinNumberConstant55
waveNumberConstant1
speedUpPerWaveNumberConstant0.07
speedUpLastWaveNumberConstant9
When Created
WhenCreate
1Declare Variable
Name
waveSpeedUp
Value
1
2Declare Variable
Name
speedUpWave
Value
1
3Generate Random Integer
Action Name
poseNumber
Maximum
7
4Set Frame
Frame
poseNumber.value * 4
5Generate Random Number
Action Name
turnDegrees
Maximum
359
6Set Rotation
Degrees
turnDegrees.value
7Generate Random Number
Action Name
spinSpeed
Minimum
-@self.maxSpin
Maximum
@self.maxSpin
8Set Spin
Spin
spinSpeed.value
9Generate Random Number
Action Name
headingDegrees
Maximum
359
10Set Direction
Direction
headingDegrees.value
11Generate Random Number
Action Name
driftSpeed
Minimum
@self.minSpeed
Maximum
@self.maxSpeed
12Change Variable
Variable
speedUpWave
Value
@self.wave
13If@self.wave > @self.speedUpLastWave
Then
14Change Variable
Variable
speedUpWave
Value
@self.speedUpLastWave
15Change Variable
Variable
waveSpeedUp
Value
1 + @self.speedUpPerWave * (speedUpWave - 1)
16Set Speed
Speed
driftSpeed.value * waveSpeedUp

A.10 Break Apart

Built in Chapter 4, Asteroids.

Logic ComponentBreak ApartAttach to: Asteroid Large, Asteroid Medium, Asteroid Small

An Asteroid hit by the player scores and shows its points; any Asteroid that breaks up bursts into sparks, plays its break sound, leaves its fragments and is destroyed.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
pointsNumberConstant20
sparkCountNumberConstant34
shakeNumberConstant0.012
shakeSecondsNumberConstant0.18
popupColorColorConstant#dff6ff
popupSizeNumberConstant0.469
popupRiseNumberConstant0.813
popupSecondsNumberConstant0.55
breakSoundSoundConstantExplosionLarge
fragmentObjectConstantNone
fragmentsNumberConstant2
On Hit
WhenhitCustom Event
1Check Game State
Action Name
isPlaying
Game State
Playing
2IfisPlaying.value == true
Then
3Change Variable
Variable
$score
Operator
+=
Value
@self.points
4Trigger Custom Event
Custom Event
scored
5Popup Text
Text
text(@self.points)
Color
@self.popupColor
Size
@self.popupSize
Rise
@self.popupRise
Seconds
@self.popupSeconds
6Trigger Custom Event on Object
Custom Event
breakUp
On Break Up
WhenbreakUpCustom Event
1Burst Particles
Particles
"Impact Sparks"
Count
@self.sparkCount
2Control Sound
Sound
@self.breakSound
3If@self.shake > 0
Then
4Camera Shake
Intensity
@self.shake
Seconds
@self.shakeSeconds
5Repeat@self.fragmentstimes
Each time
6Create Instance
Object to Create
@self.fragment
Position Relative To
Self
Created As
newFragment
7Destroy Instance

A.11 Shot Impact

Built in Chapter 4, Asteroids.

Logic ComponentShot ImpactAttach to: Shot

A Shot that touches an Asteroid tells the Asteroid it was hit and disappears.

Attach toAny Object
When Starting to Hit Anything
WhenCollision Enter
1Trigger Custom Event on Object
Applies To
other
Custom Event
hit
2Destroy Instance

A.12 Life Icon

Built in Chapter 5, Crash and Lives.

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

A.13 Lives and Respawn

Built in Chapter 5, Crash and Lives.

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 Enabled
WhenOn Enable
1Change Variable
Variable
$lives
Value
@self.startLives
2Trigger Custom Event on Object
Custom Event
spawnShip
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
4Otherwise
5Set Game State
Game State
Game Over
On the Respawn Delay Timer
WhenRecurring TimerTimer name: respawnDelay
1Trigger Custom Event on Object
Custom Event
spawnShip
On Spawn Ship
WhenspawnShipCustom Event
1Create Instance
Object to Create
@self.ship
X
$areaWidth / 2
Y
$areaHeight / 2
Created As
newShip
2Control Sound
Sound
"Ship Respawn"

A.14 Ship Crash

Built in Chapter 5, Crash and Lives.

Logic ComponentShip CrashAttach to: Ship

Touching an Asteroid, a saucer or a saucer shot destroys the Ship: it tells what it touched that it was hit, explodes, and reports shipDestroyed. While the Ship is shielded, a touch does nothing and nothing can push it.

Attach toAny Object
COMPONENTS
self.colliderCollider
SHARED VARIABLES
NameTypeKindStarting Value
explosionCountNumberConstant90
crashSparkCountNumberConstant40
shakeNumberConstant0.022
shakeSecondsNumberConstant0.45
While Hitting Anything
WhenCollision
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
WhenCollision
ModeShielded
(no Actions)
On Shield Up
WhenshieldUpCustom Event
1Switch Mode
Event
While Hitting Anything
Mode
Shielded
2Change Component Value
Component Value
self.collider
Value
true
Property
trigger
On Shield Down
WhenshieldDownCustom Event
1Change Component Value
Component Value
self.collider
Value
false
Property
trigger
2Switch Mode
Event
While Hitting Anything
Mode
Exposed

A.15 Ship Shield

Built in Chapter 5, Crash and Lives.

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

A.16 Show Life Icon (Function)

Built in Chapter 5, Crash and Lives.

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

A.17 Asteroid Material

Built in Chapter 6, Waves.

Logic ComponentAsteroid MaterialAttach to: Asteroid Large, Asteroid Medium, Asteroid Small, Title Asteroid

A new Asteroid uses the sprite of the current wave's material, from the Asteroid Materials Data Table.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
waveNumberConstant1
When Created
WhenCreate
1Declare Variable
Name
materialRow
Value
0
2Change Variable
Variable
materialRow
Value
(@self.wave - 1) % dataCount("Asteroid Materials")
3Set Sprite
Sprite
data("Asteroid Materials", materialRow, "sprite")

A.18 Create Asteroids Along Edges (Function)

Built in Chapter 6, Waves.

FunctionCreate Asteroids Along Edges

Creates perBand Asteroids in bands along the top and bottom edges and as many along the left and right edges.

PARAMETERS
NameTypeStarts at
creatorObject
asteroidObject
perBandNumber1
edgeBandNumber3.438
sideBandNumber4.688
ACTIONS
1RepeatperBandtimes
Each time
2Generate Random Number
Action Name
acrossX
Maximum
$areaWidth
3Generate Random Number
Action Name
depthIntoEdgeBand
Maximum
edgeBand
4Generate Random Integer
Action Name
edgeRoll
Maximum
1
5IfedgeRoll.value == 0
Then
6Create Instance
Applies To
creator
Object to Create
asteroid
X
acrossX.value
Y
depthIntoEdgeBand.value
Created As
bottomAsteroid
7Otherwise
8Create Instance
Applies To
creator
Object to Create
asteroid
X
acrossX.value
Y
$areaHeight - depthIntoEdgeBand.value
Created As
topAsteroid
9RepeatperBandtimes
Each time
10Generate Random Number
Action Name
upY
Maximum
$areaHeight
11Generate Random Number
Action Name
depthIntoSideBand
Maximum
sideBand
12Generate Random Integer
Action Name
sideRoll
Maximum
1
13IfsideRoll.value == 0
Then
14Create Instance
Applies To
creator
Object to Create
asteroid
X
depthIntoSideBand.value
Y
upY.value
Created As
leftAsteroid
15Otherwise
16Create Instance
Applies To
creator
Object to Create
asteroid
X
$areaWidth - depthIntoSideBand.value
Y
upY.value
Created As
rightAsteroid

A.19 Waves

Built in Chapter 6, Waves.

Logic ComponentWavesAttach to: Game Rules

Each wave announces itself with the banner, then brings its Large Asteroids; clearing every Asteroid starts the sector jump and then the next wave.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
asteroidObjectConstantNone
bannerObjectConstantNone
bannerSecondsNumberConstant1.6
jumpSecondsNumberConstant1.4
maxAsteroidsPerBandNumberConstant6
edgeBandNumberConstant3.438
sideBandNumberConstant4.688
When Enabled
WhenOn Enable
1Change Variable
Variable
$wave
Value
0
2Trigger Custom Event
Custom Event
nextWave
On Next Wave
WhennextWaveCustom Event
1Change Variable
Variable
$wave
Operator
+=
Value
1
2Set Visible
Applies To
@self.banner
Visible
Yes
3Start Recurring Timer
Timer Name
bannerTime
Repeat Every (s)
@self.bannerSeconds
Ring Once
Yes
On the Banner Time Timer
WhenRecurring TimerTimer name: bannerTime
1Declare Variable
Name
perBandThisWave
Value
1
2Set Visible
Applies To
@self.banner
Visible
No
3Change Variable
Variable
perBandThisWave
Value
$wave + 1
4IfperBandThisWave > @self.maxAsteroidsPerBand
Then
5Change Variable
Variable
perBandThisWave
Value
@self.maxAsteroidsPerBand
6Create Asteroids Along EdgesFunction
creator
self
asteroid
@self.asteroid
perBand
perBandThisWave
edgeBand
@self.edgeBand
sideBand
@self.sideBand
7Trigger Custom Event
Custom Event
waveStarted
On No Instances Left · Anything Tagged Asteroid
WhenNo Instances LeftObject: tag:Asteroid
1Control Sound
Sound
"Sector Clear"
2Control Sound
Sound
"Hyper"
3Start Recurring Timer
Timer Name
sectorJump
Repeat Every (s)
@self.jumpSeconds
Ring Once
Yes
4Trigger Custom Event
Custom Event
waveCleared
On the Sector Jump Timer
WhenRecurring TimerTimer name: sectorJump
1Trigger Custom Event
Custom Event
nextWave
When Disabled
WhenOn Disable
1Stop Recurring Timer
Timer Name
bannerTime
2Stop Recurring Timer
Timer Name
sectorJump
3Set Visible
Applies To
@self.banner
Visible
No

A.20 Extra Ships

Built in Chapter 7, Score.

Logic ComponentExtra ShipsAttach to: Game Rules

Each time the score passes another extraShipEvery points, the player gains a life, with a sound and an "EXTRA SHIP" popup.

Attach toAny Object
DATA STRUCTURES
Extra Ships Dataself.extraShipsData
SHARED VARIABLES
NameTypeKindStarting Value
extraShipEveryNumberConstant10000
popupAboveCenterNumberConstant3.75
popupColorColorConstant#7dffb2
popupSizeNumberConstant0.75
popupRiseNumberConstant1.25
popupSecondsNumberConstant1.2
When Enabled
WhenOn Enable
1Change Component Value
Component Value
self.extraShipsData.nextExtraShipAt
Value
@self.extraShipEvery
On Scored
WhenscoredCustom Event
1If$score >= self.extraShipsData.nextExtraShipAt
Then
2Change Variable
Variable
$lives
Operator
+=
Value
1
3Change Component Value
Component Value
self.extraShipsData.nextExtraShipAt
Operator
+=
Value
@self.extraShipEvery
4Control Sound
Sound
"ExtraLife"
5Popup Text
Text
EXTRA SHIP
Color
@self.popupColor
Size
@self.popupSize
Rise
@self.popupRise
Seconds
@self.popupSeconds
Position Relative To
World
X
$areaWidth / 2
Y
$areaHeight / 2 + @self.popupAboveCenter

A.21 Score

Built in Chapter 7, Score.

Logic ComponentScoreAttach to: Game Rules

The score starts at 0 each game; the high score follows it whenever the score passes it.

Attach toAny Object
When the Game Starts
WhenGame Start
1Load Persistent Value
Action Name
savedHighScore
Key
"highScore"
Default
0
2IfsavedHighScore.value > $highScore
Then
3Change Variable
Variable
$highScore
Value
savedHighScore.value
On Game State Changed
WhenGame State Changed
1Check Game State
Action Name
isPlaying
Game State
Playing
2IfisPlaying.value == true
Then
3Change Variable
Variable
$score
Value
0
4Check Game State
Action Name
isGameOver
Game State
Game Over
5IfisGameOver.value == true
Then
6Save Persistent Value
Action Name
persistentWriteResult
Key
"highScore"
Value
$highScore
On Scored
WhenscoredCustom Event
1If$score > $highScore
Then
2Change Variable
Variable
$highScore
Value
$score

A.22 Saucer Explodes

Built in Chapter 8, Saucers.

Logic ComponentSaucer ExplodesAttach to: Saucer Large, Saucer Small

A saucer that is hit gives the player its points, shows them, explodes and is destroyed.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
pointsNumberConstant200
explosionCountNumberConstant60
shakeNumberConstant0.012
shakeSecondsNumberConstant0.25
popupColorColorConstant#ffd166
popupSizeNumberConstant0.563
popupRiseNumberConstant1
popupSecondsNumberConstant0.8
On Hit
WhenhitCustom Event
1Check Game State
Action Name
isPlaying
Game State
Playing
2IfisPlaying.value == true
Then
3Change Variable
Variable
$score
Operator
+=
Value
@self.points
4Trigger Custom Event
Custom Event
scored
5Popup Text
Text
text(@self.points)
Color
@self.popupColor
Size
@self.popupSize
Rise
@self.popupRise
Seconds
@self.popupSeconds
6Burst Particles
Particles
"Ship Explosion"
Count
@self.explosionCount
7Control Sound
Sound
"ExplosionLarge"
8Camera Shake
Intensity
@self.shake
Seconds
@self.shakeSeconds
9Destroy Instance

A.23 Saucer Flight

Built in Chapter 8, Saucers.

Logic ComponentSaucer FlightAttach to: Saucer Large, Saucer Small

A saucer enters beyond a random side at a random height, crosses at its speed while weaving up and down, and leaves at the far side.

Attach toAny Object
DATA STRUCTURES
Saucer Flight Dataself.saucerFlightData
SHARED VARIABLES
NameTypeKindStarting Value
speedNumberConstant3.75
marginNumberConstant1.25
minDepthNumberConstant2.813
maxDepthNumberConstant21.25
firstWeaveSecondsNumberConstant1
weaveSpeedNumberConstant2.656
weaveMinSecondsNumberConstant0.8
weaveMaxSecondsNumberConstant1.6
When Created
WhenCreate
1Generate Random Integer
Action Name
sideRoll
Maximum
1
2IfsideRoll.value == 0
Then
3Change Component Value
Component Value
self.saucerFlightData.direction
Value
1
4Change Component Value
Component Value
self.saucerFlightData.startX
Value
-@self.margin
5Otherwise
6Change Component Value
Component Value
self.saucerFlightData.direction
Value
-1
7Change Component Value
Component Value
self.saucerFlightData.startX
Value
$areaWidth + @self.margin
8Generate Random Number
Action Name
depthBelowTop
Minimum
@self.minDepth
Maximum
@self.maxDepth
9Set Position
X
self.saucerFlightData.startX
Y
$areaHeight - depthBelowTop.value
10Set Velocity
X Velocity
self.saucerFlightData.direction * @self.speed
Y Velocity
0
11Control Sound
Operation
Loop
Sound
"Saucer Siren"
12Start Recurring Timer
Timer Name
nextWeave
Repeat Every (s)
@self.firstWeaveSeconds
Ring Once
Yes
13Start Recurring Timer
Timer Name
crossing
Repeat Every (s)
($areaWidth + 2 * @self.margin) / @self.speed
Ring Once
Yes
On the Next Weave Timer
WhenRecurring TimerTimer name: nextWeave
1Generate Random Integer
Action Name
weaveRoll
Minimum
-1
Maximum
1
2Set Velocity
Y Velocity
weaveRoll.value * @self.weaveSpeed
3Generate Random Number
Action Name
weaveSeconds
Minimum
@self.weaveMinSeconds
Maximum
@self.weaveMaxSeconds
4Start Recurring Timer
Timer Name
nextWeave
Repeat Every (s)
weaveSeconds.value
Ring Once
Yes
On the Crossing Timer
WhenRecurring TimerTimer name: crossing
1Destroy Instance
When Leaving the View
WhenLeave View
1Ifself.transform.position.y > $areaHeight
Then
2Set Position
X
self.transform.position.x
Y
self.transform.position.y - $areaHeight
3Ifself.transform.position.y < 0
Then
4Set Position
X
self.transform.position.x
Y
self.transform.position.y + $areaHeight
When Destroyed
WhenDestroy
1Control Sound
Operation
Stop
Sound
"Saucer Siren"
On Game Paused
WhengamePausedCustom Event
1Control Sound
Operation
Stop
Sound
"Saucer Siren"
On Game Resumed
WhengameResumedCustom Event
1Control Sound
Operation
Loop
Sound
"Saucer Siren"
On Play Stopped
WhenplayStoppedCustom Event
1Control Sound
Operation
Stop
Sound
"Saucer Siren"

A.24 Saucer Gun

Built in Chapter 8, Saucers.

Logic ComponentSaucer GunAttach to: Saucer Large, Saucer Small

A saucer fires its own shot every fireEvery seconds, with the pulse sound.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
shotObjectConstantNone
fireEveryNumberConstant1.35
When Created
WhenCreate
1Start Recurring Timer
Timer Name
saucerFire
Repeat Every (s)
@self.fireEvery
On the Saucer Fire Timer
WhenRecurring TimerTimer name: saucerFire
1Create Instance
Object to Create
@self.shot
Position Relative To
Self
Created As
newShot
2Control Sound
Sound
"Saucer Pulse"
On Play Stopped
WhenplayStoppedCustom Event
1Stop Recurring Timer
Timer Name
saucerFire

A.25 Saucer Shot Flight

Built in Chapter 8, Saucers.

Logic ComponentSaucer Shot FlightAttach to: Saucer Orb, Saucer Lance

A saucer shot flies in a random direction, or at the Ship if it is aimed, and is gone after lifeSeconds or when it touches something.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
shipObjectConstantNone
aimedBooleanConstantNo
aimSpreadNumberConstant7
speedNumberConstant10.313
lifeSecondsNumberConstant1.15
When Created
WhenCreate
1Generate Random Number
Action Name
shotHeading
Maximum
359
2Set Rotation
Degrees
shotHeading.value
3If@self.aimed == true
Then
4Check Instance Count
Action Name
isShipThere
Object
@self.ship
Operator
>
Value
0
5IfisShipThere.value == true
Then
6Generate Random Number
Action Name
aimOffset
Minimum
-@self.aimSpread
Maximum
@self.aimSpread
7Face Toward
Target Object
@self.ship
Rotation Offset
aimOffset.value
8Set Direction
Direction
self.transform.rotation.z
9Set Speed
Speed
@self.speed
10Start Recurring Timer
Timer Name
shotLife
Repeat Every (s)
@self.lifeSeconds
Ring Once
Yes
On the Shot Life Timer
WhenRecurring TimerTimer name: shotLife
1Destroy Instance
When Starting to Hit Anything Tagged Asteroid
WhenCollision EnterObject: tag:Asteroid
1Trigger Custom Event on Object
Applies To
other
Custom Event
breakUp
2Destroy Instance
On Hit
WhenhitCustom Event
1Destroy Instance

A.26 Saucer Spawner

Built in Chapter 8, Saucers.

Logic ComponentSaucer SpawnerAttach to: Game Rules

The first saucer comes firstSeconds into the game. After that, a saucer check comes a random number of seconds later (fewer in later waves) and sends a saucer when none is flying; the Small one comes more often in later waves and always at high scores.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
largeSaucerObjectConstantNone
smallSaucerObjectConstantNone
firstSecondsNumberConstant16
smallChanceNumberConstant0.12
smallChancePerWaveNumberConstant0.06
smallAlwaysScoreNumberConstant40000
gapMinFloorNumberConstant7
gapMinStartNumberConstant17
gapMaxFloorNumberConstant11
gapMaxStartNumberConstant24
When Enabled
WhenOn Enable
1Start Recurring Timer
Timer Name
saucerCheck
Repeat Every (s)
@self.firstSeconds
Ring Once
Yes
On the Saucer Check Timer
WhenRecurring TimerTimer name: saucerCheck
1Declare Variable
Name
gapMax
Value
0
2Declare Variable
Name
gapMin
Value
0
3Check Instance Count
Action Name
isSaucerFlying
Object
tag:Saucer
Operator
>
Value
0
4IfisSaucerFlying.value == false
Then
5Generate Random Number
Action Name
saucerRoll
6If$score >= @self.smallAlwaysScore || saucerRoll.value < (@self.smallChance + @self.smallChancePerWave * $wave)
Then
7Create Instance
Object to Create
@self.smallSaucer
Created As
newSmallSaucer
8Otherwise
9Create Instance
Object to Create
@self.largeSaucer
Created As
newLargeSaucer
10Change Variable
Variable
gapMin
Value
@self.gapMinStart - $wave
11IfgapMin < @self.gapMinFloor
Then
12Change Variable
Variable
gapMin
Value
@self.gapMinFloor
13Change Variable
Variable
gapMax
Value
@self.gapMaxStart - $wave
14IfgapMax < @self.gapMaxFloor
Then
15Change Variable
Variable
gapMax
Value
@self.gapMaxFloor
16Generate Random Number
Action Name
checkSeconds
Minimum
gapMin
Maximum
gapMax
17Start Recurring Timer
Timer Name
saucerCheck
Repeat Every (s)
checkSeconds.value
Ring Once
Yes
When Disabled
WhenOn Disable
1Stop Recurring Timer
Timer Name
saucerCheck

A.28 Game Over Screen

Built in Chapter 9, Screens.

Logic ComponentGame Over ScreenAttach to: Game Rules

After the last Ship: GAME OVER and the final score; playAgainSeconds later, the offer to play again; returnSeconds after that, the title.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
playAgainPromptObjectConstantNone
playAgainSecondsNumberConstant2
returnSecondsNumberConstant12
On Game State Changed
WhenGame State Changed
1Stop Recurring Timer
Timer Name
playAgainDelay
2Stop Recurring Timer
Timer Name
returnToTitle
3Set UI Group Visibility
UI Group
gameOver
Visible
No
4Trigger Custom Event on Object
Applies To
@self.playAgainPrompt
Custom Event
stopBlinking
5Check Game State
Action Name
isGameOver
Game State
Game Over
6IfisGameOver.value == true
Then
7Set UI Group Visibility
UI Group
gameOver
8Start Recurring Timer
Timer Name
playAgainDelay
Repeat Every (s)
@self.playAgainSeconds
Ring Once
Yes
9Check Game State
Action Name
isOfferingPlayAgain
Game State
Play Again
10IfisOfferingPlayAgain.value == true
Then
11Set UI Group Visibility
UI Group
gameOver
12Trigger Custom Event on Object
Applies To
@self.playAgainPrompt
Custom Event
startBlinking
13Start Recurring Timer
Timer Name
returnToTitle
Repeat Every (s)
@self.returnSeconds
Ring Once
Yes
On the Play Again Delay Timer
WhenRecurring TimerTimer name: playAgainDelay
1Set Game State
Game State
Play Again
On the Return to Title Timer
WhenRecurring TimerTimer name: returnToTitle
1Set Game State
Game State
Title

A.29 Leave When Cleared

Built in Chapter 9, Screens.

Logic ComponentLeave When ClearedAttach to: Shot, Asteroid Large, Asteroid Medium, Asteroid Small, Saucer Orb, Saucer Lance, Saucer Large, Saucer Small, Title Asteroid

This Object leaves when space is cleared for a new game or the title screen.

Attach toAny Object
On Clear Field
WhenclearFieldCustom Event
1Destroy Instance

A.31 Pause

Built in Chapter 9, Screens.

Logic ComponentPauseAttach to: Game Rules

Pause (Esc or P) during play holds the game under the PAUSED menu and lets it go on when the menu reports gameResumed; a menu opened as the game ends is closed.

Attach toAny Object
When Pause Is Pressed
WhenCommand PressedCommand: Pause
1Check Menu Open
Action Name
isPauseMenuOpen
Menu Element
"Paused"
2IfisPauseMenuOpen.value == false
Then
3Trigger Custom Event
Custom Event
gamePaused
4Trigger Custom Event
Custom Event
showPausedMenu
On Game Resumed
WhengameResumedCustom Event
1Trigger Custom Event
Custom Event
hideMenu
When Disabled
WhenOn Disable
1Trigger Custom Event
Custom Event
hideMenu

A.32 Play Switch

Built in Chapter 9, Screens.

Logic ComponentPlay SwitchAttach to: Game Rules

Switches the Logic that only makes sense during play on when a game starts, and off when it ends.

Attach toAny Object
On Game State Changed
WhenGame State Changed
1Check Game State
Action Name
isPlaying
Game State
Playing
2IfisPlaying.value == true
Then
3Set Logic State
Logic Component
"Lives and Respawn"
4Set Logic State
Logic Component
"Waves"
5Set Logic State
Logic Component
"Extra Ships"
6Set Logic State
Logic Component
"Saucer Spawner"
7Set Logic State
Logic Component
"Pause"
8Set Logic State
Logic Component
"Heartbeat"
9Otherwise
10Set Logic State
Logic Component
"Lives and Respawn"
State
Disable
11Set Logic State
Logic Component
"Waves"
State
Disable
12Set Logic State
Logic Component
"Extra Ships"
State
Disable
13Set Logic State
Logic Component
"Saucer Spawner"
State
Disable
14Set Logic State
Logic Component
"Pause"
State
Disable
15Set Logic State
Logic Component
"Heartbeat"
State
Disable
16Trigger Custom Event
Custom Event
playStopped

A.33 Start Game

Built in Chapter 9, Screens.

Logic ComponentStart GameAttach to: Game Rules

Start (Enter or Space) on the title or after a game over clears space and starts a game.

Attach toAny Object
When Start Is Pressed
WhenCommand PressedCommand: Start
1Check Game State
Action Name
isOnTitle
Game State
Title
2Check Game State
Action Name
isOfferingPlayAgain
Game State
Play Again
3IfisOnTitle.value == true || isOfferingPlayAgain.value == true
Then
4Control Sound
Sound
"Start"
5Trigger Custom Event
Custom Event
clearField
6Set Game State
Game State
Playing

A.34 Title Screen

Built in Chapter 9, Screens.

Logic ComponentTitle ScreenAttach to: Game Rules

The title screen: its words, its music, and six drifting Title Asteroids, whenever the game is on the title.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
promptObjectConstantNone
titleAsteroidObjectConstantNone
asteroidsPerBandNumberConstant3
edgeBandNumberConstant3.438
sideBandNumberConstant4.688
When the Game Starts
WhenGame Start
1Trigger Custom Event on Object
Custom Event
showTitle
On Game State Changed
WhenGame State Changed
1Check Game State
Action Name
isOnTitle
Game State
Title
2IfisOnTitle.value == true
Then
3Trigger Custom Event on Object
Custom Event
showTitle
4Otherwise
5Set UI Group Visibility
UI Group
title
Visible
No
6Trigger Custom Event on Object
Applies To
@self.prompt
Custom Event
stopBlinking
7Control Sound
Operation
Stop
Sound
"Space Theme"
8Set UI Group Visibility
UI Group
hud
On Show Title
WhenshowTitleCustom Event
1Trigger Custom Event
Custom Event
clearField
2Create Asteroids Along EdgesFunction
creator
self
asteroid
@self.titleAsteroid
perBand
@self.asteroidsPerBand
edgeBand
@self.edgeBand
sideBand
@self.sideBand
3Set UI Group Visibility
UI Group
hud
Visible
No
4Set UI Group Visibility
UI Group
title
5Trigger Custom Event on Object
Applies To
@self.prompt
Custom Event
startBlinking
6Control Sound
Operation
Loop
Sound
"Space Theme"

A.35 Heartbeat

Built in Chapter 10, Heartbeat.

Logic ComponentHeartbeatAttach to: Game Rules

While a wave's Asteroids are out, a two-note heartbeat plays, starting startSeconds apart and speedUp times sooner each beat, down to fastestSeconds.

Attach toAny Object
DATA STRUCTURES
Heartbeat Dataself.heartbeatData
SHARED VARIABLES
NameTypeKindStarting Value
startSecondsNumberConstant1
speedUpNumberConstant0.97
fastestSecondsNumberConstant0.24
On Wave Started
WhenwaveStartedCustom Event
1Change Component Value
Component Value
self.heartbeatData.beatSeconds
Value
@self.startSeconds
2Start Recurring Timer
Timer Name
heartbeat
Repeat Every (s)
self.heartbeatData.beatSeconds
Ring Once
Yes
On the Heartbeat Timer
WhenRecurring TimerTimer name: heartbeat
1Ifself.heartbeatData.nextNote == 1
Then
2Control Sound
Sound
"Beat1"
3Change Component Value
Component Value
self.heartbeatData.nextNote
Value
2
4Otherwise
5Control Sound
Sound
"Beat2"
6Change Component Value
Component Value
self.heartbeatData.nextNote
Value
1
7Change Component Value
Component Value
self.heartbeatData.beatSeconds
Operator
*=
Value
@self.speedUp
8Ifself.heartbeatData.beatSeconds < @self.fastestSeconds
Then
9Change Component Value
Component Value
self.heartbeatData.beatSeconds
Value
@self.fastestSeconds
10Start Recurring Timer
Timer Name
heartbeat
Repeat Every (s)
self.heartbeatData.beatSeconds
Ring Once
Yes
On Wave Cleared
WhenwaveClearedCustom Event
1Stop Recurring Timer
Timer Name
heartbeat
When Disabled
WhenOn Disable
1Stop Recurring Timer
Timer Name
heartbeat

A.36 Sky Parallax

Built in Chapter 11, Sky.

Logic ComponentSky ParallaxAttach to: Game Rules

The sky drifts layer by layer, slides against the Ship's motion by each layer's depth, and surges forward during a sector jump.

Attach toAny Object
DATA STRUCTURES
Sky Parallax Dataself.skyParallaxData
SHARED VARIABLES
NameTypeKindStarting Value
shipObjectConstantNone
followRateNumberConstant3
surgeRateNumberConstant2.4
pixelsPerMeterNumberConstant32
Every Step
WhenStep
1Check Instance Count
Action Name
isShipThere
Object
@self.ship
Operator
>
Value
0
2IfisShipThere.value == true
Then
3Change Component Value
Component Value
self.skyParallaxData.followVX
Value
@self.ship.transform.velocity.x
4Change Component Value
Component Value
self.skyParallaxData.followVY
Value
@self.ship.transform.velocity.y
5Otherwise
6Change Component Value
Component Value
self.skyParallaxData.followVX
Value
0
7Change Component Value
Component Value
self.skyParallaxData.followVY
Value
0
8Change Component Value
Component Value
self.skyParallaxData.skyVX
Operator
+=
Value
(self.skyParallaxData.followVX - self.skyParallaxData.skyVX) * @self.followRate * $deltaTime
9Change Component Value
Component Value
self.skyParallaxData.skyVY
Operator
+=
Value
(self.skyParallaxData.followVY - self.skyParallaxData.skyVY) * @self.followRate * $deltaTime
10Change Component Value
Component Value
self.skyParallaxData.jump
Operator
+=
Value
(self.skyParallaxData.jumpTarget - self.skyParallaxData.jump) * @self.surgeRate * $deltaTime
On End Step
WhenEnd Step
1RepeatdataCount("Sky Layers")times
Each time
2Change Component Value
Component Value
self.skyParallaxData.row
Value
local.index
3Change Component Value
Component Value
self.skyParallaxData.driftX
Value
data("Sky Layers", self.skyParallaxData.row, "driftX")
4Change Component Value
Component Value
self.skyParallaxData.driftY
Value
data("Sky Layers", self.skyParallaxData.row, "driftY")
5Change Component Value
Component Value
self.skyParallaxData.depth
Value
data("Sky Layers", self.skyParallaxData.row, "depth")
6Change Component Value
Component Value
self.skyParallaxData.surge
Value
data("Sky Layers", self.skyParallaxData.row, "surge")
7Set Background Sliding Speed
Background
data("Sky Layers", self.skyParallaxData.row, "background")
X Speed
self.skyParallaxData.driftX - self.skyParallaxData.skyVX * @self.pixelsPerMeter * self.skyParallaxData.depth - self.skyParallaxData.jump * self.skyParallaxData.surge
Y Speed
self.skyParallaxData.driftY - self.skyParallaxData.skyVY * @self.pixelsPerMeter * self.skyParallaxData.depth
On Wave Cleared
WhenwaveClearedCustom Event
1Change Component Value
Component Value
self.skyParallaxData.jumpTarget
Value
1
On Next Wave
WhennextWaveCustom Event
1Change Component Value
Component Value
self.skyParallaxData.jumpTarget
Value
0
On Play Stopped
WhenplayStoppedCustom Event
1Change Component Value
Component Value
self.skyParallaxData.jumpTarget
Value
0