Discuss Scratch

simo_montru
Scratcher
7 posts

Moving 2 sprites

Hi everyone, I'm new at Scratch and I just completed all the tutorials.

I want to ask you how can I move 2 sprite at the same time.

What I mean is to create an update of the tutorial “Create a pong game”, and let 2 users play a match (one user has some key in order to move his bas, the othe user has other key).
http://hausnes.no/blogg/wp-content/uploads/pong-game-screenshot.jpg

Thank you all

Last edited by simo_montru (Feb. 16, 2018 13:08:19)

python_megapixel
Scratcher
500+ posts

Moving 2 sprites

It's simplest to create a game where the paddles move horizontally (i.e left/right) instead of vertically (i.e. up/down)

Create two paddle sprites. Give them names so that you know which one is which. For example, TopPaddle and BottomPaddle
Add the code to make one sprite move based on the arrow keys:
when green flag clicked
forever //Constantly check to see if the keys are pressed
if <key [left arrow v] pressed?> then
move (-10) steps //Move left
end

if <key [right arrow v] pressed?> then
move (10) steps //Move right
end
end

Now, copy the code into the other paddle, but change and to some other keys. If you did this with A and S, you would get
when green flag clicked
forever //Constantly check to see if the keys are pressed
if <key [a v] pressed?> then
move (-10) steps //Move left
end

if <key [s v] pressed?> then
move (10) steps //Move right
end
end

You will also need to make changes to the ball code, to make it bounce off both paddles.
Change this:
<touching [Paddle v]?>

to this:

<<touching [TopPaddle v]?> or <touching [BottomPaddle v]?>> 

If you want to add a scoring system, create two variables, duplicate the scoring code and change one copy to top paddle and the top person's score and change the other copy to the bottom paddle and the bottom person's score.

Last edited by python_megapixel (Feb. 16, 2018 13:48:09)


pythonmegapixel he/him or they/them
I have nothing else to put here for now
MasterGamr13
Scratcher
1 post

Moving 2 sprites

how do i make it travel up and down.
golden_nugget2010
New to Scratch
1 post

Moving 2 sprites

hvkni

Powered by DjangoBB