2016-03-26 00:47:20 +01:00
|
|
|
# Score
|
|
|
|
|
|
|
|
The game library supports simple single-player games. The player has a **score**.
|
|
|
|
|
|
|
|
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
|
|
|
|
|
2016-06-02 06:19:16 +02:00
|
|
|
```blocks
|
2016-03-30 06:17:57 +02:00
|
|
|
input.onButtonPressed(Button.A, () => {
|
2016-03-26 00:47:20 +01:00
|
|
|
game.addScore(1)
|
|
|
|
})
|
|
|
|
game.startCountdown(10000)
|
|
|
|
```
|
|
|
|
|
|
|
|
### Score
|
|
|
|
|
|
|
|
When a player achieves a goal, you can increase the game score
|
|
|
|
|
|
|
|
* add score points to the current score
|
|
|
|
|
|
|
|
```
|
|
|
|
export function addScore(points: number)
|
|
|
|
```
|
|
|
|
|
|
|
|
* set the current score to a particular value.
|
|
|
|
|
|
|
|
```
|
|
|
|
export function setScore(value: number)
|
|
|
|
```
|
|
|
|
|
|
|
|
* get the current score value
|
|
|
|
|
|
|
|
```
|
|
|
|
export function score() : number
|
|
|
|
```
|
|
|
|
|
|
|
|
### Countdown
|
|
|
|
|
|
|
|
If your game has a time limit, you can start a countdown in which case `game->current time` returns the remaining time.
|
|
|
|
|
|
|
|
* start a countdown with the maximum duration of the game in milliseconds.
|
|
|
|
|
|
|
|
```
|
|
|
|
export function startCountdown(ms: number)
|
|
|
|
```
|
|
|
|
|