player object boilerplate
This commit is contained in:
parent
bdba4cc62f
commit
c5b8b324db
3 changed files with 25 additions and 0 deletions
1
main.lua
1
main.lua
|
|
@ -21,6 +21,7 @@ Area = require 'obj/Area'
|
||||||
GameObject = require 'obj/GameObject'
|
GameObject = require 'obj/GameObject'
|
||||||
|
|
||||||
-- game objects --
|
-- game objects --
|
||||||
|
Player = require 'obj/game/Player'
|
||||||
Circle = require 'obj/game/Circle'
|
Circle = require 'obj/game/Circle'
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
|
|
|
||||||
20
obj/game/Player.lua
Normal file
20
obj/game/Player.lua
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
---@class Player:GameObject
|
||||||
|
---@field area Area
|
||||||
|
---@field x number
|
||||||
|
---@field y number
|
||||||
|
---@field opts table|nil
|
||||||
|
local Player = GameObject:extend()
|
||||||
|
|
||||||
|
function Player:new(area, x, y, opts)
|
||||||
|
Player.super.new(self, area, x, y, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Player:update(dt)
|
||||||
|
Player.super.update(self, dt)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Player:draw()
|
||||||
|
Player.super.draw(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
return Player
|
||||||
|
|
@ -5,10 +5,14 @@ local Stage = Room:extend()
|
||||||
function Stage:new()
|
function Stage:new()
|
||||||
Stage.super.new(self)
|
Stage.super.new(self)
|
||||||
self.timer = Timer()
|
self.timer = Timer()
|
||||||
|
|
||||||
|
-- game objects
|
||||||
self.timer:every(2, function()
|
self.timer:every(2, function()
|
||||||
local latest_object = self.area:addGameObject('Circle', love.math.random(1, gw), love.math.random(1, gh))
|
local latest_object = self.area:addGameObject('Circle', love.math.random(1, gw), love.math.random(1, gh))
|
||||||
latest_object.timer:after(love.math.random(2, 4), function() latest_object:kill() end)
|
latest_object.timer:after(love.math.random(2, 4), function() latest_object:kill() end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
self.area:addGameObject('Player', gw/2, gh/2)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Stage:update(dt)
|
function Stage:update(dt)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue