|
@@ -4,6 +4,7 @@
|
|
-- script: lua
|
|
-- script: lua
|
|
|
|
|
|
t=0
|
|
t=0
|
|
|
|
+dt=0
|
|
x=96
|
|
x=96
|
|
y=24
|
|
y=24
|
|
|
|
|
|
@@ -115,23 +116,80 @@ function draw_balls_and_lasers()
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+function circleRect(cx, cy, radius, rx, ry, rw, rh)
|
|
|
|
+
|
|
|
|
+ -- temporary variables to set edges for testing
|
|
|
|
+ local testX = cx
|
|
|
|
+ local testY = cy
|
|
|
|
+
|
|
|
|
+ -- which edge is closest?
|
|
|
|
+ if cx < rx then testX = rx -- test left edge
|
|
|
|
+ elseif cx > rx+rw then testX = rx+rw end -- right edge
|
|
|
|
+ if cy < ry then testY = ry -- top edge
|
|
|
|
+ elseif cy > ry+rh then testY = ry+rh end -- bottom edge
|
|
|
|
+
|
|
|
|
+ -- get distance from closest edges
|
|
|
|
+ local distX = cx-testX
|
|
|
|
+ local distY = cy-testY
|
|
|
|
+ local distance = math.sqrt( (distX*distX) + (distY*distY) )
|
|
|
|
+
|
|
|
|
+ -- if the distance is less than the radius, collision!
|
|
|
|
+ if distance <= radius then
|
|
|
|
+ return true
|
|
|
|
+ end
|
|
|
|
+ return false
|
|
|
|
+end
|
|
|
|
+
|
|
function check_ball_collisions(ball)
|
|
function check_ball_collisions(ball)
|
|
for row=0,num_rows-1 do
|
|
for row=0,num_rows-1 do
|
|
for col=0,num_cols-1 do
|
|
for col=0,num_cols-1 do
|
|
blockVal = blocks[row][col]
|
|
blockVal = blocks[row][col]
|
|
if blockVal > 0 then
|
|
if blockVal > 0 then
|
|
- if ball.x >= col * blockWidth and ball.x <= col * blockWidth + blockWidth then
|
|
|
|
- if ball.y >= row * blockHeight and ball.y <= row * blockHeight + blockHeight then
|
|
|
|
- if row * blockHeight - ball.y <= 1 or row * blockHeight + blockHeight - ball.y <= 1 then
|
|
|
|
- ball.vy = ball.vy * -1
|
|
|
|
- blocks[row][col] = blockVal - 1
|
|
|
|
- freeze = true
|
|
|
|
- else
|
|
|
|
- ball.vx = ball.vx * -1
|
|
|
|
- blocks[row][col] = blockVal - 1
|
|
|
|
- freeze = true
|
|
|
|
- end
|
|
|
|
|
|
+ local blockX = col * blockWidth
|
|
|
|
+ local blockY = row * blockHeight
|
|
|
|
+ -- if ball.x >= blockX then
|
|
|
|
+
|
|
|
|
+ -- end
|
|
|
|
+ -- if ball.x >= col * blockWidth and ball.x <= col * blockWidth + blockWidth then
|
|
|
|
+ -- if ball.y >= row * blockHeight and ball.y <= row * blockHeight + blockHeight then
|
|
|
|
+ -- if row * blockHeight - ball.y <= 1 or row * blockHeight + blockHeight - ball.y <= 1 then
|
|
|
|
+ -- ball.vy = ball.vy * -1
|
|
|
|
+ -- blocks[row][col] = blockVal - 1
|
|
|
|
+ -- freeze = true
|
|
|
|
+ -- else
|
|
|
|
+ -- ball.vx = ball.vx * -1
|
|
|
|
+ -- blocks[row][col] = blockVal - 1
|
|
|
|
+ -- freeze = true
|
|
|
|
+ -- end
|
|
|
|
+ -- end
|
|
|
|
+ -- end
|
|
|
|
+
|
|
|
|
+ if circleRect(ball.x, ball.y, 2, blockX, blockY, blockWidth, blockHeight) then
|
|
|
|
+ -- bottom
|
|
|
|
+ if ball.y <= blockY - (blockHeight/2) then
|
|
|
|
+ -- ball.y = blockY+1
|
|
|
|
+ ball.vy = ball.vy * -1
|
|
|
|
+ return
|
|
|
|
+ end
|
|
|
|
+ -- top
|
|
|
|
+ if ball.y >= blockY + (blockHeight/2) then
|
|
|
|
+ -- ball.y = blockY-1
|
|
|
|
+ ball.vy = ball.vy * -1
|
|
|
|
+ return
|
|
|
|
+ end
|
|
|
|
+ -- left
|
|
|
|
+ if ball.x < blockX - (blockWidth/2) then
|
|
|
|
+ -- ball.x = blockX-1
|
|
|
|
+ ball.vx = ball.vx * -1
|
|
|
|
+ return
|
|
end
|
|
end
|
|
|
|
+ -- right
|
|
|
|
+ if ball.x > blockX then
|
|
|
|
+ -- ball.x = blockX+1
|
|
|
|
+ ball.vx = ball.vx * -1
|
|
|
|
+ return
|
|
|
|
+ end
|
|
|
|
+ freeze = true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
@@ -212,8 +270,13 @@ end
|
|
generate_grid()
|
|
generate_grid()
|
|
|
|
|
|
function TIC()
|
|
function TIC()
|
|
|
|
+ if not freeze then
|
|
|
|
+ t=time()
|
|
|
|
+ end
|
|
cls(0)
|
|
cls(0)
|
|
|
|
|
|
|
|
+ draw_blocks()
|
|
|
|
+
|
|
if launchMode then
|
|
if launchMode then
|
|
if launchBalls > 0 then
|
|
if launchBalls > 0 then
|
|
if launchBallTimer == 0 then
|
|
if launchBallTimer == 0 then
|
|
@@ -246,12 +309,7 @@ function TIC()
|
|
draw_preview()
|
|
draw_preview()
|
|
end
|
|
end
|
|
|
|
|
|
- draw_blocks()
|
|
|
|
draw_debug()
|
|
draw_debug()
|
|
-
|
|
|
|
- if not freeze then
|
|
|
|
- t=t+1
|
|
|
|
- end
|
|
|
|
end
|
|
end
|
|
|
|
|
|
-- <TILES>
|
|
-- <TILES>
|