Compare commits
5 commits
95bca26afe
...
abb33b4cbe
| Author | SHA1 | Date | |
|---|---|---|---|
| abb33b4cbe | |||
| 9d06b5d50e | |||
| 429f8ef813 | |||
| b79c2cf866 | |||
| 492da41dac |
6 changed files with 55 additions and 5 deletions
4
main.lua
4
main.lua
|
|
@ -1,6 +1,6 @@
|
|||
-- debug --
|
||||
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
|
||||
DEBUG = true
|
||||
DEBUG = false -- enable with f10
|
||||
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
|
||||
else DEBUG = false end
|
||||
end
|
||||
print('debug:', DEBUG)
|
||||
|
||||
-- libraries --
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ 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,8 +27,10 @@ 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(4, function() self:shoot() end)
|
||||
self.timer:every(self.ar, function() self:shoot() end)
|
||||
end
|
||||
|
||||
function Player:update(dt)
|
||||
|
|
@ -70,6 +72,7 @@ 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
|
||||
|
|
|
|||
46
obj/game/Projectile.lua
Normal file
46
obj/game/Projectile.lua
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
---@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(0.6, 0.5, 0.1)
|
||||
love.graphics.setColor(1,1,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,2)
|
||||
love.graphics.print('objects: '..#self.area.game_objects,2,gh-16)
|
||||
end
|
||||
|
||||
return CircleRoom
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue