Migrate docs from the other repo
This commit is contained in:
43
docs/reference/game/change-score-by.md
Normal file
43
docs/reference/game/change-score-by.md
Normal file
@ -0,0 +1,43 @@
|
||||
# Change Score By
|
||||
|
||||
The game library
|
||||
|
||||
The game library supports simple single-player time-based games. The player will ** add points to score**.
|
||||
|
||||
## Block Editor
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible and the score will display on the screen.
|
||||
|
||||

|
||||
|
||||
## KindScript
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
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)
|
||||
```
|
||||
|
||||
* get the current score value
|
||||
|
||||
```
|
||||
export function score() : number
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
30
docs/reference/game/change.md
Normal file
30
docs/reference/game/change.md
Normal file
@ -0,0 +1,30 @@
|
||||
# Change
|
||||
|
||||
The game library
|
||||
|
||||
### Change
|
||||
|
||||
Sprite will change the x position by this number
|
||||
|
||||
## Block Editor
|
||||
|
||||

|
||||
|
||||
## KindScript
|
||||
|
||||
Sprite will change the x position by this number
|
||||
|
||||
```
|
||||
export function changeXBy(_this: micro_bitSprites.LedSprite, x: number)
|
||||
```
|
||||
|
||||
Sprite will change the y position by this number
|
||||
|
||||
```
|
||||
export function changeYBy(_this: micro_bitSprites.LedSprite, y: number)
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
39
docs/reference/game/clear.md
Normal file
39
docs/reference/game/clear.md
Normal file
@ -0,0 +1,39 @@
|
||||
# Clear
|
||||
|
||||
The clear function for images. #clear #docs
|
||||
|
||||
Turn off all the pixels in an [Image](/microbit/reference/image/image).
|
||||
|
||||
### KindScript
|
||||
|
||||
```
|
||||
export function clear(img: micro_bit.Image)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* none
|
||||
|
||||
### Example
|
||||
|
||||
The following example turns off the pixels of `img` when the A input button is pressed:
|
||||
|
||||
```
|
||||
let img = images.createImage(`
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. . . . .
|
||||
`)
|
||||
img.showImage(0)
|
||||
input.onButtonPressed("A", () => {
|
||||
img.clear()
|
||||
img.showImage(0)
|
||||
})
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[Image](/microbit/reference/image/image), [show animation](/microbit/reference/basic/show-animation), [show image](/microbit/reference/images/show-image), [scroll image](/microbit/reference/images/scroll-image), [create image](/microbit/reference/images/create-image)
|
||||
|
161
docs/reference/game/game-library.md
Normal file
161
docs/reference/game/game-library.md
Normal file
@ -0,0 +1,161 @@
|
||||
# Game Library
|
||||
|
||||
The game library #docs
|
||||
|
||||
The game library supports simple single-player time-based games. The player has a **sprite**, number of **lives** and a **score**. The game has a sprite, number of **levels** and a **countdown clock**. The general goal of a game will be to move the sprite and achieve a top score before time runs out or the number of lives goes to zero.
|
||||
|
||||
## Block Editor
|
||||
|
||||

|
||||
|
||||
## KindScript
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(10000)
|
||||
```
|
||||
|
||||
### [Create sprite](/microbit/functions/game-library/create-sprite)
|
||||
|
||||
Create sprite with x, y coordinates and returns a LED Sprite. Create a new LED sprite.
|
||||
|
||||

|
||||
|
||||
```
|
||||
export function createSprite(x: number, y: number) : micro_bitSprites.LedSprite
|
||||
```
|
||||
|
||||
### [Move](/microbit/functions/game-library/move)
|
||||
|
||||
Sprite move by a certain number
|
||||
|
||||

|
||||
|
||||
```
|
||||
export function move(_this: micro_bitSprites.LedSprite, leds: number)
|
||||
```
|
||||
|
||||
### [Turn](/microbit/functions/game-library/turn)
|
||||
|
||||
Rotates a sprite to the right by a certain number of degrees
|
||||
|
||||

|
||||
|
||||
```
|
||||
export function turnRight(_this: micro_bitSprites.LedSprite, degrees: number)
|
||||
```
|
||||
|
||||
Rotates a sprite to the left by a certain number of degrees
|
||||
|
||||
```
|
||||
export function turnLeft(_this: micro_bitSprites.LedSprite, degrees: number)
|
||||
```
|
||||
|
||||
### [Change](/microbit/functions/game-library/change)
|
||||
|
||||
Sprite will change the x position by this number
|
||||
|
||||

|
||||
|
||||
```
|
||||
export function changeXBy(_this: micro_bitSprites.LedSprite, x: number)
|
||||
```
|
||||
|
||||
Sprite will change the y position by this number
|
||||
|
||||
```
|
||||
export function changeYBy(_this: micro_bitSprites.LedSprite, y: number)
|
||||
```
|
||||
|
||||
### [Set](/microbit/functions/game-library/set)
|
||||
|
||||
Sprite will change the x position by this number
|
||||
|
||||
```
|
||||
export function setX(_this: micro_bitSprites.LedSprite, x: number)
|
||||
```
|
||||
|
||||
Sprite will change the y position by this number
|
||||
|
||||

|
||||
|
||||
```
|
||||
export function changeYBy(_this: micro_bitSprites.LedSprite, y: number)
|
||||
```
|
||||
|
||||
### [If on edge, bounce](/microbit/functions/game-library/if-on-edge-bounce)
|
||||
|
||||
Sprite - If the sprite is on the edge, the sprite will bounce
|
||||
|
||||

|
||||
|
||||
```
|
||||
export function ifOnEdge_Bounce(_this: micro_bitSprites.LedSprite)
|
||||
```
|
||||
|
||||
### [Change score by](/microbit/functions/game-library/change-score-by)
|
||||
|
||||
When a player achieves a goal, you can increase the game score
|
||||
|
||||
* add score points to the current score
|
||||
|
||||

|
||||
|
||||
```
|
||||
export function addScore(points: number)
|
||||
```
|
||||
|
||||
### [Score](/microbit/functions/game-library/score)
|
||||
|
||||
* set the current score to a particular value.
|
||||
|
||||
```
|
||||
export function setScore(value: number)
|
||||
```
|
||||
|
||||
* get the current score value
|
||||
|
||||

|
||||
|
||||
```
|
||||
export function score() : number
|
||||
```
|
||||
|
||||
### [Countdown](/microbit/functions/game-library/start-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)
|
||||
```
|
||||
|
||||
### [Game over](/microbit/functions/game-library/game-over)
|
||||
|
||||
If the `life` reaches zero or the time expires (see countdown), the game enters the **game over** mode. When the game is over, `game->is running` returns false
|
||||
|
||||
* check if the game still running.
|
||||
|
||||
```
|
||||
let running = game.isRunning()
|
||||
```
|
||||
|
||||
You can also end the game by calling the `game -> game over` function:
|
||||
|
||||

|
||||
|
||||
```
|
||||
game.gameOver()
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
24
docs/reference/game/game-over.md
Normal file
24
docs/reference/game/game-over.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Game Over
|
||||
|
||||
The game library
|
||||
|
||||
The game library supports simple single-player time-based games. The game can end the game by calling the `game over` function
|
||||
|
||||
## Block Editor
|
||||
|
||||
You can end the game by calling the `game over ` function. In this example, if BBC micro:bit's answer to the question is GAME OVER, GAME OVER will be displayed to end the game.
|
||||
|
||||

|
||||
|
||||
## KindScript
|
||||
|
||||
You can end the game by calling the `game -> game over` function:
|
||||
|
||||
```
|
||||
game.gameOver()
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[game of chance](/microbit/lessons/game-of-chance)
|
||||
|
22
docs/reference/game/move.md
Normal file
22
docs/reference/game/move.md
Normal file
@ -0,0 +1,22 @@
|
||||
# Move
|
||||
|
||||
The game library
|
||||
|
||||
### Move
|
||||
|
||||
Sprite move by a certain number
|
||||
|
||||
## Block Editor
|
||||
|
||||

|
||||
|
||||
## KindScript
|
||||
|
||||
```
|
||||
export function move(_this: micro_bitSprites.LedSprite, leds: number)
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
32
docs/reference/game/position.md
Normal file
32
docs/reference/game/position.md
Normal file
@ -0,0 +1,32 @@
|
||||
# Position
|
||||
|
||||
The game library
|
||||
|
||||
### Create sprite
|
||||
|
||||
Reports the x or y position of a sprite on the LED screen
|
||||
|
||||
## Block Editor
|
||||
|
||||
Reports the x position of a sprite on the LED screen
|
||||
|
||||

|
||||
|
||||
## KindScript
|
||||
|
||||
Reports the x position of a sprite on the LED screen
|
||||
|
||||
```
|
||||
export function x(_this: micro_bitSprites.LedSprite) : number
|
||||
```
|
||||
|
||||
Reports the y position of a sprite on the LED screen
|
||||
|
||||
```
|
||||
export function y(_this: micro_bitSprites.LedSprite) : number
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
56
docs/reference/game/reports.md
Normal file
56
docs/reference/game/reports.md
Normal file
@ -0,0 +1,56 @@
|
||||
# Reports
|
||||
|
||||
The game library
|
||||
|
||||
### Reports
|
||||
|
||||
Reports the x or y position, the current direction of a sprite, or the brightness of a sprite on the LED screen
|
||||
|
||||
## Block Editor
|
||||
|
||||
Reports the x position of a sprite on the LED screen
|
||||
|
||||

|
||||
|
||||
Reports the y position of a sprite on the LED screen
|
||||
|
||||

|
||||
|
||||
Reports the brightness of a sprite on the LED screen
|
||||
|
||||

|
||||
|
||||
Reports the direction of a sprite on the LED screen
|
||||
|
||||

|
||||
|
||||
## KindScript
|
||||
|
||||
Reports the x position of a sprite on the LED screen
|
||||
|
||||
```
|
||||
export function x(_this: micro_bitSprites.LedSprite) : number
|
||||
```
|
||||
|
||||
Reports the y position of a sprite on the LED screen
|
||||
|
||||
```
|
||||
export function y(_this: micro_bitSprites.LedSprite) : number
|
||||
```
|
||||
|
||||
Reports the brightness of a sprite on the LED screen
|
||||
|
||||
```
|
||||
export function brightness(_this: micro_bitSprites.LedSprite) : number
|
||||
```
|
||||
|
||||
Reports the current direction of a sprite on the LED screen
|
||||
|
||||
```
|
||||
export function direction(_this: micro_bitSprites.LedSprite) : number
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
59
docs/reference/game/score.md
Normal file
59
docs/reference/game/score.md
Normal file
@ -0,0 +1,59 @@
|
||||
# Score
|
||||
|
||||
The game library #docs
|
||||
|
||||
The game library supports simple single-player games. The player has a **score**.
|
||||
|
||||
## Block Editor
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` and adds 1 point to score that will be displayed on the BBC micro:bit screen
|
||||
|
||||

|
||||
|
||||
## KindScript
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
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)
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
57
docs/reference/game/start-countdown.md
Normal file
57
docs/reference/game/start-countdown.md
Normal file
@ -0,0 +1,57 @@
|
||||
# Start Countdown
|
||||
|
||||
The game library #docs
|
||||
|
||||
The game library supports simple single-player time-based games. The general goal of a game will be to achieve a top score before time runs out of time.
|
||||
|
||||
## Block Editor
|
||||
|
||||

|
||||
|
||||
## KindScript
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
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)
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
24
docs/reference/game/touching.md
Normal file
24
docs/reference/game/touching.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Touching
|
||||
|
||||
The game library
|
||||
|
||||
### Touching
|
||||
|
||||
Reports true if sprite is touching specified sprite
|
||||
|
||||
## Block Editor
|
||||
|
||||

|
||||
|
||||
## KindScript
|
||||
|
||||
Reports true if sprite is touching specified sprite
|
||||
|
||||
```
|
||||
export function isTouching(_this: micro_bitSprites.LedSprite, other: micro_bitSprites.LedSprite) : boolean
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
30
docs/reference/game/turn.md
Normal file
30
docs/reference/game/turn.md
Normal file
@ -0,0 +1,30 @@
|
||||
# Turn
|
||||
|
||||
The game library
|
||||
|
||||
Rotates a sprite to the right by a certain number of degrees
|
||||
|
||||
## Block Editor
|
||||
|
||||
Rotates a sprite to the right by a certain number of degrees
|
||||
|
||||

|
||||
|
||||
## KindScript
|
||||
|
||||
Rotates a sprite to the right by a certain number of degrees
|
||||
|
||||
```
|
||||
export function turnRight(_this: micro_bitSprites.LedSprite, degrees: number)
|
||||
```
|
||||
|
||||
Rotates a sprite to the left by a certain number of degrees
|
||||
|
||||
```
|
||||
export function turnLeft(_this: micro_bitSprites.LedSprite, degrees: number)
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
Reference in New Issue
Block a user