Compare commits

..

No commits in common. "7e7da420b2eaf750356632085f3ab6b50a5e8ff2" and "81fb06cc8849aa810f55a291c96be2033c341b36" have entirely different histories.

20 changed files with 18 additions and 1279 deletions

Binary file not shown.

View File

@ -1,77 +0,0 @@
local vm = require("lib.vornmath")
-- https://jakesgordon.com/writing/javascript-racer-v1-straight/
---@class lib.choro.projection
local projection = {}
--- World {x, y, z} - Camera {x, y, z} (Relative to Camera Pos)
---@param world table {x, y, z}
---@param cam table {x, y, z}
---@return table {x, y, z}
function projection.translateToRelativeCamera(world, cam)
return vm.vec3(world) - vm.vec3(cam)
end
--- project relative camera {x, y, z} to z render distance on screen {x, y}
---@param camPos table {x, y, z}
---@param distance number distance to render point
---@return table {x, y}
function projection.projectRelativeCamera(camPos, distance)
return vm.vec2({
camPos[1] * distance / camPos[3],
camPos[2] * distance / camPos[3]
})
end
--- scale things from camera projection {x, y}
---@param camProj table camera projection {x, y, z}
---@param screenScale number projection scale / distance
---@param resolution table {screen width, screen height}
---@return table {x, y}
function projection.scalePosToRelativeProjectCamera(camProj, screenScale, resolution)
local w2 = resolution[1]/2
local h2 = resolution[2]/2
return vm.vec2({
vm.round(w2 + ( screenScale * camProj[1] * w2)),
vm.round(h2 - ( screenScale * camProj[2] * h2)),
})
end
--- scale things from camera projection {w, h}
---@param size table world size {w, h}
---@param screenScale number projection scale / distance
---@param resolution table {screen width, screen height}
---@return table {w, h}
function projection.scaleSizeToRelativeProjectCamera(size, screenScale, resolution)
local w2 = resolution[1]/2
local h2 = resolution[2]/2
return vm.vec2({
vm.round( screenScale * size[1] * w2),
vm.round( screenScale * size[2] * h2)
})
end
--- calculate distance from field of view
---@param fieldOfView number field of view
---@return number distance distance from camera to projection plane
function projection.distanceCamToProjection(fieldOfView)
local d = 1 / math.tan((fieldOfView/2) * math.pi/180);
return d
end
--- apply world to camera projection
---@param world table world position {x, y, z}
---@param cameraPos table camera position {x, y, z}
---@param cameraDepth number distance from camera to projection plane
---@param resolution table render resolution {width, height}
---@param size table object {width, height}
---@return table,table {x, y, z}, {w, h}
function projection.projectWorldToCam(world, cameraPos, cameraDepth, resolution, size)
local relativetocamera = projection.translateToRelativeCamera(world, cameraPos)
local scale = cameraDepth / relativetocamera[3];
return
projection.scalePosToRelativeProjectCamera(relativetocamera, scale, resolution),
projection.scaleSizeToRelativeProjectCamera(size, scale, resolution)
end
return projection

View File

@ -1,388 +0,0 @@
--
-- json.lua
--
-- Copyright (c) 2020 rxi
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
-- this software and associated documentation files (the "Software"), to deal in
-- the Software without restriction, including without limitation the rights to
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-- of the Software, and to permit persons to whom the Software is furnished to do
-- so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
--
local json = { _version = "0.1.2" }
-------------------------------------------------------------------------------
-- Encode
-------------------------------------------------------------------------------
local encode
local escape_char_map = {
[ "\\" ] = "\\",
[ "\"" ] = "\"",
[ "\b" ] = "b",
[ "\f" ] = "f",
[ "\n" ] = "n",
[ "\r" ] = "r",
[ "\t" ] = "t",
}
local escape_char_map_inv = { [ "/" ] = "/" }
for k, v in pairs(escape_char_map) do
escape_char_map_inv[v] = k
end
local function escape_char(c)
return "\\" .. (escape_char_map[c] or string.format("u%04x", c:byte()))
end
local function encode_nil(val)
return "null"
end
local function encode_table(val, stack)
local res = {}
stack = stack or {}
-- Circular reference?
if stack[val] then error("circular reference") end
stack[val] = true
if rawget(val, 1) ~= nil or next(val) == nil then
-- Treat as array -- check keys are valid and it is not sparse
local n = 0
for k in pairs(val) do
if type(k) ~= "number" then
error("invalid table: mixed or invalid key types")
end
n = n + 1
end
if n ~= #val then
error("invalid table: sparse array")
end
-- Encode
for i, v in ipairs(val) do
table.insert(res, encode(v, stack))
end
stack[val] = nil
return "[" .. table.concat(res, ",") .. "]"
else
-- Treat as an object
for k, v in pairs(val) do
if type(k) ~= "string" then
error("invalid table: mixed or invalid key types")
end
table.insert(res, encode(k, stack) .. ":" .. encode(v, stack))
end
stack[val] = nil
return "{" .. table.concat(res, ",") .. "}"
end
end
local function encode_string(val)
return '"' .. val:gsub('[%z\1-\31\\"]', escape_char) .. '"'
end
local function encode_number(val)
-- Check for NaN, -inf and inf
if val ~= val or val <= -math.huge or val >= math.huge then
error("unexpected number value '" .. tostring(val) .. "'")
end
return string.format("%.14g", val)
end
local type_func_map = {
[ "nil" ] = encode_nil,
[ "table" ] = encode_table,
[ "string" ] = encode_string,
[ "number" ] = encode_number,
[ "boolean" ] = tostring,
}
encode = function(val, stack)
local t = type(val)
local f = type_func_map[t]
if f then
return f(val, stack)
end
error("unexpected type '" .. t .. "'")
end
function json.encode(val)
return ( encode(val) )
end
-------------------------------------------------------------------------------
-- Decode
-------------------------------------------------------------------------------
local parse
local function create_set(...)
local res = {}
for i = 1, select("#", ...) do
res[ select(i, ...) ] = true
end
return res
end
local space_chars = create_set(" ", "\t", "\r", "\n")
local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",")
local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u")
local literals = create_set("true", "false", "null")
local literal_map = {
[ "true" ] = true,
[ "false" ] = false,
[ "null" ] = nil,
}
local function next_char(str, idx, set, negate)
for i = idx, #str do
if set[str:sub(i, i)] ~= negate then
return i
end
end
return #str + 1
end
local function decode_error(str, idx, msg)
local line_count = 1
local col_count = 1
for i = 1, idx - 1 do
col_count = col_count + 1
if str:sub(i, i) == "\n" then
line_count = line_count + 1
col_count = 1
end
end
error( string.format("%s at line %d col %d", msg, line_count, col_count) )
end
local function codepoint_to_utf8(n)
-- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa
local f = math.floor
if n <= 0x7f then
return string.char(n)
elseif n <= 0x7ff then
return string.char(f(n / 64) + 192, n % 64 + 128)
elseif n <= 0xffff then
return string.char(f(n / 4096) + 224, f(n % 4096 / 64) + 128, n % 64 + 128)
elseif n <= 0x10ffff then
return string.char(f(n / 262144) + 240, f(n % 262144 / 4096) + 128,
f(n % 4096 / 64) + 128, n % 64 + 128)
end
error( string.format("invalid unicode codepoint '%x'", n) )
end
local function parse_unicode_escape(s)
local n1 = tonumber( s:sub(1, 4), 16 )
local n2 = tonumber( s:sub(7, 10), 16 )
-- Surrogate pair?
if n2 then
return codepoint_to_utf8((n1 - 0xd800) * 0x400 + (n2 - 0xdc00) + 0x10000)
else
return codepoint_to_utf8(n1)
end
end
local function parse_string(str, i)
local res = ""
local j = i + 1
local k = j
while j <= #str do
local x = str:byte(j)
if x < 32 then
decode_error(str, j, "control character in string")
elseif x == 92 then -- `\`: Escape
res = res .. str:sub(k, j - 1)
j = j + 1
local c = str:sub(j, j)
if c == "u" then
local hex = str:match("^[dD][89aAbB]%x%x\\u%x%x%x%x", j + 1)
or str:match("^%x%x%x%x", j + 1)
or decode_error(str, j - 1, "invalid unicode escape in string")
res = res .. parse_unicode_escape(hex)
j = j + #hex
else
if not escape_chars[c] then
decode_error(str, j - 1, "invalid escape char '" .. c .. "' in string")
end
res = res .. escape_char_map_inv[c]
end
k = j + 1
elseif x == 34 then -- `"`: End of string
res = res .. str:sub(k, j - 1)
return res, j + 1
end
j = j + 1
end
decode_error(str, i, "expected closing quote for string")
end
local function parse_number(str, i)
local x = next_char(str, i, delim_chars)
local s = str:sub(i, x - 1)
local n = tonumber(s)
if not n then
decode_error(str, i, "invalid number '" .. s .. "'")
end
return n, x
end
local function parse_literal(str, i)
local x = next_char(str, i, delim_chars)
local word = str:sub(i, x - 1)
if not literals[word] then
decode_error(str, i, "invalid literal '" .. word .. "'")
end
return literal_map[word], x
end
local function parse_array(str, i)
local res = {}
local n = 1
i = i + 1
while 1 do
local x
i = next_char(str, i, space_chars, true)
-- Empty / end of array?
if str:sub(i, i) == "]" then
i = i + 1
break
end
-- Read token
x, i = parse(str, i)
res[n] = x
n = n + 1
-- Next token
i = next_char(str, i, space_chars, true)
local chr = str:sub(i, i)
i = i + 1
if chr == "]" then break end
if chr ~= "," then decode_error(str, i, "expected ']' or ','") end
end
return res, i
end
local function parse_object(str, i)
local res = {}
i = i + 1
while 1 do
local key, val
i = next_char(str, i, space_chars, true)
-- Empty / end of object?
if str:sub(i, i) == "}" then
i = i + 1
break
end
-- Read key
if str:sub(i, i) ~= '"' then
decode_error(str, i, "expected string for key")
end
key, i = parse(str, i)
-- Read ':' delimiter
i = next_char(str, i, space_chars, true)
if str:sub(i, i) ~= ":" then
decode_error(str, i, "expected ':' after key")
end
i = next_char(str, i + 1, space_chars, true)
-- Read value
val, i = parse(str, i)
-- Set
res[key] = val
-- Next token
i = next_char(str, i, space_chars, true)
local chr = str:sub(i, i)
i = i + 1
if chr == "}" then break end
if chr ~= "," then decode_error(str, i, "expected '}' or ','") end
end
return res, i
end
local char_func_map = {
[ '"' ] = parse_string,
[ "0" ] = parse_number,
[ "1" ] = parse_number,
[ "2" ] = parse_number,
[ "3" ] = parse_number,
[ "4" ] = parse_number,
[ "5" ] = parse_number,
[ "6" ] = parse_number,
[ "7" ] = parse_number,
[ "8" ] = parse_number,
[ "9" ] = parse_number,
[ "-" ] = parse_number,
[ "t" ] = parse_literal,
[ "f" ] = parse_literal,
[ "n" ] = parse_literal,
[ "[" ] = parse_array,
[ "{" ] = parse_object,
}
parse = function(str, idx)
local chr = str:sub(idx, idx)
local f = char_func_map[chr]
if f then
return f(str, idx)
end
decode_error(str, idx, "unexpected character '" .. chr .. "'")
end
function json.decode(str)
if type(str) ~= "string" then
error("expected argument of type string, got " .. type(str))
end
local res, idx = parse(str, next_char(str, 1, space_chars, true))
idx = next_char(str, idx, space_chars, true)
if idx <= #str then
decode_error(str, idx, "trailing garbage")
end
return res
end
return json

View File

@ -1,40 +1,37 @@
local wm = require("world_map")
world = {
["main_menu"] = require("src.world.main_menu")(),
["1_intro"] = require("src.world.1_intro")(),
["2_town_square"] = require("src.world.2_town_square")(),
["race"] = require("src.world.race")(),
["train"] = require("src.world.train")(),
local world = {
require("src.world.race")(),
require("src.world.train")()
};
current = wm["main_menu"]
function load_world(world_to_load)
current = world_to_load
world[current]:reload()
end
local world_i = 1
function love.load()
world[current]:load()
world[world_i]:load()
end
function love.update(dt)
world[current]:update(dt)
world[world_i]:update(dt)
end
function love.draw()
world[current]:draw()
world[world_i]:draw()
end
function love.keyreleased(key, scancode)
world[current]:keyreleased(key, scancode)
if (key == "right") then
world_i = world_i + 1
if (world_i > 2) then
world_i = 1
end
world[world_i]:reload()
end
world[world_i]:keyreleased(key, scancode)
end
function love.keypressed(key, scancode, isrepeat)
world[current]:keypressed(key, scancode, isrepeat)
world[world_i]:keypressed(key, scancode, isrepeat)
end
function love.mousereleased(x, y, button, istouch, presses)
world[current]:mousereleased(x, y, button, istouch, presses)
world[world_i]:mousereleased(x, y, button, istouch, presses)
end

View File

@ -1,68 +0,0 @@
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["2_town_square"])
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["2_town_square"])
end
end
end
end
return wrapper

View File

@ -1,31 +0,0 @@
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 wm = require("world_map")
local wrapper = world:extend()
function wrapper:new()
wrapper.super.new(self, BASE, ".2_town_square")
end
function wrapper:load(_args)
wrapper.super.load(self, {
"src/world/common/system/"
}, {
{
assemblage = debug_entity.assembleDebug,
data = {
position = {0, 0},
label = "2_town_square"
}
},
})
end
return wrapper

View File

@ -1,12 +0,0 @@
local utils = {}
function utils.overlap(x1, w1, x2, w2, percent)
local half = (percent or 1)/2;
local min1 = x1 - (w1*half);
local max1 = x1 + (w1*half);
local min2 = x2 - (w2*half);
local max2 = x2 + (w2*half);
return not ((max1 < min2) or (min1 > max2));
end
return utils

View File

@ -1,55 +0,0 @@
local vm = require("lib.vornmath")
local utils = {}
function utils.easeIn(a,b,percent)
return a + (b-a)*math.pow(percent,2);
end
function utils.easeOut(a,b,percent)
return a + (b-a)*(1-math.pow(1-percent,2));
end
function utils.easeInOut(a,b,percent)
return a + (b-a)*((-math.cos(percent*math.pi)/2) + 0.5);
end
function utils.percentRemaining(n, total)
return (n%total)/total;
end
function utils.interpolate(a, b, percent)
return a + (b-a)*percent
end
function utils.randomInt(min, max)
return vm.round(utils.interpolate(min, max, math.random()));
end
function utils.randomChoice(options)
return options[utils.randomInt(1, #options)]
end
function utils.limit(value, min, max)
return math.max(min, math.min(value, max))
end
function utils.accelerate(v, accel, dt)
return v + (accel * dt)
end
function utils.exponentialFog(distance, density)
return 1 / (math.exp(distance * distance * density))
end
function utils.increase(start, increment, max, is_loop) -- with looping
local result = start + increment
if (result > max) and is_loop then
result = 1
elseif result <= 0 and is_loop then
result = max - 1
end
return result
end
return utils

View File

@ -1,338 +0,0 @@
local reap = require("lib.reap")
local BASE = reap.base_path(...)
local easeFN = require(BASE .. ".ease")
local json = require("lib.json")
local QuadCache = require("wrapper.lappy.new.quad").obj
local ImageCache = require("wrapper.lappy.new.image").obj
local utils = {}
local function loadJSON(path)
local data = json.decode(love.filesystem.read(path))
return data
end
local ROAD = {
LENGTH= { NONE= 0, SHORT= 25, MEDIUM= 50, LONG= 100 }, -- num segments
HILL= { NONE= 0, LOW= 20, MEDIUM= 40, HIGH= 60 },
CURVE= { NONE= 0, EASY= 2, MEDIUM= 4, HARD= 6 }
};
-- function utils.getRumbleColor(index, rumbleLength)
-- local colorDark = hex2color("#1a1d33")
-- local colorBright = hex2color("#c8d0fa")
-- if (math.floor(index/rumbleLength)%2 == 0) then
-- return colorBright
-- else
-- return colorDark
-- end
-- end
-- function utils.getFinishStartColor()
-- local colorDark = hex2color("#CCFFCC")
-- local colorBright = hex2color("#FFCCFF")
-- return colorDark, colorBright
-- end
local function lastY(segments)
if (#segments == 0) then
return 0
else
return segments[#segments].p2.world.y
end
end
local function lastWidth(segments, fallback)
if (#segments == 0) then
return fallback
else
return segments[#segments].p2.world.w
end
end
function utils.findSegment(zPosition, segments, segmentLength)
local index = (math.floor(zPosition/segmentLength) % #segments) + 1
if (index >= #segments) then
index = #segments
end
return segments[index];
end
--- add quad and image
---@param path string
---@param slice "horizontal" | "vertical"
---@param w1 number
---@param w2 number
function utils.addQuads(path, slice, w1, w2)
local image = ImageCache:load_to(path, path)
local sw, sh = image:getDimensions()
local quads = {}
if (slice == "vertical") then
for i = 0, sh - 1 do
local percent = easeFN.percentRemaining(i, sh - 1)
local destW = easeFN.interpolate(w1, w2, percent)
table.insert(quads,
QuadCache:load_to(string.format("%s %s %s %s %s %s %s",
path, 0, i, sw, 1, sw, sh),
path, 0, i, sw, 1, sw, sh)
)
end
elseif (slice == "horizontal") then
for i = 0, sw - 1 do
local percent = easeFN.percentRemaining(i, sw - 1)
local destH = easeFN.interpolate(w1, w2, percent)
table.insert(quads,
QuadCache:load_to(
string.format("%s %s %s %s %s %s %s",
path, i, 0, 1, sh, sw, sh),
path, i, 0, 1, sh, sw, sh)
)
end
end
return quads, image
end
--- add new segment to segments
---@param segments any
---@param segmentLength number z coord length
---@param rumbleLength number for debug purpose only
---@param curve number curve degree
---@param y number height
---@param width number
---@return table segment it's basically part that are drawn
function utils.addSegment(segments, segmentLength, rumbleLength, curve, y, width)
local index = #segments
local w1 = lastWidth(segments, width)
local w2 = width
local y1 = lastY(segments)
local y2 = y
local fQuads, fImage = utils.addQuads("asset/image/sample/javascript-racer-master/images/sprites/column.png", "vertical", w1, w2)
local cQuads, cImage = utils.addQuads("asset/image/sample/javascript-racer-master/images/sprites/column.png", "vertical", w1, w2)
local lQuads, lImage = utils.addQuads("asset/image/sample/javascript-racer-master/images/sprites/column.png", "horizontal", y1, y2)
local rQuads, rImage = utils.addQuads("asset/image/sample/javascript-racer-master/images/sprites/column.png", "horizontal", y1, y2)
return {
--- index for seeking
index= index + 1,
--- part 1 start
p1 = {
world =
{
w = w1,
y = y1,
z = index * segmentLength,
},
camera = {},
screen = {}
},
--- part 2 end
p2 = {
world = {
w = w2,
y = y2,
z = (index+1)* segmentLength,
},
camera = {},
screen = {}
},
--- curve to follow along
curve = curve,
sprites= {},
---p1 -> p2 quads
texture = {
floor = {
image = fImage,
quads = fQuads
},
ceil = {
image = cImage,
quads = cQuads
},
wallL = {
image = lImage,
quads = lQuads
},
wallR = {
image = rImage,
quads = rQuads
},
}
}
end
function utils.addRoad(segments, segmentLength, rumbleLength, enter, hold, leave, curve, y, roadWidth)
local startY = lastY(segments);
local endY = startY + ((y or 0) * segmentLength);
local startWidth = lastWidth(segments, (roadWidth or 0));
local endWidth = (roadWidth or 0)
local total = enter + hold + leave;
for n = 1, enter do
table.insert(
segments,
utils.addSegment(
segments,
segmentLength,
rumbleLength,
easeFN.easeIn(0, curve, n/enter),
easeFN.easeInOut(startY, endY, n/total),
easeFN.easeInOut(startWidth, endWidth, n/total)
)
)
end
for n = 1, hold do
table.insert(
segments,
utils.addSegment(
segments,
segmentLength,
rumbleLength,
curve,
easeFN.easeInOut(startY, endY, (enter + n)/total),
easeFN.easeInOut(startWidth, endWidth, (enter + n)/total)
)
)
end
for n = 1, leave do
table.insert(
segments,
utils.addSegment(
segments,
segmentLength,
rumbleLength,
easeFN.easeInOut(curve, 0, n/leave),
easeFN.easeInOut(startY, endY, (enter+hold+n)/total),
easeFN.easeInOut(startWidth, endWidth, (enter + hold + n)/total)
)
)
end
return segments
end
function utils.addStraight(segments, segmentLength, rumbleLength, num)
num = num or ROAD.LENGTH.MEDIUM;
return utils.addRoad(segments, segmentLength, rumbleLength, num, num, num, 0, 2000);
end
function utils.addHill(segments, segmentLength, rumbleLength, num, height)
num = num or ROAD.LENGTH.MEDIUM;
height = height or ROAD.HILL.MEDIUM;
return utils.addRoad(segments, segmentLength, rumbleLength, num, num, num, 0, height, 2000);
end
function utils.addCurve(segments, segmentLength, rumbleLength, num, curve, height)
num = num or ROAD.LENGTH.MEDIUM;
curve = curve or ROAD.CURVE.MEDIUM;
height = height or ROAD.HILL.NONE;
return utils.addRoad(segments, segmentLength, rumbleLength, num, num, num, curve, height, 2000);
end
function utils.addLowRollingHills(segments, segmentLength, rumbleLength, num, height)
num = num or ROAD.LENGTH.SHORT;
height = height or ROAD.HILL.LOW;
utils.addRoad(segments, segmentLength, rumbleLength, num, num, num, 0, height/2, 2000);
utils.addRoad(segments, segmentLength, rumbleLength, num, num, num, 0, -height, 2000);
utils.addRoad(segments, segmentLength, rumbleLength, num, num, num, 0, height, 2000);
utils.addRoad(segments, segmentLength, rumbleLength, num, num, num, 0, 0, 2000);
utils.addRoad(segments, segmentLength, rumbleLength, num, num, num, 0, height/2, 2000);
utils.addRoad(segments, segmentLength, rumbleLength, num, num, num, 0, 0, 2000);
return segments
end
function utils.addSCurves(segments, segmentLength, rumbleLength)
utils.addRoad(segments, segmentLength, rumbleLength, ROAD.LENGTH.MEDIUM, ROAD.LENGTH.MEDIUM, ROAD.LENGTH.MEDIUM, -ROAD.CURVE.EASY, 2000);
utils.addRoad(segments, segmentLength, rumbleLength, ROAD.LENGTH.MEDIUM, ROAD.LENGTH.MEDIUM, ROAD.LENGTH.MEDIUM, ROAD.CURVE.MEDIUM, 2000);
utils.addRoad(segments, segmentLength, rumbleLength, ROAD.LENGTH.MEDIUM, ROAD.LENGTH.MEDIUM, ROAD.LENGTH.MEDIUM, ROAD.CURVE.EASY, 2000);
utils.addRoad(segments, segmentLength, rumbleLength, ROAD.LENGTH.MEDIUM, ROAD.LENGTH.MEDIUM, ROAD.LENGTH.MEDIUM, -ROAD.CURVE.EASY, 2000);
utils.addRoad(segments, segmentLength, rumbleLength, ROAD.LENGTH.MEDIUM, ROAD.LENGTH.MEDIUM, ROAD.LENGTH.MEDIUM, -ROAD.CURVE.MEDIUM, 2000);
return segments
end
function utils.addDownhillToEnd(segments, segmentLength, rumbleLength, num)
num = num or 200;
utils.addRoad(segments, segmentLength, rumbleLength, num, num, num, -ROAD.CURVE.EASY, -lastY(segments)/segmentLength, 2000);
return segments
end
function utils.resetCars(cars, segments, segmentLength, totalCars, maxSpeed)
local n, car, segment, offset, z, sprite, speed;
for n = 0, totalCars do
offset = math.random() * easeFN.randomChoice({-0.8, 0.8});
z = math.floor(math.random() * segments.length) * segmentLength;
sprite = easeFN.randomChoice({
ImageCache:load_to("asset/image/sample/javascript-racer-master/images/sprites/bush1.png",
"asset/image/sample/javascript-racer-master/images/sprites/bush1.png")
});
speed = maxSpeed/4 + math.random() * maxSpeed;
car = { offset = offset, z = z, sprite = sprite, speed = speed };
segment = utils.findSegment(car.z, segments, segmentLength);
table.insert(segment.cars, car);
table.insert(cars, car);
end
end
function utils.loadRoad(segments, segmentLength, rumbleLength, path)
local segmentData = loadJSON(path)
for _, v in ipairs(segmentData) do
local enter = v.enter
local hold = v.hold
local leave = v.leave
local curve = v.curve
local height = v.height
local width = v.width
utils.addRoad(segments, segmentLength, rumbleLength, enter, hold, leave, curve, height, width);
end
end
function utils.resetRoad(path, pathSprite, segmentLength, rumbleLength, playerZ)
local segments = {}
utils.loadRoad(segments, segmentLength, rumbleLength, path)
if (pathSprite) then
utils.loadSpriteMapData(segments, pathSprite);
end
local trackLength = #segments * segmentLength;
return segments, trackLength
end
function utils.loadSpriteMapData(segments, path)
local segmentData = loadJSON(path)
for _, v in ipairs(segmentData) do
local index = v.index
local texture = v.texture
local offset = v.offset
utils.addSprite(segments, index, ImageCache:load_to(texture, texture), offset, texture);
end
end
local imageData = {
["car"] = {
path = "asset/image/sample/javascript-racer-master/images/sprites/car01.png"
}
}
function utils.addSprite(segments, index, sprite, offset, key)
table.insert(segments[index].sprites, {
source= sprite,
offset= offset,
data = {}
})
local _sIndex = #segments[index].sprites
segments[index].sprites[_sIndex].data = {
path = imageData[key].path,
type = imageData[key].type
}
end
return utils

View File

@ -1,30 +0,0 @@
local components = {}
components.dict = {
collider = "button.collider",
func = "button.func",
label = "button.label"
}
function components.collider (c, x, y, w, h)
c.data = {
x = x or 0,
y = y or 0,
w = w or 0,
h = h or 0
}
end
function default()
print("click")
end
function components.func (c, func)
c.data = func or default
end
function components.label (c, label)
c.data = label or ""
end
return components

View File

@ -1,16 +0,0 @@
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

View File

@ -1,81 +0,0 @@
local system_constructor = require("wrapper.Concord.system")
local c_button = require("src.world.common.component.button")
local system = {}
system.__index = system
system.pool = {
pool = {
c_button.dict.collider,
c_button.dict.func,
c_button.dict.label
}
}
system.components = {
[c_button.dict.collider] = c_button.collider,
[c_button.dict.func] = c_button.func,
[c_button.dict.label] = c_button.label
}
function system.new()
local new_system = system_constructor.new("trigger_button", 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
-- x1 y1 -- (x1 + w1) y1
-- x2 y2
-- x1 (y1 + h1) -- (x1 + w1) (y1 + h1)
local function is_inside(x1,y1,w1,h1, x2,y2)
return x1 < x2 and
x2 < x1+w1 and
y1 < y2 and
y2 < y1+h1
end
function system:mousereleased(x, y, button, istouch, presses)
for _, e in ipairs(self.pool) do
local x1 = e[c_button.dict.collider].data.x
local y1 = e[c_button.dict.collider].data.y
local w1 = e[c_button.dict.collider].data.w
local h1 = e[c_button.dict.collider].data.h
local func = e[c_button.dict.func].data
if (is_inside(x1, y1, w1, h1, x, y) and button == 1) then
func()
end
end
end
local function draw(text, x, y, w, h)
love.graphics.push()
love.graphics.line(
x, y,
x + w, y,
x + w, y + h,
x, y + h,
x, y
)
love.graphics.print(text, x, y)
love.graphics.pop()
end
function system:draw()
for _, e in ipairs(self.pool) do
local x = e[c_button.dict.collider].data.x
local y = e[c_button.dict.collider].data.y
local w = e[c_button.dict.collider].data.w
local h = e[c_button.dict.collider].data.h
local label = e[c_button.dict.label].data
draw(label, x, y, w, h)
end
end
return system

View File

@ -1,50 +0,0 @@
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

View File

@ -1,5 +1,4 @@
local flip = require("src.world.common.system.flip")
local transform = require("src.world.common.component.transform")
local template = {}
@ -25,7 +24,6 @@ template.default_data = {
next_trigger_frame = 1,
run_time = 0,
trigger_frame = {1},
position = {0, 0, 0}
}
function template.assemble(e, data)
e:give(flip.pool.pool[1], data.sfx)
@ -36,7 +34,6 @@ function template.assemble(e, data)
e:give(flip.pool.pool[6], data.next_trigger_frame)
e:give(flip.pool.pool[7], data.run_time)
e:give(flip.pool.pool[8], data.trigger_frame)
e:give(transform.dict.position, data.position)
end
return template

View File

@ -1,24 +0,0 @@
local button = require("src.world.common.component.button")
local template = {}
local function default()
end
template.default_data = {
collider = {
x = 0,
y = 0,
w = 20,
h = 20
},
func = default,
label = "debug"
}
function template.assemble(e, data)
e:give(button.dict.collider, data.collider.x, data.collider.y, data.collider.w, data.collider.h)
e:give(button.dict.func, data.func)
e:give(button.dict.label, data.label)
end
return template

View File

@ -1,12 +0,0 @@
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

View File

@ -1,48 +0,0 @@
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 wm = require("world_map")
local wrapper = world:extend()
local function button_func()
load_world(wm["1_intro"])
end
function wrapper:new()
wrapper.super.new(self, BASE, ".main_menu")
end
function wrapper:load(_args)
wrapper.super.load(self, {
"src/world/common/system/"
}, {
{
assemblage = debug_entity.assembleDebug,
data = {
position = {0, 0},
label = "main_menu"
}
},
{
assemblage = button.assemble,
data = {
collider = {
x = 20,
y = 20,
w = 20,
h = 20
},
func = button_func,
label = "play"
}
}
})
end
return wrapper

View File

@ -9,7 +9,6 @@ local debug_entity = require("src.world.common.template.debug_entity")
local book = require("src.world.common.template.book")
local animation = require("src.world.common.component.animation")
local transform = require("src.world.common.component.transform")
local wrapper = world:extend()
@ -43,7 +42,7 @@ function wrapper:draw()
local frame_i = v[animation.dict.frame_i].data
local img = v[animation.dict.image_frame].data.images
if (img ~= nil) then
love.graphics.draw(img[frame_i], v[transform.dict.position].data[1], v[transform.dict.position].data[2])
love.graphics.draw(img[frame_i])
end
end
end

View File

@ -1,7 +0,0 @@
return {
["main_menu"] = "main_menu",
["1_intro"] = "1_intro",
["2_town_square"] = "2_town_square",
["race"] = "race",
["train"] = "train"
}

View File

@ -1,17 +0,0 @@
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
}