- Learn
- Build a Game
- Pitch Shot
- 7 Winning
7 Winning
By the end of this chapter, finding the call wins the stage. A card comes up: “That’s the one!”, up to three stars for how well you listened, a line about how you found it, and the next stage’s name. A bar fills, and the next stage stands up.
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. Unzip it first. Then open it and compare, or start Chapter 8 from it.
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. Nunito-OFL.txt beside it comes with the game.
7.1 The Idea
Shoot at the call. The note bursts in gold, the world slows, and the tower comes down knocking. The rubble settles on the grass. Then a fresh happy note pops into the band, and the stage goes on, as if nothing had happened.
You found it. The game should say so.
This chapter gives the moment its ending. A moment after the last block lands, a card comes up over the meadow. “That’s the one!” Three stars, or two, or one. A line that says how you found it, such as “Found by ear, first time.” The name of the next stage. And a bar that fills, and when it’s full, the next stage stands up.
The stars are for listening. No wrong notes earns three. One or two wrong notes earn two, and more earn one. Every stage can be won, and the stars only say how well you heard it.
To end a stage, the game needs to know it has ended. That’s the Game State: one word for what the whole game is doing right now, Playing or Stage Won. Think of the sign on a shop door. Anyone walking by can read it, and one hand turns it over. Here that hand is Win The Stage, and the readers are the pieces that should stop when the stage is over.
Nothing in this chapter changes how a shot flies or a tower falls. It all happens after.
7.2 The Plan
Here’s how the pieces work together. A name in bold is a piece you’ll make or change, and a name in plain text is a Custom Event.
- The call is found -> Win The Stage turns the Game State to Stage Won and counts the stars. Load The Happy Note and Repeat The Call read the sign and stay quiet.
- At the same moment, Bring Up The Card waits for the blocks to settle -> cardShown.
- On cardShown, Show With The Card shows the card’s parts. Light A Star, Tell How It Was Found and Show The Next Stage fill them in. Fill The Bar starts the bar.
- The full bar sends cardTimeUp. A click sends goOnWanted, and Enter is the Go On Command. All three ways -> Go On To The Next Stage -> the next stage.
- At the top, the Stage Title names the stage, and the Restart Button starts it again.
You’ll build it in that order: the win, then the card, then the way on, then the top of the screen.
7.3 Set Up
EnterGo OnPlaying, Stage WonART names the pictures for the card and for the top of the screen. There’s the card itself, a star, the bar’s track and its fill, a pill for the stage’s name, and the restart icon. SOUNDS names Sound Click, for the restart button. The Starter Kit brought them all.
INPUT CONTEXTS has a new one, Card, and it starts Inactive at Start. Make it before the Command, so Go On goes into its Command Set, as Keys: Commands and Input Contexts says from Chapter 7. Next, add Go On, a Button, on Enter.
Why a second context? Enter already lets go of the happy note, in Field. While the card is up, Field is off and Card is on, so the same key means “go on” instead.
GLOBAL VARIABLES has one, $starsWon, a Number that starts at 0, for the stars this stage has earned. Open any Logic Component, and add it from its canvas’s Globals card.
GAME SETTINGS names the two Game States. Your project has Playing already, so add Stage Won, as The Set up card shows from Chapter 7.
PLACE THESE waits for the card’s parts, the Stage Title and the Restart Button. The chapter comes back to it when they’re made.
7.4 The Stage Is Won
First, the win itself. The card comes in the next part, so this one ends in quiet.
7.4.1 Win The Stage
When the Field starts, Win The Stage sets the Game State to Playing. It also turns Field on and Card off, so that Enter lets go of the happy note again, the way it did in Chapter 4.
When callFound comes, it turns the sign over: Stage Won. Then it counts the stars, from $wrongNotes, the count you made in Chapter 5. None, and $starsWon is 3. Up to twoStarWrongNotes, which is 2, and the stage earns 2 stars. More, and it’s 1.
Finding the called note wins the stage: the game is Stage Won, and the stage earns stars for listening.
Any Object- Game State
Playing
- Input Context
Field
- Input Context
Card- Active
No
- Game State
Stage Won
$wrongNotes == 0- Variable
$starsWon- Value
3
$wrongNotes <= @self.twoStarWrongNotes- Variable
$starsWon- Value
2
- Variable
$starsWon- Value
1
Set Game State has one list, Game State, with your two in it. Set Input Context Active has two: an Input Context list, and an Active switch. The switch starts On. So where the card gives no Active line, leave it On, and where it says No, turn it off.
The stars are an If with an If in its Else. Build the outer If first. Use Add inside Else to add the inner If, with its own Else.
7.4.2 Load The Happy Note, Changed
Puts a happy note in the band when the opening is over, and again a moment after each shot ends, if none is there.
Any Object- bandX
self.transform.position.x + @self.bandOffsetX- bandY
self.transform.position.y + @self.bandOffsetY- happyNote
@self.happyNote- slingshot
self
- Timer Name
"loadNext"- Repeat Every (s)
@self.secondsAfterShot- Ring Once
Yes
- bandX
self.transform.position.x + @self.bandOffsetX- bandY
self.transform.position.y + @self.bandOffsetY- happyNote
@self.happyNote- slingshot
self
- Action Name
isPlaying- Game State
Playing
isPlaying.value == true- bandX
self.transform.position.x + @self.bandOffsetX- bandY
self.transform.position.y + @self.bandOffsetY- happyNote
@self.happyNote- slingshot
self
After the winning shot ends, the slingshot would load a note, as it does after every shot. Nobody needs one now. So the loadNext timer asks first.
Check Game State asks whether the game is in the state you pick, and its answer is isPlaying. You’ve read an answer like that before, from Check Cooldown Ready in Chapter 6. The If reads isPlaying.value == true, and the call to Put A Note In The Band moves inside it.
Delete the old call. The Event’s line is empty now, as On Opening Finished’s was in Chapter 4, so Connect to Sequence joins Check Game State at its start. Add the If after it, and join it. Use Add inside Then for Put A Note In The Band, with the same four values.
7.4.3 Repeat The Call, Changed
Plays the call whenever it is asked for while the stage is being played, and again by itself after a quiet spell, at most twice in a row, never over the player's aim or a shot in the air.
Any Objectself.repeatTheCallData$calledPitch > 0- Action Name
isPlaying- Game State
Playing
isPlaying.value == true && $calledPitch > 0- pitch
$calledPitch
- Component Value
self.repeatTheCallData.repeatsLeft- Value
@self.mostRepeats
- Timer Name
"repeatTheCall"- Repeat Every (s)
@self.quietSeconds- First Delay (s)
@self.quietSeconds
self.repeatTheCallData.isNoteWaiting == true- pitch
$calledPitch
- Component Value
self.repeatTheCallData.repeatsLeft- Operator
+=- Value
-1
self.repeatTheCallData.repeatsLeft <= 0- Timer Name
"repeatTheCall"
- Timer Name
"repeatTheCall"- Repeat Every (s)
@self.quietSeconds- First Delay (s)
@self.waitSeconds
- Component Value
self.repeatTheCallData.isNoteWaiting- Value
true
- Component Value
self.repeatTheCallData.isNoteWaiting- Value
false
- Component Value
self.repeatTheCallData.isNoteWaiting- Value
true
- Component Value
self.repeatTheCallData.isNoteWaiting- Value
false
- Timer Name
"repeatTheCall"- Repeat Every (s)
@self.quietSeconds- First Delay (s)
@self.quietSeconds
- Action Name
isStillPlaying- Game State
Playing
isStillPlaying.value == true- Timer Name
"repeatTheCall"- Repeat Every (s)
@self.quietSeconds- First Delay (s)
@self.quietSeconds
- Timer Name
"repeatTheCall"
The call should rest once it’s found. Three changes.
On Call Requested asks the same question first. Once the stage is won, “Hear it again” rests too, because the call has been found.
The Changes card replaces the old If. Delete that If and its three Actions, then rebuild this Event from the green lines. Start with Check Game State, named isPlaying, on the empty Event line. Add the new If after it. Its one Condition box joins the state check and the pitch check with &&. Use Add inside Then to rebuild the three Actions under it. Their values stay the same. The card leaves those values unmarked; here you rebuild their Actions under the new If.
On Shot Ended starts the quiet spell only while Playing. Delete its timer, and build it again the same way: Check Game State named isStillPlaying on the empty line, the If after it, and the timer inside Then.
And a new Event: when callFound comes, Stop Recurring Timer stops the repeatTheCall timer. Its one box takes repeatTheCall, the timer’s name.
7.4.4 Game Rules, Changed
Sound The FallSound The Fall DataRepeat The CallRepeat The Call DataMake Way For The NotesMake Way For The Notes DataSinging NoteAttach Win The Stage to Game Rules now. Bring Up The Card and Go On To The Next Stage join it later in the chapter.
Run the game. Find the call. The tower comes down, the rubble settles, and then nothing. No new note in the band, and the call doesn’t come back. Press Space, and the meadow stays quiet.
It looks like the game has stopped. It hasn’t. It’s waiting for the card, which is the next part’s work.
7.5 The Card Comes Up
Now the card. It’s six pieces on the screen: the panel, three stars, a message, the next stage’s name, and a bar on a track. And one Logic decides when it appears.
7.5.1 Bring Up The Card
The card shouldn’t come up in the middle of the crash. It waits for the dust to settle.
Count the beats. The call is found. A little over a second and a half goes by, cardAfterSeconds, 1.6. Are blocks still knocking? Wait another restSeconds, 0.4 seconds, and ask again. And again. When the knocks have been quiet for 0.4 seconds, up comes the card. A big crash can’t hold it back for long. At latestCardSeconds, 3.5, it comes up anyway.
The quiet is a cooldown, the named stopwatch from Chapter 6. Every blockKnocked starts stillCrashing over. The stopwatch runs out only once the knocks stop.
A Cooldown Key takes its name bare, as a Timer Name does. Type stillCrashing without quote marks.
Two timers race, showCard and latestCard. Whichever rings first sends cardDue, and On Card Due stops them both, so the card comes up once.
Trigger Custom Event on Object sends cardDue only to Game Rules itself. Then it turns Field off and Card on, and sends cardShown to the whole Scene. Everything on the card waits for that.
When the stage is won, the card comes up cardAfterSeconds later, or later while blocks are still crashing, and at latestCardSeconds at the latest.
Any Object- Timer Name
"showCard"- Repeat Every (s)
@self.cardAfterSeconds- Ring Once
Yes
- Timer Name
"latestCard"- Repeat Every (s)
@self.latestCardSeconds- Ring Once
Yes
- Cooldown Key
"stillCrashing"- Seconds
@self.restSeconds
- Action Name
isQuiet- Cooldown Key
"stillCrashing"
isQuiet.value == true- Custom Event
cardDue
- Timer Name
"showCard"- Repeat Every (s)
@self.restSeconds- Ring Once
Yes
- Custom Event
cardDue
- Timer Name
"showCard"
- Timer Name
"latestCard"
- Input Context
Field- Active
No
- Input Context
Card
- Custom Event
cardShown
The blocks are familiar. The Else at step 4 belongs to the If at step 2. It starts the showCard timer again. Attach Bring Up The Card to Game Rules now, before the run at the end of this part.
7.5.2 Show With The Card
Every part of the card starts hidden. It appears on cardShown. That’s one small Logic, Show With The Card. Five Objects carry it.
A part of the card that shows when a stage is won: hidden until then.
Any Object- Visible
No
- Visible
Yes
Make it once, and attach it to each card part as you make it. One Logic can sit on many Objects, and each one runs it for itself, at its own place on the screen. Each part’s Object card lists the Logic it carries.
7.5.3 The Card Panel
Window / UIUIX 820, Y 426-1Card Panel ArtX 820, Y 426That’s the one!Nunito54Extra Bold#EC4A33CenterVectorX 0, Y 162The win card is a cream panel with a dark rim, Card Panel Art. Across its top, in red, it says That’s the one!
That apostrophe is a curly one, ’. It isn’t the straight ’ on your keyboard, so copy the words from the card, and yours will match the game. The words sit at Y 162, near the top of the panel.
Keep its UI Interaction, as it comes. A click on the card goes on to the next stage, and Go On From The Card joins it in the next part.
7.5.4 Light A Star
One of the three stars on the card (each placement has its starNumber): it shows lit when the stage earned at least that many stars.
Any Object$starsWon >= self.starNumber- Frame
1
- Frame
0
Star Art is a picture with two frames, a dim star and a lit one. Set Frame shows one of them: 0 is dim, 1 is lit.
Each star knows its number, Star Number, read as self.starNumber. When the card comes up, it asks: did this stage earn at least my number of stars? If so, it lights. Two stars earned, and stars 1 and 2 light, while star 3 stays dim.
7.5.5 The Card Star
Window / UIUIX 96, Y 96-1Star ArtX 96, Y 96There’s one Card Star, placed three times. Each placement gets its own Star Number under PLACE THESE. The first keeps its Starting Value of 1; the others get 2 and 3. Use the placement’s Properties. One Object gives you three stars, each with a number of its own. The stars aren’t buttons. Remove the UI Interaction.
7.5.6 Found Line, Found Words and Tell How It Was Found
One line of the card's message.
Found by ear, first time.Found after one wrong note.Found afterwrong notes.The message under the stars says how you found the call. Its words live in a table, Found Words, made of Found Line rows, like the message near the top, whose words live in Messages.
Rows 0 and 1 are whole lines. Row 2 comes in two halves, “Found after” and “wrong notes.”, because a number goes between them. Leave the empty wordsAfterNumber cells empty.
The card's message: how the called note was found, by how many wrong notes came first.
Any Object- Type
Text- Name
wordsBefore
- Type
Text- Name
wordsAfter
$wrongNotes <= 1- Text
data("Found Words", $wrongNotes, "words")
- Variable
wordsBefore- Value
data("Found Words", 2, "words")
- Variable
wordsAfter- Value
data("Found Words", 2, "wordsAfterNumber")
- Text
text(wordsBefore, " ", $wrongNotes, " ", wordsAfter)
Declare Variable makes wordsBefore and wordsAfter as Text, ready to hold the two halves of the message. Leave their starting Value alone; both are filled before the message uses them.
The row number is $wrongNotes. No wrong notes reads row 0, and one reads row 1. More than one takes row 2’s two halves, and text(...) joins them with the number between, into one line: Found after 3 wrong notes.
Set UI Text puts words on a Screen UI Object. Leave its Element box blank, and it writes on the Object this Logic is attached to.
7.5.7 The Card Message
Window / UIUIX 740, Y 50Nunito32Extra Bold#3A1D0BCenterVectorTextThe Card Message has no words of its own until Tell How It Was Found writes them. Its UI Interaction stays, with Element Type set to Text in its list, so Set UI Text can write through it. Text templates in braces read their values without UI Interaction.
7.5.8 Show The Next Stage and the Card Next
The card's last line, the number and name of the next stage: shown with the card when there is a next stage.
Any Object- Visible
No
$stage < dataCount("Stages")- Visible
Yes
The next stage gets a line of its own at the bottom of the win card. It’s hidden until the card comes up, like the others. But it has its own Logic, because one stage has no next stage. dataCount("Stages") counts the rows of the Stages table. While $stage is less than that, there’s a next stage, and the line shows. On the very last stage there isn’t. Chapter 10 gives that moment its own ending.
Window / UIUIX 740, Y 40Next: {$stage + 1}. {data("Stages", $stage, "name")}Nunito26Extra Bold#3A1D0BCenterVectorIts Text is a template, like the shot count’s {$shots}, with two pieces in braces. The first is the next stage’s number. The second reads that stage’s name from Stages. Stage 1 is row 0, so the next stage’s row is $stage itself. Copy the line from the card. Its card lists no UI Interaction, so remove the one it came with.
7.5.9 Fill The Bar, the Card Bar Track and the Card Bar
The bar on the card fills over fillSeconds; when it is full it says the card has had its time.
Any Object- Horizontal Scale
0- Vertical Scale
1
- Value
self.transform.scale.x- Target
1- Duration
@self.fillSeconds
- Timer Name
"barFull"- Repeat Every (s)
@self.fillSeconds- Ring Once
Yes
- Custom Event
cardTimeUp
The bar is the card’s clock. When the card comes up, Set Scale squeezes the bar to nothing across, a Horizontal Scale of 0. Then Tween grows it back to 1 over fillSeconds, 2.4 seconds, from its middle out to both ends. A timer, barFull, rings at the same moment. It sends cardTimeUp.
Window / UIUIX 480, Y 18-1Card Bar Track ArtX 480, Y 18Window / UIUIX 476, Y 14-1Card Bar Fill ArtX 476, Y 14The track is a pale strip, and the bar is the orange fill drawn on top of it, a little smaller. Neither one is clicked, so remove their UI Interactions.
Now PLACE THESE, for the card. Drag each part onto the Field, and leave its Screen Anchor on the top-left dot, as in Chapter 4. Type its X, Y and Z-Index from the card. Place the Card Star three times, and give each its Star Number under Per Instance Variables in Properties. The Z-Indexes stack the card: the panel at 10050, its words and stars at 10060, and the bar at 10061, in front of its track.
Run the game. Find the call. The tower comes down, and a moment after the last knock, the card comes up. “That’s the one!”, the stars, your line, and the next stage’s name. The bar fills.
And then it stays there, full, and nothing happens, because nobody is listening for cardTimeUp yet.
7.6 On to the Next Stage
The bar is full. Time to go on to the next stage.
7.6.1 Go On To The Next Stage
From the card, the next stage starts: by itself when the card has had its time, or at once with Enter or a click.
Any Object- Custom Event
goOn
- Custom Event
goOn
- Custom Event
goOn
- Logic Component
Go On To The Next Stage- State
Disable
- Variable
$stage- Operator
+=- Value
1
There are three ways on: the bar fills, you press Enter, or you click the card. Each of the first three Events sends one message, goOn, to Game Rules itself. One way on, really. Three doors into it.
On Go on adds 1 to $stage, and Restart Scene starts the Field again. That’s all a new stage takes. The Field starts, Build The Stage reads $stage, and the next stage stands up, with a new call.
When Goon Is Pressed is Myth’s heading for the Go On Command, with the words joined.
Set Logic State has two lists. Choose Go On To The Next Stage in the first, and Disable in the second.
Before any of that, On Go on switches its own Logic off. Why? Press Enter at the instant the bar fills, and two goOns arrive in the same moment. Without that first step, both would add 1, and you’d skip a stage. Now the second one finds the Logic off, and does nothing at all, and the new Field starts it on again.
7.6.2 Go On From The Card
Clicking or tapping the card asks to go on at once.
Any Object- Custom Event
goOnWanted
A click on the panel sends goOnWanted, and that’s all. Attach it to the Card Panel, under Show With The Card. The heading On Hud Activated is Myth’s own name for a UI Activated Event, as on the Listen Button in Chapter 2.
7.6.3 Game Rules, Complete for Now
Attach Go On To The Next Stage to Game Rules now. Bring Up The Card is there already. The Game Rules card at the start lists all three new Logic Components.
Run the game. Find the call. The card comes up, the bar fills, and the meadow changes under it. Stage 2, Hilltop echo. A taller tower stands, and the notes sing their opening again.
Play another, and press Enter while the bar is filling. You’re on at once.
7.7 The Top of the Screen
Last, two small things at the top, so you always know where you are.
7.7.1 The Stage Title
Window / UIUIX 640, Y 64-1Title Pill ArtX 640, Y 64{data("Stages", $stage - 1, "place")} · {$stage}. {data("Stages", $stage - 1, "name")}Nunito27Extra Bold#3A1D0BCenterVectorA cream pill at the top names the place and the stage: Sunny Meadow · 1. Low and high. Its Text is a template with three pieces in braces. The place and the name come from the Stages table, at row $stage - 1, because stage 1 is row 0.
The dot in the middle, ·, isn’t on most keyboards. Copy the whole line from the card, the two spaces on each side of the dot too. It has no Logic. Its card lists no UI Interaction either, so remove the one it came with.
7.8 If It Didn’t Work
Most slips in this chapter leave the card missing, or stuck. Watch what the game does after the win, and you’ll know where to look.
The tower falls, and a new note loads anyway? Look at Load The Happy Note’s loadNext Event, and at Win The Stage on Game Rules. Is the Game State set to Stage Won on callFound?
The card never comes up? Is Bring Up The Card on Game Rules? Perhaps a part of the card is hidden because Show With The Card missed it. Look at that part’s Logic, and at its Z-Index.
The card comes up empty, a panel with no stars? Perhaps the Card Stars aren’t placed, or their Z-Index is under the panel’s 10050.
Every star lights, every time? Look at each placement’s Star Number, because all three may still say 1.
The message is missing? Look at the Card Message’s UI Interaction, whose Element Type should be Text.
The bar fills and nothing happens? Is Go On To The Next Stage on Game Rules? Is barFull spelled the same, letter for letter, in both Events of Fill The Bar, the one that starts the timer and the one that hears it?
Enter lets go of a note instead of going on? Look at Bring Up The Card’s On Card Due, where Field goes off and Card goes on. And is Go On in the Card context, not in Field?
A stage gets skipped? Look at step 1 of On Go on, which switches the Logic off before anything else can happen.
Each of these is one small fix. Make it, run the game, and find the call again. And if you’d like to compare, the catch-up download in the Goal is this chapter’s game, finished.
The win is yours to shape. Change twoStarWrongNotes in Win The Stage from 2 to 0, and only a perfect stage earns more than one star. Or change fillSeconds in Fill The Bar from 2.4 to 6, and the card stays up long enough to read twice. Or change the words in Found Words, and make the card say it your way. What would you want it to say? Put everything back before Chapter 8.
Still stuck? Search the manual, or ask in the Myth Engine Discord (opens a new tab).
Your stages begin and end now, and each one leads to the next. In Chapter 8, the game gets its front door.
