The odd thing is that I dont get any error messages...

Code:
Code: Select all
function load()
love.filesystem.include("Points.lua")
env = love.physics.newWorld(0,0,love.graphics.getWidth(),love.graphics.getHeight(),0,0,false)
bounds = {}
for i,v in pairs( {
{1,love.graphics.getHeight(),0,0},
{love.graphics.getWidth(),1,0,0},
{-1,love.graphics.getHeight(),love.graphics.getWidth(),0},
{love.graphics.getWidth(),-1,0,love.graphics.getHeight()}}) do
bounds[i] = {}
bounds[i].body = love.physics.newBody(env,0,0,0)
bounds[i].shape = love.physics.newRectangleShape(bounds[i].body,unpack(v))
end
fireinterval = 0
bullets = {img = love.graphics.newImage("Bullet1.png")}
turret = {img = love.graphics.newImage("Turret1.png"), pos = Point(love.graphics.getWidth()/2,love.graphics.getHeight()+60)}
love.graphics.setBackgroundColor(127,127,255)
love.graphics.setFont(love.graphics.newFont(love.default_font,8))
mousepos = Point(love.graphics.getWidth()/2,love.graphics.getHeight()/2)
end
function fireBullet(pos,dir,mass,speed)
IsPoint(pos,true) IsPoint(dir,true)
dir = dir:normal(pos)
for i = 1,1000 do
if bullets[i] == nil then
bullets[i] = {}
bullets[i].body = love.physics.newBody(env,pos.x,pos.y,mass)
bullets[i].shape = love.physics.newCircleShape(bullets[i].body, 4)
bullets[i].body:setBullet(true)
bullets[i].body:setVelocity(dir.x*speed,dir.y*speed)
break
end
end
end
function unpdate(dt)
env:update(dt)
mousepos = Point(love.mouse.getPosition())
if love.mouse.isDown(love.mouse_left) then
fireinterval = fireinterval + dt
if fireinterval > 0.2 then
fireBullet(turret.pos,mousepos,5,1000)
fireinterval = 0
end
else fireinterval = 0 end
love.timer.sleep(5)
end
function draw()
for k,v in pairs(bullets) do
if type(k) == "number" then
love.graphics.draw(bullets.img,v.body:getPosition())
end
end
love.graphics.draw(turret.img,turret.pos.x,turret.pos.y)
love.graphics.draw("Number of shots:\n"..#bullets, mousepos.x+10,mousepos.y+10)
end
Code: Select all
point = {}
function IsPoint(self,assrt)
if assrt then
assert(type(self) == "table")
assert(type(self.x) == "number")
assert(type(self.y) == "number")
assert(getmetatable(self))
for k,v in pairs(getmetatable(self)) do
assert(v == point.mt[k])
end
else
if type(self) ~= "table" or type(self.x) ~= "number" or type(self.y) ~= "number" then return false end
for k,v in pairs(getmetatable(self)) do
if v ~= self[k] then return false end
end
return true
end
end
function Point(x,y)
local obj = {x = x or 0, y = y or 0}
setmetatable(obj, point.mt)
IsPoint(obj,true)
return obj
end
point.mt = {
__index = point,
__add = function(a,b)
IsPoint(a,true) IsPoint(b,true)
return Point(a.x+b.x,a.y+b.y)
end,
__sub = function(a,b)
IsPoint(a,true) IsPoint(b,true)
return Point(a.x-b.x,a.y-b.y)
end,
__unm = function(a)
return Point(-a.x,-b.y)
end,
__mul = function(a,b)
if type(a) == "number" then
return Point(a*b.x,a*b.y)
end
if type(b) == "number" then
return Point(a.x*b,a.y*b)
end
IsPoint(a,true) IsPoint(a,true)
return Point(a.x*b.x,a.y*b.y)
end,
__div = function(a,b)
if type(a) == "number" then
return Point(a/b.x,a/b.y)
end
if type(b) == "number" then
return Point(a.x/b,a.y/b)
end
IsPoint(a,true) IsPoint(b,true)
return Point(a.x/b.x,a.y/b.y)
end,
__concat = function(a,b)
if IsPoint(a) then
if IsPoint(b) then
return "("..a.x..","..a.y..")".."("..b.x..","..b.y..")"
end
return "("..a.x..","..a.y..")"..b
end
if IsPoint(b) then
return a.."("..b.x..","..b.y..")"
end
end,
}
function point:dist(p)
p = p or Point()
IsPoint(p,true)
local res = self-p
return math.sqrt(res.x^2+res.y^2)
end
function point:normal(p)
p = p or Point()
IsPoint(p,true)
return self/self:dist()+p
end