Welcome to the 'Attack of the Dots' game project! In this exciting lesson, you will learn how to create a fun and interactive game using Scratch. You will control a colored disc in the middle of the screen, and your mission is to match the color of the disc with the colored dots that are attacking it. You will learn how to make the disc spin, clone the attacking dots, and detect the color of the dots. Let's get started and have some fun!
We've created a starter project that has some custom sprites for this game.
Go to the starter project at the below link and click on the Remix button to create a copy of the project.
In this game coloured balls will move towards the disc in the middle. You need to spin the wheel to match the colour of each ball as it hits the wheel. So we'll program the left and right arrow keys on our keyboard to spin the wheel in each direction.
Add the following code to the 'wheel' sprite:
when green flag clicked
go to x[0] y [0] // place it in the center
set size to [30]% // resize the wheel to 30%
forever
if < key (left arrow v) pressed? > then
turn ccw (3) degrees // turn anti clockwise
end
if < key (right arrow v) pressed? > then
turn cw (3) degrees // turn clockwise
end
end
Since your tablet or iPad doesn’t have a physical keyboard, you’ll use on-screen buttons to complete this task. Wherever the instructions in this lesson mention pressing a key, you’ll need to tap a button on the screen instead. So, while your steps are a little different, you’ll still be able to make everything happen in your project.
So for example, instead of doing either of these:
when [left arrow v] key pressed
move (10) steps
if < key [left arrow v] pressed? > then
move (10) steps
end
You need to add an on-screen button (like an arrow sprite) and use this code:
when this sprite clicked
move (10) steps
Now, just tap the button on the screen to perform the same action!
In the game, the balls should appear every few seconds, in a random position and start moving towards the wheel.
Add the following code to the green ball called 'Sprite1':
when green flag clicked
hide
forever
wait (pick random (4) to (8)) seconds // wait a random number of seconds
create clone of (myself v) // create the clone
end
when I start as a clone
go to (random position v) // start in a random position
point towards (wheel v) // point in the direction of the wheel
show
We don't want the balls appearing too close to the wheel as it won't give us much time to react. So to prevent this add the following code to 'Sprite1' which detects where the ball is when it's cloned and deletes it if it's too close.
when I start as a clone
go to (random position v)
point towards (wheel v)
show // add new code under here
if < ( distance to (wheel v)) < (100) > then
delete this clone
end