This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-09-17 20:17:15

wowwheeitsnicki
Scratcher
Registered: 2009-09-17
Posts: 1

Ping Pong game?

We have to make a pretty basic ping pong game at school: two paddles, one ball, etc. I had the whole thing done and working, and then my teacher announces that we're not allowed to use the "if on edge, bounce" script. This totally throws me off, because I have no idea how to make it without that. He said something about setting the x to an xVelocity variable and the y to a yVelocity variable, but whenever the ball hits the paddle, it just shoots into the left top corner. I can't figure it out.

Help?!

Offline

 

#2 2009-09-18 22:57:44

floatingmagictree
Scratcher
Registered: 2008-10-21
Posts: 1000+

Re: Ping Pong game?

Instead, make a sprite that goes around the border. Make it thin so it is hard to notice. Now make this:
<when green flag clicked>
<forever if <touching [border]>
<change direction by ( pick random (20) to (-20) )>
</forever>

Offline

 

#3 2009-09-18 22:59:36

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Ping Pong game?

Most pong scripts use a script something like this:

<when green flag clicked>
<point in direction( 90
<forever>
<move( whatever )steps>
<if><< <touching[ edge <or><touching[ paddle  >>
<point in direction( (( direction <-> 180 ))

Atleast I think this is how it works . . . Just add velocity from here.

Offline

 

#4 2009-09-19 03:20:04

Chrischb
Scratcher
Registered: 2008-07-24
Posts: 1000+

Re: Ping Pong game?

floatingmagictree wrote:

Instead, make a sprite that goes around the border. Make it thin so it is hard to notice. Now make this:
<when green flag clicked>
<forever if <touching [border]>
<change direction by ( pick random (20) to (-20) )>
</forever>

That would work, but the problem with it is that the bouncing is random; it's not at all accurate. Shadow_7283's does "bounce".


I fall: It's a tragedy. You fall: It's comedy.
Hmph enjoy your fall - I get a lovely spring... without pans of new leaves.

Offline

 

#5 2009-09-19 04:41:27

deatheater
Scratcher
Registered: 2008-04-11
Posts: 1000+

Re: Ping Pong game?

Oh and for all those previous scripts, you need a sprite called edge, drawn so it's on the top and bottom

Last edited by deatheater (2009-09-19 04:41:38)

Offline

 

#6 2009-09-21 21:25:58

SVN
Scratcher
Registered: 2009-09-21
Posts: 2

Re: Ping Pong game?

floatingmagictree wrote:

Instead, make a sprite that goes around the border. Make it thin so it is hard to notice. Now make this:
<when green flag clicked>
<forever if <touching [border]>
<change direction by ( pick random (20) to (-20) )>
</forever>

what happens if he notices you without the x velocity and y velocity thing?

Offline

 

Board footer