LevelGoal
What a physics puzzler’s level is for, with no code: knock out every target before the slingshot runs out of shots. Once the last target is down it waits for things to settle, counts a bonus for each shot left, rates the level one to three stars by the score and keeps the best stars and score in the save data, and sends its WonMessage; out of shots with targets still standing, it sends its LostMessage. A panel opens on each.
Part of the Physics Games module: Physics puzzlers: a Slingshot to pull back and launch shots from, and Breakable things (planks, panes, blocks, pigs) that crack and break on hard knocks; a LevelGoal that wins a level once its targets are down (with a bonus for the shots left, and one to three stars) or loses it once the shots run out; a Slingshot and a Tower to make from the Entity menu (Genres, Physics Games); and the Physics template, levels of wood, glass and stone to knock down.
The targets are everything named Targets (a Breakable is gone once broken; anything else once removed or turned off), so they can be pigs in a tower or a platformer’s enemies. The score is a Counter’s (Score), which the targets’ and blocks’ Break Messages add their points to. With SaveAs “Level1” it saves the best stars as “Level1.Stars” and the best score as “Level1.Best”: a level select menu’s Stars show them, and a button that Needs Saved “Level1.Stars” opens the next level once it’s won.
Works with: Slingshot (its shots: out of them with targets standing loses, and each one left is a bonus); Counter (the score (on another entity), which the stars are given by); Stars (shows its Stars (on the panel its Won Message opens))
Properties
Section titled “Properties”Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.
targets: text = “Target”. What has to be knocked out, by name: every entity called this, e.g. “Target”. The level’s won once none is left. (Names an entity.) (Field: an entity’s name.)slingshot: text = null. The slingshot whose shots the level is played with, by name. Empty is the scene’s first. (Names an entity.) (Field: an entity’s name.)score: text = “Score”. The Counter keeping the score, by name, e.g. “Score”: the stars are given by it, and the bonus added to it. (Names an entity.) (Field: an entity’s name.)shotBonus: a whole number = 10000. Points for each shot left once the targets are down, added one after another. (Field: a number.)settle: a number = 2. Seconds it waits, once the last target is down or the last shot has come to rest, for things to settle before it says the level’s won or lost: a target knocked out meanwhile still counts. (Field: a number.)
twoStars: a whole number = 20000. The score that earns two stars (winning earns one). (Field: a number.)threeStars: a whole number = 35000. The score that earns three stars. (Field: a number.)saveAs: text = null. A name to keep the level’s best in the save data under, e.g. “Level1”: the best stars as “Level1.Stars” and the best score as “Level1.Best”, for a level select menu. Empty keeps nothing. (Names a name in the save data: this entity’s own, which other fields can name.) (Field: a name.)
Sound and Messages
Section titled “Sound and Messages”wonMessage: text = “Level Complete”. A message sent as the level is won (after the bonus), with the stars as its data: a panel opens on it. (Names a message.) (Field: a name.)lostMessage: text = “Level Failed”. A message sent as the level is lost, with the targets left as its data. (Names a message.) (Field: a name.)bonusSound: text = null. A sound played for each shot’s bonus as it’s counted. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)winSound: text = null. A sound played as the level is won. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)loseSound: text = null. A sound played as the level is lost. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
phase: one of Playing, Settling, Bonus, Won, Lost = “Playing”. Where the level has got to. Set by the game. (Field: one of its values.)timer: a number = 0. Seconds until it moves on from settling, or counts the next shot’s bonus. Set by the game. (Field: a number.)targetCount: a whole number = 0. How many targets the level started with. Set by the game as it starts. (Field: a number.)stars: a whole number = 0. The stars it earned, 1 to 3, once it’s won; 0 before. Set by the game. (Field: a number.)
Actions
Section titled “Actions”What anything can make it do with no code: a Trigger’s do when its message arrives, a Contraptions Wire’s input as its signal comes on, a script’s Game.Do(entity, “Name”).
Win. Wins the level now: its shots left are counted for their bonus, and its stars given.Lose. Loses the level now.
Outputs
Section titled “Outputs”What anything can read with no code: a Counter’s, Bar’s or Text’s output, a Contraptions Wire’s output as its signal; Text shows names too, the rest read numbers, true as 1.
Stars(a whole number, out of its maxStars). The stars it earned, 1 to 3, once it’s won; 0 before. Set by the game.TargetsLeft(a whole number, out of its targetCount). How many targets are still standing.Won(true or false). True once the level’s won (and its bonus counted).Lost(true or false). True once the level’s lost.BestStars(a whole number, out of its maxStars). The best stars the level has had, from the save data (with SaveAs; this run’s without).BestScore(a whole number). The best score the level has been won with, from the save data (with SaveAs; this run’s without).
While the game runs
Section titled “While the game runs”Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.
targetsLeft: a whole number. How many targets are still standing.won: true or false. True once the level’s won (and its bonus counted).lost: true or false. True once the level’s lost.bestStars: a whole number. The best stars the level has had, from the save data (with SaveAs; this run’s without).bestScore: a whole number. The best score the level has been won with, from the save data (with SaveAs; this run’s without).maxStars: a whole number. Three: what Stars is out of.starsKey: text. The save data name its best stars are kept under (“Level1.Stars”), or null without SaveAs.bestKey: text. The save data name its best score is kept under (“Level1.Best”), or null without SaveAs.
Scripts use it as LevelGoal: its methods, events and values that aren’t saved with the scene.