Hot or cold game project edits (#596)
This commit is contained in:
parent
a0529828d9
commit
7ef65715d7
@ -1,4 +1,4 @@
|
||||
# Hot Or Cold
|
||||
# Hot or Cold
|
||||
|
||||
## @description A Hot-or-Cold treasure hunt game
|
||||
|
||||
@ -12,14 +12,14 @@ https://youtu.be/nbRfNug-RkY
|
||||
|
||||
## Beacons
|
||||
|
||||
In this game, players are looking for hidden @boardname@ that emit radio signals.
|
||||
The hidden @boardname@ are called **beacons**.
|
||||
In this game, players are looking for a hidden @boardname@ that emits a radio signal.
|
||||
Hidden @boardname@s are called **beacons**.
|
||||
|
||||
## Setting up the radio
|
||||
### Setting up the radio
|
||||
|
||||
We set the radio group to ``1`` to make sure all the players are using the same group.
|
||||
We also tell the @boardname@ to transmit its serial number (that's a unique number that identifies it)
|
||||
so that the player can tell apart each beacon. We also reduce the power of the antenna to reduce the range of transmission.
|
||||
We set the radio group to ``1`` and all the players use the same group.
|
||||
The @boardname@ transmits its serial number (that's a unique number that identifies it)
|
||||
so that players can tell one beacon apart from another. Also, the power of the antenna is reduced to shorten the range of transmission.
|
||||
|
||||
```block
|
||||
radio.setGroup(1)
|
||||
@ -27,12 +27,9 @@ radio.setTransmitSerialNumber(true)
|
||||
radio.setTransmitPower(6)
|
||||
```
|
||||
|
||||
## Beacon gotta beam
|
||||
|
||||
The beacon simply needs to send a radio message every now and then. To pace it out,
|
||||
we add some ``|show icon|`` blocks to animate the screen.
|
||||
|
||||
### Beacon gotta beam
|
||||
|
||||
The beacon just needs to send a radio message every now and then. So, to pace the transmits and give some visual feedback, we add some ``||basic:show icon||`` blocks to animate the screen.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
@ -45,18 +42,17 @@ radio.setTransmitSerialNumber(true)
|
||||
radio.setTransmitPower(6)
|
||||
```
|
||||
|
||||
## Hide the beacons
|
||||
### Hide the beacons
|
||||
|
||||
Download the code to your beacon @boardname@ and hide them!
|
||||
Download the code to each beacon @boardname@ and hide them!
|
||||
|
||||
## Hunters
|
||||
|
||||
The hunter @boardname@ look for beacons.
|
||||
The hunter @boardname@ looks for beacons.
|
||||
|
||||
## Is the beacon close?
|
||||
### Is the beacon close?
|
||||
|
||||
To determine how far or close, we use the signal strength of each radio packet sent by the beacons. The signal
|
||||
strength ranges from ``-128db`` (weak) to ``-42db`` (very strong).
|
||||
To determine how far away or how close they are, we use the signal strength of each radio packet sent by the beacons. The signal strength ranges from ``-128db`` (weak) to ``-42db`` (very strong).
|
||||
|
||||
```blocks
|
||||
radio.onDataPacketReceived( ({ receivedNumber, signal }) => {
|
||||
@ -65,19 +61,27 @@ radio.onDataPacketReceived( ({ receivedNumber, signal }) => {
|
||||
radio.setGroup(1)
|
||||
```
|
||||
|
||||
Take notes of the values as you move around the beacon.
|
||||
Test and record the signal values as you move around a beacon, moving closer and farther away:
|
||||
|
||||
* hot signal value: ``_________________``
|
||||
* mild signal value: ``_________________``
|
||||
* cold signal value: ``_________________``
|
||||
| | |
|
||||
|-|-|
|
||||
| Hot signal value: | ``_________________`` |
|
||||
| Warm signal value: | ``_________________`` |
|
||||
| Cold signal value: | ``_________________`` |
|
||||
|
||||
## Hot or cold?
|
||||
### Hot or cold?
|
||||
|
||||
The hunter screen displays ``SmallDiamond`` on the screen if the beacon is far, ``Diamond`` mildly close and ``Square`` if it is close. Use the ``signal`` values collected in the previous step to determine when to show those letters.
|
||||
The hunter's screen will display:
|
||||
|
||||
Here is an example that uses ``-95`` and less for cold, between ``-95`` and ``-80`` for mild and above ``-80`` for hot. Use your own values based on the room setup or the hidding place.
|
||||
* ``SmallDiamond``: if the beacon is far (cold).
|
||||
* ``Diamond``: if the beacon is relatively close (warm).
|
||||
* ``Square``: if the beacon is really close (hot).
|
||||
|
||||
To make the program more responsive, we add a ``|led stop animation|`` to cancel any icon animation when a new beacon packet comes.
|
||||
Use the ``signal`` values collected in the previous step to determine when to show each icon.
|
||||
|
||||
Here is an example that uses ``-95`` or less for cold, between ``-95`` and ``-80`` for warm, and ``-80`` or above for hot. You can change these values to account for your room setup or conditions of your hidding place.
|
||||
|
||||
To make the program more responsive, add a ``||led:stop animation||`` to cancel icon animations when a new beacon packet comes in.
|
||||
|
||||
```blocks
|
||||
radio.onDataPacketReceived( ({ receivedNumber, signal }) => {
|
||||
@ -95,26 +99,25 @@ radio.setGroup(1)
|
||||
|
||||
Download the code and play the game!
|
||||
|
||||
## Extra: Multiple beacons
|
||||
## Expand the game: multiple beacons
|
||||
|
||||
We're making the game more interresting by counting how many beacons a player has seen so far.
|
||||
We'll making the game more interesting by counting how many beacons the hunting player has seen so far.
|
||||
|
||||
## Remember the beacons
|
||||
### Remember the beacons
|
||||
|
||||
Remember that the beacon was configured to transmit its serial number? We can use this information
|
||||
to determine if we've visited a beacon for the first time.
|
||||
Do you remember that the beacon was configured to transmit its serial number? We can use this information
|
||||
to determine if a beacon is new or if it's one we've seen before.
|
||||
|
||||
To do so, we are going to add an **array** variable that will hold all the beacon serial numbers seen so far.
|
||||
To do so, we add an **[array](/types/array)** variable that will hold all the beacon serial numbers seen so far.
|
||||
|
||||
```block
|
||||
let beacons: number[] = [0]
|
||||
```
|
||||
|
||||
Whenever we receive a new packet, we are going to check if the ``beacons`` already
|
||||
contains the serial number. If not, we add the serial number at the end of ``beacons`` and increment the ``|game score|``.
|
||||
Whenever we receive a new packet, we are going to check if the ``beacons`` array already
|
||||
contains the serial number. If not, we add the serial number at the end of ``beacons`` and increment the ``||game:score||``.
|
||||
|
||||
To check if an ``array`` contains an element, we use the ``|find index of|`` block which returns ``-1``
|
||||
if the value is not found.
|
||||
To check if an array contains an certain element, we use the ``||arrays:find index of||`` block which returns ``-1`` if the element is not found.
|
||||
|
||||
```blocks
|
||||
let beacons: number[] = [0]
|
||||
@ -127,9 +130,9 @@ radio.onDataPacketReceived( ({ receivedNumber, signal, serial }) => {
|
||||
})
|
||||
```
|
||||
|
||||
## Show my score
|
||||
### Show my score
|
||||
|
||||
To see the current score, we add a ``|on button pressed|`` that displays the score on screen when ``A`` is pressed.
|
||||
To see the current score, we add an ``||input:on button pressed||`` that displays the score on the screen when the **A** button is pressed.
|
||||
|
||||
```block
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
@ -137,9 +140,9 @@ input.onButtonPressed(Button.A, () => {
|
||||
})
|
||||
```
|
||||
|
||||
## All together
|
||||
### All together
|
||||
|
||||
The hunter code with all th pieces together looks like this now. Download it and try it out with multiple beacons!
|
||||
The hunter code with all th pieces together looks like this now. Download and try it out with multiple beacons!
|
||||
|
||||
```blocks
|
||||
let beacons: number[] = [0];
|
||||
|
Loading…
Reference in New Issue
Block a user