Skip to content

LevelGoal

namespace Griff.Modules.PhysicsGames;
public sealed class LevelGoal : Component, IPlaytestReport

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.

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.

This is a component: its saved properties are on its component page.

public string? BestKey { get; }

The save data name its best score is kept under (“Level1.Best”), or null without SaveAs.

public int BestScore { get; }

The best score the level has been won with, from the save data (with SaveAs; this run’s without).

public int BestStars { get; }

The best stars the level has had, from the save data (with SaveAs; this run’s without).

public string? BonusSound { get; set; }

A sound played for each shot’s bonus as it’s counted.

public string? LoseSound { get; set; }

A sound played as the level is lost.

public bool Lost { get; }

True once the level’s lost.

public string? LostMessage { get; set; }

A message sent as the level is lost, with the targets left as its data.

public int MaxStars { get; }

Three: what Stars is out of.

public LevelPhase Phase { get; set; }

Where the level has got to. Set by the game.

public string? SaveAs { get; set; }

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.

public string? Score { get; set; }

The Counter keeping the score, by name, e.g. “Score”: the stars are given by it, and the bonus added to it.

public float Settle { get; set; }

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.

public int ShotBonus { get; set; }

Points for each shot left once the targets are down, added one after another.

public string? Slingshot { get; set; }

The slingshot whose shots the level is played with, by name. Empty is the scene’s first.

public int Stars { get; set; }

The stars it earned, 1 to 3, once it’s won; 0 before. Set by the game.

public string? StarsKey { get; }

The save data name its best stars are kept under (“Level1.Stars”), or null without SaveAs.

public int TargetCount { get; set; }

How many targets the level started with. Set by the game as it starts.

public string? Targets { get; set; }

What has to be knocked out, by name: every entity called this, e.g. “Target”. The level’s won once none is left.

public int TargetsLeft { get; }

How many targets are still standing.

public int ThreeStars { get; set; }

The score that earns three stars.

public float Timer { get; set; }

Seconds until it moves on from settling, or counts the next shot’s bonus. Set by the game.

public int TwoStars { get; set; }

The score that earns two stars (winning earns one).

public string? WinSound { get; set; }

A sound played as the level is won.

public bool Won { get; }

True once the level’s won (and its bonus counted).

public string? WonMessage { get; set; }

A message sent as the level is won (after the bonus), with the stars as its data: a panel opens on it.

public void Lose()

Loses the level now.

public int StarsFor(int score)

The stars a score earns: one for winning, two from TwoStars, three from ThreeStars.

public override bool Uses(string property)
public void Win()

Wins the level now: its shots left are counted for their bonus, and its stars given.

public event Action<LevelGoal, int>? Completed

Raised as the level is won, after its bonus, with the stars it earned.

public event Action<LevelGoal>? Failed

Raised as the level is lost.