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

#1 2009-11-02 20:58:59

mountain16
Scratcher
Registered: 2009-10-06
Posts: 4

Reflections in scratch (pong)

Hey all, im trying to make a pong game that uses reflections so the ball looks and feels natural when bouncing off of the walls. The only problem is, i dont know how to. ive been using a simple code that basically goes if direction >180 go to 45 degs. visa versa. Ive tryed looking around but I cant seem to find what Im looking for. What im asking for, is ideally either a step by step or an explanation on how angles work in scratch (as im new to scratch) please though, do not dumb down your code, as I would love to read over it.

Offline

 

#2 2009-11-02 21:45:26

mountain16
Scratcher
Registered: 2009-10-06
Posts: 4

Re: Reflections in scratch (pong)

:{

Offline

 

#3 2009-11-02 21:52:26

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: Reflections in scratch (pong)

Did you try the basic pong bouncing code?
[blocks]
<when green flag clicked>
<forever if><touching[ paddle or edge]
<point in direction ((  180 <+> <direction> ))
<end>
[/blocks]

Last edited by fg123 (2009-11-02 21:53:00)


Hai.

Offline

 

#4 2009-11-02 21:56:39

Flait7
Scratcher
Registered: 2008-04-14
Posts: 100+

Re: Reflections in scratch (pong)

If you want to make a mirror image.. if i understand properly  tongue  make a second sprite, that looks like the sprite being reflected, but facing the other direction, ( > would be the sprite and < would be the reflected sprite) then when > is moving, and hits the mirror <if><touching[ Mirror ]> <point in direction( 90 )> make this sprite (<) do <if><touching[ Mirror ]> <point in direction( -90 )> and depending on the angle of the mirror, it should look like it's being reflected


http://scratch.mit.edu/static/projects/Flait7/2248016_sm.pnghttp://scratch.mit.edu/static/projects/Flait7/1827934_sm.png

Offline

 

#5 2009-11-02 22:18:43

mountain16
Scratcher
Registered: 2009-10-06
Posts: 4

Re: Reflections in scratch (pong)

well I want it to bounce of the 2 paddles i have but there has to be the law of relction used. my code is <if><touching[ paddle 1
                             <if><(<direction> > 180  )>
                                      <turn cw( 45 )degrees>

and vica versa but the prob is, its using rotation so it breaks some of my boundries and it dosnt look natural.
and yes i have tried the basic 180-direction but it wont work going negs

Last edited by mountain16 (2009-11-02 22:32:44)

Offline

 

#6 2009-11-02 23:40:29

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

Re: Reflections in scratch (pong)

Try searching "Pong" and downloading projects to have a look.


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

 

#7 2009-11-03 16:13:08

Ssbrawl700
Scratcher
Registered: 2009-02-11
Posts: 100+

Re: Reflections in scratch (pong)

Wait so are u talking about shadows because things can only reflect an image if in front of a mirror.


Can you beat the ever-so challenging Keyboard Khaos?

Offline

 

#8 2009-11-03 18:07:41

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Reflections in scratch (pong)

http://scratch.mit.edu/projects/Locomule/737050
hope that helps some


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#9 2009-11-03 18:59:44

mountain16
Scratcher
Registered: 2009-10-06
Posts: 4

Re: Reflections in scratch (pong)

hey loco, yah that helps, but im just having a hard time wrapping my head around "shadows" as you were calling it SSbrawl. I dont know how to calculate angles at all and its kinda annoying.

Offline

 

#10 2009-11-06 01:33:45

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Reflections in scratch (pong)

One of they keys to my script is that it uses 2 variables to keep up with whether the ball is moving up or down and right or left. This is how it determines which formula to figure the bounce angle by and is why it always works whether it is a negative direction or not. Then you only need two formulas to calculate all possible angles...
direction * -1 (for bounces at the top and bottom)
180 - direction (for bounces at the left or right side)

You shouldn't have to any more than that to calculate every possible angle, if I am understanding your question correctly. Hope so  smile  This comes up so often in the forums, I am gonna do a tutorial application just on figuring reflections in Scratch.


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#11 2009-11-06 01:49:39

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Reflections in scratch (pong)

Try this one in the meantime. All it does is bounce a ball around. Not Pong, just a simple script for doing the reflections on all 4 sides of the stage but not at screen edges.
http://scratch.mit.edu/projects/Locomule/709464


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

Board footer