Code: Select all
require 'rectangle'
local world = love.physics.newWorld(0, 0, love.graphics.getWidth(), love.graphics.getHeight())
local height = 200
local y = (love.graphics.getHeight() - height) / 2
local x1 = 200
local y1 = 250
local angle = 1.2
local moving = false
local ball = {}
ball.body = love.physics.newBody(world, x1, y1, 1)
ball.shape = love.physics.newCircleShape(ball.body, 0, 0, 10)
ball.shape:setFriction(0)
ball.body:setBullet(true)
local topWall = {}
topWall.body = love.physics.newBody(world, 0, y)
topWall.shape = love.physics.newRectangleShape(topWall.body, love.graphics.getWidth() / 2, 0, love.graphics.getWidth(), 1)
topWall.shape:setFriction(0)
local bottomWall = {}
bottomWall.body = love.physics.newBody(world, 0, y + height)
bottomWall.shape = love.physics.newRectangleShape(bottomWall.body, love.graphics.getWidth() / 2, 0, love.graphics.getWidth(), 1)
bottomWall.shape:setFriction(0)
function love.update(dt)
world:update(dt)
end
function love.draw()
love.graphics.line(0, y, love.graphics.getWidth(), y)
love.graphics.line(0, y + height, love.graphics.getWidth(), y + height)
love.graphics.circle('line', ball.body:getX(), ball.body:getY(), ball.shape:getRadius(), 50)
local lastX, lastY = x1, y1
-- draw the zig zag lines
for i=1, 6 do
local currX, currY, knownSide
if (angle < 0) then
knownSide = lastY - y
currY = y
else
knownSide = y + height - y1
currY = y + height
end
local missingSide = math.abs(knownSide / math.tan(angle))
currX = lastX + missingSide
love.graphics.line(lastX, lastY, currX, currY)
lastX, lastY = currX, currY
angle = angle * -1
end
end
function love.keypressed(key)
if (key == ' ' and not moving) then
moving = true
local factor = 10
ball.body:applyImpulse(math.cos(angle) * factor, math.sin(angle) * factor)
end
end
Any ideas? Sorry if this is confusing