Log In  

I am trying to do a simple game of pong for class and am having trouble. I have got the ball and the paddle. Now I am having trouble making the 2 collide. I am trying to get the ball to turn a different color when collided with the paddle.
I am also having trouble coding to get my paddle to stop when it hits the end of the screen so it does not disappear. Any advice would be much appreciated. I have attached my code so far that I have been working on. Thank you

ball_x = 3
x_speed = 1
ball_y = 15
y_speed = 1
ball_round = 3
col = 7
x=1
x1=5
y=127
y1=1
speed=5

function _init()
cls()
end

function _update()
buttpress = false

if btn(0) then speed =-5 end
if btn(1) then speed+=5 end
if not (buttpress) then
speed = speed/1.7
end
x+=speed

ball_y = ball_y+y_speed
ball_x = ball_x+x_speed

if ball_x > 127
then x_speed = -2
end

if ball_x < 0
then x_speed = 2
end

if ball_y > 127
then y_speed = -2
end

if ball_y < 0
then y_speed = 2
end

end

function _draw()
cls()
circfill(ball_x,ball_y,ball_round,col)
rect( x, y, x+8, y+1, 8)
end

P#67908 2019-09-19 20:20 ( Edited 2019-09-19 20:21)


[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 19:22:57 | 0.005s | Q:11