How to Keep Score in a Game

Материал из Поле цифровой дидактики
Описание Как хранить результаты (очки) в игре
Область знаний Информатика
Область использования (ISTE) Computational Thinker
Возрастная категория 7


Поясняющее видео
Близкие рецепту понятия
Среды и средства для приготовления рецепта: Scratch, Snap!, Lua

This tutorial shows how to keep score in a game. First, make a variable named "score". How the game works defines which find of script should be used.

Color Sensing

If it is needed to detect when a sprite touching a particular color, use

when gf clicked
forever
if <touching color [#FFFFFF]?> then
change [score v] by (1)
end
end

If it is wanted to decrease the score when touching a color, change change [score v] by (1) to change [score v] by (-1).

Sprite Sensing

To sense when a sprite touching another sprite, replace <touching color [#FFFFFF]?> with <touching (sprite v)?>.

Click Sensing

To sense if a sprite is clicked, use:

when this sprite clicked
change [points v] by (...::grey)

or

when gf clicked
forever
if <<touching (Sprite v)?> and <mouse down?>> then
change [points v] by (...::grey)

Broadcasts

To use broadcasts, use

when I receive [increase score v]
change [score v] by (1)
when I receive [decrease score v]
change [score v] by (-1)