Log In  

I'm quite new to Pico-8 and video game programming and so started out by making a simple ping pong like game. I can't seem to figure out how to make my ball collide with the side of the paddle however which leads to the ball getting stuck inside the paddle, bouncing up and down, or just passing through the paddle.

Ideally I'd like the ball's x and y velocity to reverse when it hits the sides of the paddle.

Thanks in advance for any help!

'p' is my paddle object
'b' is my ball object
p.w is the paddle width
p.h is the paddle height

 --ball wall collision
 if b.x>=128 then b.dx*=-1 end
 if b.x<=0 then b.dx*=-1 end

 --ball paddle collision top
 if b.x>=p.x and b.x<=p.x+p.w and
 flr(b.y)==p.y-b.size then
   b.dy*=-1
 end
P#26447 2016-08-04 06:15 ( Edited 2016-08-04 10:15)

Have you looked at the first issue of the PICOZINE? There is a squash ball-paddle example in there which should help a bit.

In addition, you probably want to check if the b.y is somewhere between p.y and p.y+p.h, as well as b.x > p.x and b.x < p.x+p.w.

P#26448 2016-08-04 06:29 ( Edited 2016-08-04 10:29)
:: matt

there's also a collide.p8 demo builtin (type demos at command prompt)

P#26461 2016-08-04 09:25 ( Edited 2016-08-04 13:25)

I started following the tutorial on the picozine so I'll reread it and try again, thanks.

P#26465 2016-08-04 09:51 ( Edited 2016-08-04 13:51)

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-11-22 03:19 | 0.010s | 2097k | Q:15