Hi,
I decided to start learning Codea Lua by writing a game of Pong. The enclosed code is only my initial idea of movement of bat and ball, and therein a couple of questions…
Firstly there is probably a much more elegant way of moving the ball around than the way I’ve done it.
Secondly, if you increase velocity of the ball it seriously blurs, moreso horizontally than vertically for some reason.
Any suggestions would be most appreciated… next step is collision detection with the bat.
Many thanks,
David
PS Is there a specific way to cut and paste code to stop this strange formatting?
-- Pong 1.4
function setup()
x = 100 -- (x,y) ball coords
y = 100
a = 25 -- (a,b) bat coords
b = 100
moveRight = 1 -- flag 1 is right, 0 left
moveUp = 1 -- flag 1 is up, 0 down
watch("x")
watch("y")
watch("moveRight")
watch ("moveUp")
parameter("horiz_vel", 0, 10, 1)
parameter("vert_vel", 0, 10, 1)
end
function draw()
background(0,0,0)
fill(255, 255, 255, 255)
rect(a,b,15,50) -- bat
if moveRight == 1 then
fill(255, 255, 255, 255)
rect(x,y,10,10) -- ball l-r
x = x + horiz_vel
end
if x > 750 then
moveRight = 0
end
if moveRight == 0 then
fill(255, 255, 255, 255)
rect(x,y,10,10) -- ball r-l
x = x - horiz_vel
end
if x == 0 then
moveRight = 1
end
if moveUp == 1 then
fill(255, 255, 255, 255)
rect(x,y,10,10) -- ball move up
y = y + vert_vel
end
if y > 750 then
moveUp = 0
end
if moveUp == 0 then
fill(255, 255, 255, 255)
rect(x,y,10,10) -- ball move down
y = y - vert_vel
end
if x < 0 then
moveRight = 1
end
if y < 0 then
moveUp = 1
end
end
function touched (touch)
b = touch.y
end