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