Compare commits
No commits in common. "abb33b4cbe2486363d94b8706dbc7f053f555eea" and "95bca26afe6814d8bce81e4d48f6695c2a28a5dc" have entirely different histories.
abb33b4cbe
...
95bca26afe
6 changed files with 5 additions and 55 deletions
4
main.lua
4
main.lua
|
|
@ -1,6 +1,6 @@
|
|||
-- debug --
|
||||
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
|
||||
DEBUG = false -- enable with f10
|
||||
DEBUG = true
|
||||
local lldebugger = require('lldebugger')
|
||||
lldebugger.start()
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
|
|
@ -9,7 +9,7 @@ if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
|
|||
local f = lldebugger.call(run, false, ...)
|
||||
return function(...) return lldebugger.call(f, false, ...) end
|
||||
end
|
||||
end
|
||||
else DEBUG = false end
|
||||
print('debug:', DEBUG)
|
||||
|
||||
-- libraries --
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ function Room:draw()
|
|||
camera:attach(0, 0, gw, gh)
|
||||
self:canvasDraw()
|
||||
camera:detach()
|
||||
if DEBUG then love.graphics.print('DEBUG', 2, 2) end
|
||||
love.graphics.setCanvas()
|
||||
|
||||
love.graphics.setColor(255, 255, 255, 255)
|
||||
|
|
|
|||
|
|
@ -27,10 +27,8 @@ function Player:new(area, x, y, opts)
|
|||
self.max_v = 100
|
||||
-- player acceleration
|
||||
self.a = 100
|
||||
-- attack rate
|
||||
self.ar = 0.24
|
||||
|
||||
self.timer:every(self.ar, function() self:shoot() end)
|
||||
self.timer:every(4, function() self:shoot() end)
|
||||
end
|
||||
|
||||
function Player:update(dt)
|
||||
|
|
@ -72,7 +70,6 @@ function Player:shoot()
|
|||
local d = 1.2*self.w
|
||||
local offset_x, offset_y = self.x + d*math.cos(self.r), self.y + d*math.sin(self.r)
|
||||
self.area:addGameObject('ShootEffect', offset_x, offset_y, {player = self, d = d})
|
||||
self.area:addGameObject('Projectile', offset_x, offset_y, {r = self.r})
|
||||
end
|
||||
|
||||
return Player
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
---@class Projectile:GameObject
|
||||
---@field r number
|
||||
---@field s number|nil
|
||||
---@field v number|nil
|
||||
local Projectile = GameObject:extend()
|
||||
|
||||
function Projectile:new(area, x, y, opts)
|
||||
Projectile.super.new(self, area, x, y, opts)
|
||||
|
||||
-- radius of collider
|
||||
self.s = opts.s or 2.5
|
||||
-- velocity
|
||||
self.v = opts.v or 200
|
||||
self.collider = self.area.world:circle(self.x, self.y, self.s)
|
||||
end
|
||||
|
||||
---Updates Projectile
|
||||
---@param dt number delta time
|
||||
function Projectile:update(dt)
|
||||
Projectile.super.update(self, dt)
|
||||
|
||||
-- update velocity
|
||||
--self.v = math.min(self.v + self.a*dt, self.max_v)
|
||||
|
||||
-- update position
|
||||
local vx = self.v * math.cos(self.r) -- velocity X
|
||||
local vy = self.v * math.sin(self.r) -- velocity Y
|
||||
self.x = self.x + vx * dt -- update position X
|
||||
self.y = self.y + vy * dt -- update position Y
|
||||
|
||||
-- move collision area
|
||||
self.collider:moveTo(self.x, self.y)
|
||||
end
|
||||
|
||||
---Draws Projectile
|
||||
function Projectile:draw()
|
||||
Projectile.super.draw(self)
|
||||
if DEBUG then
|
||||
love.graphics.setColor(1, 0, 0)
|
||||
self.collider:draw()
|
||||
end
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.circle('fill', self.x, self.y, self.s)
|
||||
end
|
||||
|
||||
return Projectile
|
||||
|
|
@ -23,7 +23,7 @@ end
|
|||
function ShootEffect:draw()
|
||||
ShootEffect.super.draw(self)
|
||||
pushRotateScale(self.x, self.y, self.player.r+math.pi/4)
|
||||
love.graphics.setColor(1,1,1)
|
||||
love.graphics.setColor(0.6, 0.5, 0.1)
|
||||
love.graphics.rectangle('fill', self.x - self.w/2, self.y - self.w/2, self.w, self.w)
|
||||
love.graphics.pop()
|
||||
end
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ end
|
|||
function CircleRoom:canvasDraw()
|
||||
CircleRoom.super.canvasDraw(self)
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.print('objects: '..#self.area.game_objects,2,gh-16)
|
||||
love.graphics.print('objects: '..#self.area.game_objects,2,2)
|
||||
end
|
||||
|
||||
return CircleRoom
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue