Compare commits

...

3 commits

Author SHA1 Message Date
c225cc6edf add and draw collision to player 2025-11-11 03:22:44 -03:00
fd69762121 instantiate collision engine in area 2025-11-11 03:22:25 -03:00
16f9233ea8 set 'Stage' as default room on boot 2025-11-11 03:21:58 -03:00
4 changed files with 18 additions and 1 deletions

View file

@ -60,6 +60,8 @@ function love.load()
}
}
camera = Camera()
gotoRoom('Stage')
end
function love.update(dt)

View file

@ -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

View file

@ -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

View file

@ -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