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]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-11-13 06:32 | 0.009s | 2097k | Q:13