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
If you're using a tablet or iPad without a physical keyboard, you won't be able to use keyboard keys like the arrow keys in your project. Instead, we'll add simple on-screen buttons (using sprites) that you can tap to do the same things. This keeps your project working great! Just follow these steps wherever the lesson talks about pressing a key.
First, add a new sprite for your button:
Now, program your button sprite to make things happen when you tap it. Here's how it works for different situations:
Example 1: If the lesson uses a key to trigger an action on a specific sprite (like making something move, turn, or jump)
Instead of code like this on your target sprite:
when [left arrow v] key pressed
change x by (-10) // or any action
Or this:
if < key [left arrow v] pressed? > then
change x by (-10) // or any action
end
Add this code to your new button sprite:
when this sprite clicked
broadcast [do action v]
Then, on your target sprite, add this to receive the message:
when I receive [do action v]
change x by (-10) // or any action
Tap the button on the screen, and the action will happen, just like pressing the key! Use a unique broadcast name for each different action or key.
Example 2: If the lesson uses a key to change a variable (like adding to a score or setting a value)
Instead of code like this:
when [space v] key pressed
change [score v] by (1)
Or this:
if < key [space v] pressed? > then
change [score v] by (1)
end
Add a new button sprite. Then, put this code on the button sprite:
when this sprite clicked
change [score v] by (1)
(If the variable is "for this sprite only," make sure it's set to "for all sprites" so the button can change it.)
Tap the button, and the variable changes, no message needed since it's something shared!
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