diff --git a/game/asset/video/1_intro.ogv b/game/asset/video/1_intro.ogv new file mode 100644 index 0000000..f79380d Binary files /dev/null and b/game/asset/video/1_intro.ogv differ diff --git a/game/main.lua b/game/main.lua index 53bfae1..e7cffcc 100644 --- a/game/main.lua +++ b/game/main.lua @@ -1,36 +1,39 @@ -local world = { +local wm = require("world_map") + +world = { ["main_menu"] = require("src.world.main_menu")(), + ["1_intro"] = require("src.world.1_intro")(), ["race"] = require("src.world.race")(), ["train"] = require("src.world.train")(), }; -local world_i = "main_menu" +current = wm["main_menu"] function load_world(world_to_load) - world_i = world_to_load - world[world_i]:reload() + current = world_to_load + world[current]:reload() end function love.load() - world[world_i]:load() + world[current]:load() end function love.update(dt) - world[world_i]:update(dt) + world[current]:update(dt) end function love.draw() - world[world_i]:draw() + world[current]:draw() end function love.keyreleased(key, scancode) - world[world_i]:keyreleased(key, scancode) + world[current]:keyreleased(key, scancode) end function love.keypressed(key, scancode, isrepeat) - world[world_i]:keypressed(key, scancode, isrepeat) + world[current]:keypressed(key, scancode, isrepeat) end function love.mousereleased(x, y, button, istouch, presses) - world[world_i]:mousereleased(x, y, button, istouch, presses) + world[current]:mousereleased(x, y, button, istouch, presses) end diff --git a/game/src/world/1_intro/init.lua b/game/src/world/1_intro/init.lua new file mode 100644 index 0000000..b6eed01 --- /dev/null +++ b/game/src/world/1_intro/init.lua @@ -0,0 +1,68 @@ +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 button = require("src.world.common.template.button") +local video = require("src.world.common.template.video") +local c_video = require("src.world.common.component.video") +local wm = require("world_map") + +local wrapper = world:extend() + +local function button_func() + load_world(wm["race"]) +end + +function wrapper:new() + wrapper.super.new(self, BASE, ".1_intro") +end + +function wrapper:load(_args) + wrapper.super.load(self, { + "src/world/common/system/" + }, { + { + assemblage = debug_entity.assembleDebug, + data = { + position = {0, 0}, + label = "1_intro" + } + }, + { + assemblage = button.assemble, + data = { + collider = { + x = 20, + y = 20, + w = 20, + h = 20 + }, + func = button_func, + label = "skip" + } + }, + { + assemblage = video.assemble, + data = { + path = "asset/video/1_intro.ogv" + } + } + }) +end + +function wrapper:update(dt) + wrapper.super.update(self, dt) + for k, v in pairs(self.entities) do + local c_v = v[c_video.dict.video] + if c_v ~= nil then + if (not c_v.data.video:isPlaying()) then + load_world(wm["race"]) + end + end + end +end + +return wrapper diff --git a/game/src/world/common/component/video.lua b/game/src/world/common/component/video.lua new file mode 100644 index 0000000..40d2a1a --- /dev/null +++ b/game/src/world/common/component/video.lua @@ -0,0 +1,16 @@ +local video = require("wrapper.lappy.new.video").obj + +local components = {} + +components.dict = { + video = "video", +} + +function components.video (c, path) + c.data = { + video = video:load_to(path, path), + path = path + } +end + +return components diff --git a/game/src/world/common/system/video_render.lua b/game/src/world/common/system/video_render.lua new file mode 100644 index 0000000..123e204 --- /dev/null +++ b/game/src/world/common/system/video_render.lua @@ -0,0 +1,50 @@ +local system_constructor = require("wrapper.Concord.system") +local c_video = require("src.world.common.component.video") + +local system = {} + +system.__index = system + +system.pool = { + pool = { + c_video.dict.video, + } +} + +system.components = { + [c_video.dict.video] = c_video.video, +} + +function system.new() + local new_system = system_constructor.new("video_render", 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 + +function system:load() + for _, e in ipairs(self.pool) do + video = e[c_video.dict.video].data.video + video:play() + end +end + +function system:update(dt) + for _, e in ipairs(self.pool) do + video = e[c_video.dict.video].data.video + end +end + +function system:draw() + for _, e in ipairs(self.pool) do + video = e[c_video.dict.video].data.video + love.graphics.draw(video, 0, 0) + end +end + +return system diff --git a/game/src/world/common/template/video.lua b/game/src/world/common/template/video.lua new file mode 100644 index 0000000..0e7767e --- /dev/null +++ b/game/src/world/common/template/video.lua @@ -0,0 +1,12 @@ +local video = require("src.world.common.component.video") + +local template = {} + +template.default_data = { + path = "" +} +function template.assemble(e, data) + e:give(video.dict.video, data.path) +end + +return template diff --git a/game/src/world/main_menu/init.lua b/game/src/world/main_menu/init.lua index 392863c..4d4c5ac 100644 --- a/game/src/world/main_menu/init.lua +++ b/game/src/world/main_menu/init.lua @@ -6,11 +6,12 @@ local world = require("wrapper.Concord.world") local debug_entity = require("src.world.common.template.debug_entity") local button = require("src.world.common.template.button") +local wm = require("world_map") local wrapper = world:extend() local function button_func() - load_world("race") + load_world(wm["1_intro"]) end function wrapper:new() @@ -38,7 +39,7 @@ function wrapper:load(_args) h = 20 }, func = button_func, - label = "race" + label = "play" } } }) diff --git a/game/world_map.lua b/game/world_map.lua new file mode 100644 index 0000000..b5c4c01 --- /dev/null +++ b/game/world_map.lua @@ -0,0 +1,6 @@ +return { + ["main_menu"] = "main_menu", + ["1_intro"] = "1_intro", + ["race"] = "race", + ["train"] = "train" +} diff --git a/game/wrapper/lappy/new/video.lua b/game/wrapper/lappy/new/video.lua new file mode 100644 index 0000000..140d066 --- /dev/null +++ b/game/wrapper/lappy/new/video.lua @@ -0,0 +1,17 @@ +local cache = require("lib.reoof.cache") +---@class lappy.video : Cache +---@field cache any +local _cache = cache:extend() + +--- new function +function _cache:new() + _cache.super.new(self, love.graphics.newVideo, ".video") + self.cache = {} +end + +local obj = _cache() + +return { + class = _cache, + obj = obj +}