From 5c2aa31153f547ee80bee2032603a40b02a52d2f Mon Sep 17 00:00:00 2001 From: fnicon Date: Mon, 23 Mar 2026 00:19:20 +0900 Subject: [PATCH] add countdown and track1 data --- .../new/world/race/components/countdown.lua | 34 ++++++- .../new/world/race/components/world_state.lua | 32 ++++++ .../src/new/world/race/data/track1.lua | 99 +++++++++++++++++++ game/love_src/src/new/world/race/init.lua | 5 + game/main.lua | 4 +- 5 files changed, 168 insertions(+), 6 deletions(-) create mode 100644 game/love_src/src/new/world/race/components/world_state.lua create mode 100644 game/love_src/src/new/world/race/data/track1.lua diff --git a/game/love_src/src/new/world/race/components/countdown.lua b/game/love_src/src/new/world/race/components/countdown.lua index ce1e3ad..0ff0785 100644 --- a/game/love_src/src/new/world/race/components/countdown.lua +++ b/game/love_src/src/new/world/race/components/countdown.lua @@ -13,20 +13,46 @@ function world:new() world.super.new(self, BASE, "phase") end + function world:load(entity, data) self.data = data self.e = entity end +function world:load_world_state(world_state) + self.e.components.animation.data.triggers_fn[4] = function () + if (not self.disappear) then + world_state.components.world_state.data.state = "START" + self.e.components.animation.data.anim_direction = 0 + self.disappear = 2 + end + end +end + function world:update(dt) + if (self.disappear) then + self.disappear = self.disappear - dt + end self.data.label = self.e.components.animation.data.frames[self.e.components.animation.data.current_frame] end function world:ui_draw() - uir.draw_text(self.data.label, - self.data.pos[1], self.data.pos[2], - self.data.label_color - ) + if (not self.disappear) then + uir.draw_text(self.data.label, + self.data.pos[1], self.data.pos[2], + self.data.label_color + ) + elseif (self.disappear and self.disappear > 0) then + uir.draw_text(self.data.label, + self.data.pos[1], self.data.pos[2], + self.data.label_color + ) + else + uir.draw_text("", + self.data.pos[1], self.data.pos[2], + self.data.label_color + ) + end end return world diff --git a/game/love_src/src/new/world/race/components/world_state.lua b/game/love_src/src/new/world/race/components/world_state.lua new file mode 100644 index 0000000..7cb3d06 --- /dev/null +++ b/game/love_src/src/new/world/race/components/world_state.lua @@ -0,0 +1,32 @@ +local vm = require"lib.vornmath" +local uib = require"love_src.src.system.ui_behavior" +local uir = require"love_src.src.system.ui_render" + +local main_wrapper = require "love_src.wrapper.lappy.world" +---@class wrappers.Concord.world : lappy.world +local world = main_wrapper:extend() + +local reap = require("lib.reap") +local BASE = reap.base_path(...) + +function world:new() + world.super.new(self, BASE, "phase") +end + +function world:load(entity, data) + self.data = data + self.e = entity +end + +function world:next_state(state) + self.data.state = state +end + +function world:ui_draw() + uir.draw_text(self.data.state, + self.data.pos[1], self.data.pos[2], + self.data.label_color + ) +end + +return world diff --git a/game/love_src/src/new/world/race/data/track1.lua b/game/love_src/src/new/world/race/data/track1.lua new file mode 100644 index 0000000..cecc1cf --- /dev/null +++ b/game/love_src/src/new/world/race/data/track1.lua @@ -0,0 +1,99 @@ +local vm = require"lib.vornmath" + +local lw, lh = love.graphics.getDimensions() + +return { + { + components = { + racer = require("love_src.src.new.world.race.components.racer"), + actor = require("love_src.src.new.world.race.components.actor"), + }, + type = "racer", + name = "racer 1", + data = { + racer = { + pos = vm.vec2(44.64, 10.87), + + orientation = vm.vec2(1.0, 0.0), + orientation_speed = 0.0, + min_orientation_speed = -1.0, + max_orientation_speed = 1.0, + + velocity = vm.vec2(0.0, 0.0), + max_speed = 0.3, + min_speed = -0.3, + inertia = vm.vec2(0.0, 0.0), + + accel = 0.1, + brake = 0.1, + grip = 0.1, + steer = 0.01, + mass = 0.1, + streamline = 0.1 + }, + actor = { + forward = 0.0, + steer = 0.0, + } + } + }, + { + components = { + map = require"love_src.src.new.world.race.components.map" + }, + type = "map", + name = "map 1", + data = { + map = { + drag_movement = 0.1, + friction = 0.1, + drag = vm.vec2(0.1, 0.0) + } + } + }, + { + type = "world_state", + name = "race_state", + components = { + world_state = require("love_src.src.new.world.race.components.world_state"), + }, + data = { + world_state = { + state = "count down", + pos = vm.vec2(lw/2, lh - 50), + label_color = {1, 0, 1} + } + } + }, + { + type = "countdown", + name = "321go", + components = { + countdown = require("love_src.src.new.world.race.components.countdown"), + animation = require("love_src.src.new.shared.components.animation"), + }, + data = { + countdown = { + label = "", + pos = vm.vec2(lw/2, lh/2), + label_color = {1, 0, 1} + }, + animation = { + frames = { + "3", + "2", + "1", + "go", + "" + }, + fps = 1, + triggers = {4}, + triggers_fn = { + [4] = function () + print("GO") + end + } + } + } + } +} diff --git a/game/love_src/src/new/world/race/init.lua b/game/love_src/src/new/world/race/init.lua index 06a5e9e..7b61584 100644 --- a/game/love_src/src/new/world/race/init.lua +++ b/game/love_src/src/new/world/race/init.lua @@ -106,6 +106,7 @@ end function world:setup() local map + self.world_state = {} for _, d in pairs(self.entities_data) do local e = { type = d.type, @@ -119,6 +120,8 @@ function world:setup() table.insert(self.entities, e) if (e.type == "map") then map = e + elseif e.type == "world_state" then + self.world_state = e end end for _, e in ipairs(self.entities) do @@ -128,6 +131,8 @@ function world:setup() c.map = map.components.map end end + elseif (e.type == "countdown") then + e.components.countdown:load_world_state(self.world_state) end end end diff --git a/game/main.lua b/game/main.lua index 86c1386..e127394 100644 --- a/game/main.lua +++ b/game/main.lua @@ -215,8 +215,8 @@ local world_data = { }, ["track_1"] = { world = require("love_src.src.new.world.race.init")(), - -- data = {}, - -- entities_data = require("love_src.src.new.world.main_menu.data.track_choose"), + data = {}, + entities_data = require("love_src.src.new.world.race.data.track1"), }, ["track_2"] = { world = require("love_src.src.new.world.race.init")(),