moved values into the global tree
This commit is contained in:
parent
ad77a92106
commit
9abb55dd1d
@ -122,7 +122,8 @@ function Character:update(dt)
|
||||
self.animationTable[self.state]:update(dt)
|
||||
end
|
||||
|
||||
function Character:draw(camera)
|
||||
function Character:draw()
|
||||
local camera = Tree.level.camera
|
||||
self.animationTable[self.state]:draw(AssetBundle.files.sprites.character[self.state], self.position.x,
|
||||
self.position.y, nil, 1 / camera.pixelsPerMeter, 1 / camera.pixelsPerMeter, 38, 47)
|
||||
end
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
--- @class AssetBundle
|
||||
--- @field root string Path to the tree root
|
||||
--- @field files table
|
||||
local AssetBundle = {
|
||||
root = "/assets",
|
||||
files = {}
|
||||
}
|
||||
|
||||
--- Loads assets into the tree.
|
||||
--- Calls [onFileLoading] whenever a file is loaded.
|
||||
--- @param onFileLoading? fun(path: string): AssetBundle | nil
|
||||
function AssetBundle:load(onFileLoading)
|
||||
local callback = onFileLoading or function(path)
|
||||
print("[AssetBundle]: loading " .. path)
|
||||
@ -29,6 +35,7 @@ function AssetBundle:load(onFileLoading)
|
||||
end
|
||||
|
||||
self.files = enumerate(self.root)
|
||||
return self
|
||||
end
|
||||
|
||||
function AssetBundle.loadFile(path)
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
local Vec3 = require "lib/vec3"
|
||||
local tree = require "lib/tree"
|
||||
|
||||
local EPSILON = 0.001
|
||||
|
||||
@ -25,7 +24,7 @@ end
|
||||
|
||||
---@todo Отрефакторить и вынести кнопки управления в controls, не должно быть таких ужасных проверок
|
||||
function camera:update(dt)
|
||||
local ps = tree.instance().panning
|
||||
local ps = Tree.panning
|
||||
if ps.delta:length() > 0 then
|
||||
local worldDelta = ps.delta:scale(1 / (self.pixelsPerMeter * self.scale)):scale(dt):scale(self.speed)
|
||||
self.velocity = self.velocity + worldDelta
|
||||
|
||||
@ -18,6 +18,7 @@ function level:update(dt)
|
||||
utils.each(self.characters, function(el)
|
||||
el:update(dt)
|
||||
end)
|
||||
self.camera:update(dt)
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
15
lib/tree.lua
15
lib/tree.lua
@ -3,15 +3,8 @@
|
||||
--- В love.update обновлять, в love.draw читать
|
||||
|
||||
|
||||
local tree
|
||||
|
||||
local function instance()
|
||||
tree = tree or {
|
||||
panning = require "lib/panning"
|
||||
}
|
||||
return tree
|
||||
end
|
||||
|
||||
return {
|
||||
instance = instance
|
||||
Tree = {
|
||||
panning = require "lib/panning",
|
||||
assets = (require "lib/asset_bundle"):load(),
|
||||
level = (require "lib/level"):new() -- для теста у нас только один уровень, который сразу же загружен
|
||||
}
|
||||
|
||||
41
main.lua
41
main.lua
@ -1,50 +1,33 @@
|
||||
-- CameraLoader = require 'lib/camera'
|
||||
|
||||
require "character"
|
||||
|
||||
local camera = require 'lib/camera'
|
||||
local Vec3 = require "lib/vec3"
|
||||
local tree = require "lib/tree"
|
||||
local AssetBundle = require "lib/asset_bundle"
|
||||
require "lib/tree"
|
||||
|
||||
function love.conf(t)
|
||||
t.console = true
|
||||
end
|
||||
|
||||
function love.load()
|
||||
AssetBundle:load()
|
||||
|
||||
Camera = camera.new()
|
||||
Camera.position = Vec3({})
|
||||
-- PlayerFaction = Faction
|
||||
|
||||
-- Hero1 = Character:create("Petya", 10)
|
||||
-- Hero2 = Character:create("Andrysha", 12)
|
||||
|
||||
Hero = CreateCharacter("Hero", AssetBundle.files.sprites.character)
|
||||
Hero = CreateCharacter("Hero", Tree.assets.files.sprites.character)
|
||||
|
||||
-- PlayerFaction.characters = { Hero1, Hero2 }
|
||||
love.window.setMode(1080, 720, { resizable = true, msaa = 4, vsync = true })
|
||||
end
|
||||
|
||||
---@todo Вынести это в свое поле в дереве глобального состояния уровня
|
||||
-- local cameraPos = Vec3({})
|
||||
-- Camera:lockPosition(cameraPos.x, cameraPos.y, Camera.smooth.damped(10))
|
||||
|
||||
function love.update(dt)
|
||||
Camera:update(dt)
|
||||
tree.instance().panning:update(dt)
|
||||
|
||||
Tree.panning:update(dt)
|
||||
Tree.level:update(dt)
|
||||
Hero:update(dt)
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
Camera:attach()
|
||||
Tree.level.camera:attach()
|
||||
|
||||
local uiSize = 0.2
|
||||
|
||||
local windowWidth = love.graphics.getWidth()
|
||||
local windowHeight = love.graphics.getHeight() * (1 - uiSize)
|
||||
local width = 20
|
||||
local height = 12
|
||||
|
||||
@ -54,17 +37,7 @@ function love.draw()
|
||||
love.graphics.setColor(244 / 255, 67 / 255, 54 / 255, 1)
|
||||
love.graphics.rectangle('fill', 0, 0, 1, 1)
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
Hero:draw(Camera)
|
||||
Hero:draw()
|
||||
|
||||
Camera:detach()
|
||||
Tree.level.camera:detach()
|
||||
end
|
||||
|
||||
local Level = {}
|
||||
Level.kakaya_ta_hren = 10
|
||||
Level.map = {}
|
||||
|
||||
local v = Vec3({ 0, 1, 2 })
|
||||
|
||||
-- Faction -> Character
|
||||
-- calculate_order()
|
||||
-- calculate_order()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user