libraries_setup #3
@ -1,45 +1,37 @@
|
||||
local mode = {
|
||||
require("src.modes.racing"),
|
||||
require("src.modes.raising_sim")
|
||||
local world = {
|
||||
require("src.world.race")(),
|
||||
require("src.world.train")()
|
||||
};
|
||||
|
||||
local actor = require("src.entities.shared.actor")
|
||||
local player = actor.load("player")
|
||||
|
||||
local source_cls = require("wrapper.lappy.new.source")
|
||||
local source = source_cls.obj
|
||||
|
||||
local mode_i = 1
|
||||
local world_i = 1
|
||||
|
||||
function love.load()
|
||||
source:load_to("asset/audio/bgm/Ensemble.mp3", "asset/audio/bgm/Ensemble.mp3", "stream")
|
||||
source:load_from("asset/audio/bgm/Ensemble.mp3"):play()
|
||||
mode[mode_i].load(player)
|
||||
world[world_i]:load()
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
mode[mode_i].update(dt)
|
||||
world[world_i]:update(dt)
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
mode[mode_i].draw()
|
||||
world[world_i]:draw()
|
||||
end
|
||||
|
||||
function love.keyreleased(key, scancode)
|
||||
if (key == "right") then
|
||||
mode_i = mode_i + 1
|
||||
if (mode_i > 2) then
|
||||
mode_i = 1
|
||||
world_i = world_i + 1
|
||||
if (world_i > 2) then
|
||||
world_i = 1
|
||||
end
|
||||
mode[mode_i].load(player)
|
||||
world[world_i]:reload()
|
||||
end
|
||||
mode[mode_i].keyreleased(key, scancode)
|
||||
world[world_i]:keyreleased(key, scancode)
|
||||
end
|
||||
|
||||
function love.keypressed(key, scancode, isrepeat)
|
||||
mode[mode_i].keypressed(key, scancode, isrepeat)
|
||||
world[world_i]:keypressed(key, scancode, isrepeat)
|
||||
end
|
||||
|
||||
function love.mousereleased(x, y, button, istouch, presses)
|
||||
mode[mode_i].mousereleased(x, y, button, istouch, presses)
|
||||
world[world_i]:mousereleased(x, y, button, istouch, presses)
|
||||
end
|
||||
|
||||
11
game/src/world/common/component/debug_label.lua
Normal file
11
game/src/world/common/component/debug_label.lua
Normal file
@ -0,0 +1,11 @@
|
||||
local components = {}
|
||||
|
||||
components.dict = {
|
||||
debug_label = "debug_label",
|
||||
}
|
||||
|
||||
function components.debug_label (c, label)
|
||||
c.data = label
|
||||
end
|
||||
|
||||
return components
|
||||
23
game/src/world/common/component/transform.lua
Normal file
23
game/src/world/common/component/transform.lua
Normal file
@ -0,0 +1,23 @@
|
||||
local vm = require("lib.vornmath")
|
||||
|
||||
local components = {}
|
||||
|
||||
components.dict = {
|
||||
position = "position",
|
||||
scale = "scale",
|
||||
rotation = "rotation"
|
||||
}
|
||||
|
||||
function components.position (c, x, y, z)
|
||||
c.data = vm.vec3(x or 0, y or 0, z or 0)
|
||||
end
|
||||
|
||||
function components.scale (c, sx, sy, sz)
|
||||
c.data = vm.vec3(sx or 1, sy or 1, sz or 1)
|
||||
end
|
||||
|
||||
function components.rotation (c, rx, ry, rz)
|
||||
c.data = vm.vec3(rx or 0, ry or 0, rz or 0)
|
||||
end
|
||||
|
||||
return components
|
||||
48
game/src/world/common/system/debug_world_draw.lua
Normal file
48
game/src/world/common/system/debug_world_draw.lua
Normal file
@ -0,0 +1,48 @@
|
||||
local system_constructor = require("wrapper.Concord.system")
|
||||
local debug_label = require("src.world.common.component.debug_label")
|
||||
local transform = require("src.world.common.component.transform")
|
||||
|
||||
local system = {}
|
||||
|
||||
system.__index = system
|
||||
|
||||
system.pool = {
|
||||
pool = {
|
||||
debug_label.dict.debug_label,
|
||||
transform.dict.position
|
||||
}
|
||||
}
|
||||
|
||||
system.components = {
|
||||
[debug_label.dict.debug_label] = debug_label.debug_label,
|
||||
[transform.dict.position] = transform.position
|
||||
}
|
||||
|
||||
function system.new()
|
||||
local new_system = system_constructor.new("debug_world_draw", system.pool)
|
||||
if (new_system) then
|
||||
for k, v in pairs(system) do
|
||||
new_system[k] = v
|
||||
end
|
||||
return new_system
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
local function draw(text, x, y)
|
||||
love.graphics.push()
|
||||
love.graphics.print(text, x, y)
|
||||
love.graphics.pop()
|
||||
end
|
||||
|
||||
function system:draw()
|
||||
for _, e in ipairs(self.pool) do
|
||||
local text = e[debug_label.dict.debug_label].data
|
||||
local x = e[transform.dict.position].data[1]
|
||||
local y = e[transform.dict.position].data[2]
|
||||
draw(text, x, y)
|
||||
end
|
||||
end
|
||||
|
||||
return system
|
||||
14
game/src/world/common/template/debug_entity.lua
Normal file
14
game/src/world/common/template/debug_entity.lua
Normal file
@ -0,0 +1,14 @@
|
||||
local debug_world_draw = require("src.world.common.system.debug_world_draw")
|
||||
|
||||
local template = {}
|
||||
|
||||
template.default_data = {
|
||||
position = {0, 0},
|
||||
label = "debug"
|
||||
}
|
||||
function template.assembleDebug(e, data)
|
||||
e:give(debug_world_draw.pool.pool[1], data.label)
|
||||
e:give(debug_world_draw.pool.pool[2], data.position[1], data.position[2])
|
||||
end
|
||||
|
||||
return template
|
||||
29
game/src/world/race/init.lua
Normal file
29
game/src/world/race/init.lua
Normal file
@ -0,0 +1,29 @@
|
||||
local reap = require("lib.reap")
|
||||
|
||||
local BASE = reap.base_path(...)
|
||||
|
||||
local world = require("wrapper.Concord.world")
|
||||
|
||||
local debug_entity = require("src.world.common.template.debug_entity")
|
||||
|
||||
local wrapper = world:extend()
|
||||
|
||||
function wrapper:new()
|
||||
wrapper.super.new(self, BASE, ".race")
|
||||
end
|
||||
|
||||
function wrapper:load(_args)
|
||||
wrapper.super.load(self, {
|
||||
"src/world/common/system/"
|
||||
}, {
|
||||
{
|
||||
assemblage = debug_entity.assembleDebug,
|
||||
data = {
|
||||
position = {0, 0},
|
||||
label = "race world"
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
return wrapper
|
||||
29
game/src/world/train/init.lua
Normal file
29
game/src/world/train/init.lua
Normal file
@ -0,0 +1,29 @@
|
||||
local reap = require("lib.reap")
|
||||
|
||||
local BASE = reap.base_path(...)
|
||||
|
||||
local world = require("wrapper.Concord.world")
|
||||
|
||||
local debug_entity = require("src.world.common.template.debug_entity")
|
||||
|
||||
local wrapper = world:extend()
|
||||
|
||||
function wrapper:new()
|
||||
wrapper.super.new(self, BASE, ".train")
|
||||
end
|
||||
|
||||
function wrapper:load(_args)
|
||||
wrapper.super.load(self, {
|
||||
"src/world/common/system/"
|
||||
}, {
|
||||
{
|
||||
assemblage = debug_entity.assembleDebug,
|
||||
data = {
|
||||
position = {0, 0},
|
||||
label = "train world"
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
return wrapper
|
||||
@ -20,6 +20,7 @@ local wrapper = main_wrapper:extend()
|
||||
|
||||
function wrapper:new(path, name)
|
||||
wrapper.super.new(self, path, name)
|
||||
self.is_loaded = false
|
||||
self.world = World()
|
||||
end
|
||||
|
||||
@ -56,9 +57,17 @@ end
|
||||
function wrapper:load(system_paths, entities_data)
|
||||
load_systems(self.world, system_paths)
|
||||
load_entities(self.world, entities_data)
|
||||
self.is_loaded = true
|
||||
self.world:emit("load")
|
||||
end
|
||||
|
||||
function wrapper:reload(system_paths, entities_data)
|
||||
if not self.is_loaded then
|
||||
self:load(system_paths, entities_data)
|
||||
end
|
||||
self.world:emit("reload")
|
||||
end
|
||||
|
||||
function wrapper:draw()
|
||||
self.world:emit("draw")
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user