# Hittest for pong game

**URL:** <https://forum.kirupa.com/t/hittest-for-pong-game/113424>\
**Category:** Uncategorized\
**Created:** [June 17, 2004, 6:58pm UTC](https://forum.kirupa.com/t/hittest-for-pong-game/113424 "2004-06-17T18:58:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crippy](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@Crippy](https://forum.kirupa.com/u/Crippy)\
**Post date:** [June 17, 2004, 6:58pm UTC](https://forum.kirupa.com/t/hittest-for-pong-game/113424/1 "2004-06-17T18:58:52Z")

</div>

ok, i have a pong game and have got the bats working but i need the ball 2 do 2 things

a) i need the ball to just bounce around the screen randomly, and make a speedthing on it cause i cant get 1 to work

b) i need the hittest on the ball so it hits the paddles and bounces off them

im not sure if anyone needs this information but i have the inctance names, bat1 and bat2. and thats about it.

---

<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:** [June 18, 2004, 2:25am UTC](https://forum.kirupa.com/t/hittest-for-pong-game/113424/2 "2004-06-18T02:25:55Z")

</div>

Off the top of my head (Put this in the ball):

onClipEvent(load){  
speedX = 10;  
speedY = 10;  
counter = 10;//Or whatever. You’ll see what this is for  
stageWidth = //The stage width  
stageHeight = //The stage height  
}  
onClipEvent(enterFrame){  
if(counter \<= 0){  
counter = 10;  
speedX = random(//some number)+1;  
speedY = random(//some number)+1;  
}  
counter --;  
this.\_x += speedX;  
this.\_y += speedY;  
if((this.\_x \> stageWidth-(\_width/2)) or (this.\_x \< \_width/2) or (this.\_y \< \_height/2) or (this.\_y \> stageHeight - (\_height/2)) or (this.hitTest(\_root.bat1)) or (this.hitTest(\_root.bat2))){  
speedX = -speedX;  
speedY = -speedY;  
}  
}

That MAY work. Like I said, I just made that up off the top of my head
