RFNXVfwQQPS4J

The first project in the Scratch environment - we teach the sprite to walk and draw

Source: licencja: CC 0.

Pierwszy projekt w środowisku Scratch – uczymy duszka chodzić i rysować

You will learn
  • how to move an object on the screen.

RueP4oSbUArUF1
nagranie abstraktu

Start the Scratch program. You can do it on your computer if you have it installed or open in your browser. Remind which part of the program window is the stage and which part is the script areascript areascript area. Where are the building blocks needed to build scripts? Almost every computer game hero can move around the screen. He cannot do it himself, he must be thoroughly instructed, where and how he should go. In Scratch, you'll build scripts that will allow your cat‑sprite to move around the screen. Remember that in the scripts area, you can place a lot of scripts for every spritespritesprite. Each of them can be located in any part of the script area. Your sprite can move in different directions by doing steps and making turns.

Task 1
RdwmZRCPvLkpD1
nagranie abstraktu

Build a script that, when launched by clicking on the green flaggreen flaggreen flag, will cause the cat-spritespritesprite to go 10 steps forward. You can try to create it yourself or use the instructions below.

  • Compare the results with a slideshow. Does your script look similar?

  • Think about what you need to do to make the sprite go backwards.

RakDrjthvyokV1
nagranie abstraktu

Instruction

Step 1.
Select the Events category and drag the blockblockblock when green flag clicked into the script areascript areascript area.

Step 2.
Choose the Motion category and drag the block move … steps to the script area and connect it to the green flaggreen flaggreen flag block.

Step 3.
Choose the Control category, drag the block, stop ...and connect it to the previous block. Click on the drop down list in this block and select this script option.

Step 4.
Check how the script works. Click on the green flag several times. The cat‑sprite should move 10 steps forward with each click. You can check if the cat‑sprite actually moves by looking at the counter in the upper right corner of the panel.

If the cat‑sprite reaches the edge of the stage, you can grab it with the mouse (e.g. by the tail) and move it to any place in the stage.

Step 5.
If your script works correctly, experiment with the amount of steps performed by the sprite. Increase or decrease the numbernumbernumber of steps in the blockblockblock window. Check what will happen if you enter a minus sign in front of the number of steps, e.g. -20.

R1RRUMQgh6Msf1
Pokaz przedstawia instrukcję tworzenia prostego skryptu w programie Scratch. Instrukcja obsługi z poziomu klawiatury: 1. Uruchomienie aplikacji - ENTER, 2. Na każdym ze slajdów czytany jest automatycznie tekst alternatywny po polsku, 3. Przy pierwszym uruchomieniu na pierwszym slajdzie, czytanie tekstu po angielsku - TAB, 4. Przejście między slajdami: do następnego slajdu - TAB, do poprzedniego slajdu - TAB + SHIFT, 5. Przejście do czytania napisu po angielsku - strzałka w górę + strzałka w dół (czyta tekst po angielsku widoczny na slajdzie).
Source: GroMar, licencja: CC BY 3.0.
Important!
R1ZUKHmdeW9PV1
nagranie abstraktu

The script would work the same way, if there was no blockblockblock, stop .... 
However, it is worth to learn good habits and finish the scripts so that you cannot attach any blocks to the top or bottom. You can now run the script using the green flaggreen flaggreen flag. It is often more convenient to run scripts using the keyboard. You can start each script with a separate keykeykey.

Task 2
RPYdE8ir1sH1K1
nagranie abstraktu

Practice running the script using the keyboard.

In your script, replace the block when green flag clicked with when ... keykeykey pressed selecting the space barspace barspace bar as the start key. Restart the script by pressing the space bar.

R1ZP0SCwd1C7c1
nagranie abstraktu

Instruction

Go to the Events category. Detach the blockblockblock with the green flaggreen flaggreen flag from the remaining blocks and drag it to the left. Enter a new block when ... keykeykey pressed and select the space from its drop‑down menudrop‑down menudrop‑down menu. Run your script again by pressing the space barspace barspace bar.

Your sprite can move, but only in one direction. You will get more motion possibilities when you apply turns.

Task 3
RKKraV8EFzv951
nagranie abstraktu

Create a new script that will turn the spritespritesprite when you press a selected key (e.g., right arrow or left arrow). Combine rotationrotationrotation with movement of the sprite. If you have no idea how to do it, follow the instructions.

R3LNQcoCobO3W1
nagranie abstraktu

Turning right

Create a new script:

  • Enter a blockblockblock when ... keykeykey pressed and select from the drop‑down menudrop‑down menudrop‑down menu the key with which you want to run the script.

  • Add a block turn right ... degrees. Enter the numbernumbernumber of degrees you want the sprite to turn by.

  • Add another block that moves the sprite with the required number of steps.

  • Add a block ending the script.

R3LNQcoCobO3W1
nagranie abstraktu

Turning left

Create a new script:

  • Enter a block when ... key pressed and select from the drop‑down menudrop‑down menudrop‑down menu the key with which you want to run the script.

  • Add a block turn left ... degrees. Enter the number of degrees you want the sprite to turn by.

  • Add another block that moves the sprite with the required number of steps.

  • Add a block ending the script.

R4YRMtqUvxHGC1
nagranie abstraktu

If we want the sprite to start its movement in the selected place, we can create the appropriate script. This script will move the sprite where we want it. You can also choose the direction in which it will look.

Task 4
RZWZGZnxcd2pf1
nagranie abstraktu

Find in the program the blocks shown in the figure and create a script to move the sprite to the desired location. Check what option in the blockblockblock point in direction ... you have to choose for the sprite to look down. Try out the settings you need to set for the blocks set x to ... and set y to ... for the spritespritesprite to be in the upper left corner of the stage.

R214Mz42CLR4Q1
Source: GroMar, licencja: CC BY 3.0.
R1SH6lLAoZb0p1
nagranie abstraktu

Your sprite can also leave a trailtrailtrail behind itself. Sometimes this function is useful if we want to check if the sprite is moving along the path we want. To create trails, we use blocks in the Pen category.

Task 5
RwVnWQgA7SfFB1
nagranie abstraktu

Build two additional scripts:

  1. The first script causes to lower the pen on the stage after pressing the selected key,

  2. The second script causes to raise the pen above the stage after pressing the selected key.

Once the scripts works expand them and add changing colour and thickness.
If you have no idea how to do it, look at the hint.

R15JbqY7xzNeX1
Source: GroMar, licencja: CC BY 3.0.
R14UGzYVJvcXB1
nagranie abstraktu

The spritespritesprite leaves a lot of trails. To get rid of them, you need to clear the stage. You can combine this action with placing the sprite in the starting position after restarting the program, e.g. using the following script.

RqyokFm0v5Sm91
Source: GroMar, licencja: CC BY 3.0.
R7AP9bAVhmMOd1
nagranie abstraktu

Saving the script

  • You can save the scripts you have created on your drive or in the cloud on the Scratch portal. If you want to save it on the portal, you must have an account there.

  • To save the program on your computer, select File/Save or File/Download to your computer (depending on whether you run Scratch locally or in a web browser). Then enter the filename, e.g. First program and click Save.

Remember:

RGt5D3dROITtI1
nagranie abstraktu

Using scripts, we can control the sprite movement in any direction; place it in the selected position. The sprite can leave a trailtrailtrail when moving around.

Exercises

Exercise 1
RQ5MOPlLmyHPY
Wersja alternatywna ćwiczenia: Which sentence is true? Możliwe odpowiedzi: 1. The green flag starts the program, while the red icon stops it., 2. Each script is executed step by step, according to the layout of the blocks., 3. At the end of each script there should not be a block stop ... ., 4. If we want the ghost to leave a trail, we have to lower the pen on the stage.
zadanie
Source: GroMar, licencja: CC BY 3.0.
Exercise 2

Write a script in which the sprite moves from one corner of the stage to another. Plan your route so that the sprite changes its direction at least three times.

Exercise 3

Explain in English how to build a script that causes the sprite to leave trails on the stage.

Exercise 4
RAvkAmQcHA1Sj
Wersja alternatywna ćwiczenia: Indicate which pairs of expressions or words are translated correctly. Możliwe odpowiedzi: 1. obszar skryptu - script area, 2. zielona flaga - green flag, 3. spacja - space, 4. duszek - sprite, 5. ślad - rotation, 6. klocek - key
zadanie
Source: GroMar, licencja: CC BY 3.0.
R1J5HMsJAIqAb1
Interaktywna gra, polegająca na łączeniu wyrazów w pary w ciągu jednej minuty. Czas zaczyna upływać wraz z rozpoczęciem gry. Jeden ruch to odkrywanie najpierw jednej potem drugiej karty z wyrazem. Każdy wyraz jest odczytywany. Kolejny ruch to odkrywanie trzeciej i czwartej karty. W ten sposób odsłuchasz wszystkie wyrazy. Nawigacja z poziomu klawiatury za pomocą strzałek, odsłuchiwanie wyrazów enterem lub spacją. Znajdź wszystkie pary wyrazów.
Source: Zespół autorski Politechniki Łódzkiej, licencja: CC BY 3.0.

Glossary

block
block

klocek

Rljbq3MQosrW61
wymowa w języku angielskim: block
drop‑down menu
drop‑down menu

rozwijalne menu

R1E9T9Gal506j1
wymowa w języku angielskim: drop‑down menu
green flag
green flag

zielona flaga

Rv939M6E9Hzy81
wymowa w języku angielskim: green flag
key
key

klawisz

R19f8BxBIFzOQ1
wymowa w języku angielskim: key
number
number

liczba

R1QkozXry1Sbd1
wymowa w języku angielskim: number
rotation
rotation

obrót

Rbf1UPWFj3WVr1
wymowa w języku angielskim: rotation
script area
script area

obszar skryptu

RJFnEJYQvL3qL1
wymowa w języku angielskim: script area
space bar
space bar

spacja

RpUDLiGE6eEhe1
wymowa w języku angielskim: space bar
sprite
sprite

duszek

Ry1BGluPEVXbZ1
wymowa w języku angielskim: sprite
trail
trail

ślad

R6qISvTf1Vp921
wymowa w języku angielskim: trail

Keywords

green flaggreen flaggreen flag

script areascript areascript area

space barspace barspace bar

spritespritesprite

trailtrailtrail