Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Paddle

Status
Not open for further replies.

DaveEire

MIS
Apr 3, 2001
2
IE

i am trying to create a simple paddle game and this is the code i have on the ball but when the ball hits the paddle it is only 50% chance that it works.
Could anyone take a look at this and see what i am doing wrong. Alternitavly if there is a better way of dooing this i would be intrested to hear about it.
Cheers
D


--code for the ball
property pX, pY, pAngle, pVel, xvel, yvel

on beginsprite me
set pX = 320
set pY = 240
set pAngle = 30
set pVel = 10
set xvel = pVel*Cos(pAngle * PI/180)
set yvel = pVel*Sin(pAngle * PI/180)
end beginsprite

on exitframe me
set pX = pX + xvel
set pY = pY + yvel

If pX > 625 then set xvel = -xvel
If pY > 465 then set yvel = -yvel
If pX < 15 then set xvel = -xvel

--if hits paddel
--sprite 3 is the movable paddle and it 70 pixels long
if ( (pY < 50) and ( pY > 15 ) and (pX > (the loch of sprite 3 - 35)) and (pX < (the loch of sprite 3 + 35 )) ) then

set yvel = -yvel

end if


set the loc of sprite ( the spritenum of me ) = point( pX,480 - pY)



end exitframe
 
I gave it a quick test and it seemed fine, but then I did a VERY rough test. All I can think off is that the ball can move more than 35 pixels in one jump hence going through the paddle. try changing pY > 15 to pY > 0.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top