# Pong

**URL:** https://forum.kirupa.com/t/pong/2887
**Category:** flash
**Created:** [March 17, 2002, 8:21pm UTC](https://forum.kirupa.com/t/pong/2887 "2002-03-17T20:21:40Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 17, 2002, 8:21pm UTC](https://forum.kirupa.com/t/pong/2887/1 "2002-03-17T20:21:40Z")

</div>

I am familiar with hit test, but how do you make a ball bounce off a wall with the same angle that it bounced on it with?\r\rex. it hits the wall at 45 degrees, and it bounces off the wall at 45 degrees\r\rThanks 4 your time!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 17, 2002, 8:28pm UTC](https://forum.kirupa.com/t/pong/2887/2 "2002-03-17T20:28:38Z")

</div>

You can see a bounce that way, but also as a change of speed. When the thing bounces against a vertical wall, the \_x speed just turns negative.\r\rTry this, I’m sure you can make this work.\r\rpom 0]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 17, 2002, 8:57pm UTC](https://forum.kirupa.com/t/pong/2887/3 "2002-03-17T20:57:26Z")

</div>

yea, that’s only part of it, i think i need to make the angle negitive or something…MORE HELP NEEDED PLEASE!!!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 17, 2002, 9:14pm UTC](https://forum.kirupa.com/t/pong/2887/4 "2002-03-17T21:14:31Z")

</div>

put the following code in a movie clip’s object actions. make the main stage 400x400.\ronClipEvent (load) {\r&nbsp &nbsp &nbsp &nbsp nXmov = (Math.random()\*5)+3;\r&nbsp &nbsp &nbsp &nbsp nYmov = (Math.random()\*5)+3;\r}\ronClipEvent (mouseUp) {\r&nbsp &nbsp &nbsp &nbsp nXmov = (Math.random()\*5)+3;\r&nbsp &nbsp &nbsp &nbsp nYmov = (Math.random()\*5)+3;\r}\ronClipEvent (enterFrame) {\r&nbsp &nbsp &nbsp &nbsp if (\_x+nXmov\<10) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp \_x = 10;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp nXmov \*= -1;\r&nbsp &nbsp &nbsp &nbsp } else if (\_x+nXmov\>390) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp \_x = 390;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp nXmov \*= -1;\r&nbsp &nbsp &nbsp &nbsp }\r&nbsp &nbsp &nbsp &nbsp if (\_y+nYmov\<10) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp \_y = 10;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp nYmov \*= -1;\r&nbsp &nbsp &nbsp &nbsp } else if (\_y+nYmov\>390) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp \_y = 390;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp nYmov \*= -1;\r&nbsp &nbsp &nbsp &nbsp }\r&nbsp &nbsp &nbsp &nbsp \_x += nXmov;\r&nbsp &nbsp &nbsp &nbsp \_y += nYmov;\r}\r\revery time you click, the speed will change.\r:) \rjeremy

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 17, 2002, 9:55pm UTC](https://forum.kirupa.com/t/pong/2887/5 "2002-03-17T21:55:18Z")

</div>

Sinf, you have a gift to use variable names that make your code look complicated !!\rTry this “light” version : draw a ball, turn it into a movie clip, and add the actions :

```auto
  onClipEvent (load) {\r\rspeedx = 5 ;\r\rspeedy = 3 ;\r\r}\r\ronClipEvent (enterFrame) {\r\rif (_x>250) {_x=250 ; speedx *=-1;}\r\relse if (_x<50) {_x=50 ; speedx *=-1;}\r\rif (_y>250) {_y=250 ; speedy *=-1;}\r\relse if (_y<50) {_y=50 ; speedy *=-1;}\r\r\r\r_x += speedx ;\r\r_y += speedy ;\r\r}

```

pom 0]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 17, 2002, 10:40pm UTC](https://forum.kirupa.com/t/pong/2887/6 "2002-03-17T22:40:38Z")

</div>

the problem with your code is that there is a possibility of an error where the clip will get ‘stuck’ bouncing in the general area of the border. flash has problems incrementing floating point numbers, so if your ‘speed’ was 5.05 you may encounter an error. also, if you are applying acceleration, or gravity, or other changes to the ‘speed’ then you will get an error more often than not when using your method.\ri used to do the exact same thing, and it worked fine as long as it was just a ball by itself and the ‘speed’ was always an integer, and it didn’t change.\r:) \rjeremy\r\rp.s. i use ‘mov’ for frame based movement, and ‘speed’ for time based movement.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 17, 2002, 10:58pm UTC](https://forum.kirupa.com/t/pong/2887/7 "2002-03-17T22:58:09Z")

</div>

Argghhh! You got me Austin Powers !\rOK, I agree, your code is better, no doubts about that. It’s just that I wanted to show something basic… I’ve been doing stuff with acceleration but never had any trouble with it. Interesting though. Thanks !\r\rpom 0]
