Compare commits
3 commits
89f9bd1913
...
c225cc6edf
| Author | SHA1 | Date | |
|---|---|---|---|
| c225cc6edf | |||
| fd69762121 | |||
| 16f9233ea8 |
4 changed files with 18 additions and 1 deletions
2
main.lua
2
main.lua
|
|
@ -60,6 +60,8 @@ function love.load()
|
|||
}
|
||||
}
|
||||
camera = Camera()
|
||||
|
||||
gotoRoom('Stage')
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
|
|
|
|||
|
|
@ -3,12 +3,14 @@
|
|||
---@class Area:Object
|
||||
---@field room Room
|
||||
---@field game_objects GameObject[]
|
||||
---@field world table|nil
|
||||
local Area = Object:extend()
|
||||
|
||||
---Instantiates area
|
||||
function Area:new(room)
|
||||
self.room = room
|
||||
self.game_objects = {}
|
||||
self.world = nil
|
||||
end
|
||||
|
||||
---Updates area
|
||||
|
|
@ -36,4 +38,10 @@ function Area:addGameObject(game_object_type, x, y, opts)
|
|||
return game_object
|
||||
end
|
||||
|
||||
---Initializes HC physics as a world
|
||||
---@param cell_size number|nil
|
||||
function Area:addPhysicsWorld(cell_size)
|
||||
self.world = HC(cell_size or 100)
|
||||
end
|
||||
|
||||
return Area
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ local Player = GameObject:extend()
|
|||
|
||||
function Player:new(area, x, y, opts)
|
||||
Player.super.new(self, area, x, y, opts)
|
||||
|
||||
self.w, self.h = 12, 12
|
||||
self.collider = self.area.world:circle(self.x, self.y, math.floor(self.w*0.8))
|
||||
end
|
||||
|
||||
function Player:update(dt)
|
||||
|
|
@ -15,6 +18,10 @@ end
|
|||
|
||||
function Player:draw()
|
||||
Player.super.draw(self)
|
||||
love.graphics.setColor(1, 0.4, 0.4)
|
||||
self.collider:draw()
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.circle('line', self.x, self.y, self.w)
|
||||
end
|
||||
|
||||
return Player
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ local Stage = Room:extend()
|
|||
|
||||
function Stage:new()
|
||||
Stage.super.new(self)
|
||||
|
||||
self.area:addPhysicsWorld()
|
||||
self.area:addGameObject('Player', gw/2, gh/2)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue