Add UI and navigation
This commit is contained in:
parent
a7fd31a83f
commit
5dbf8ce1d0
@ -23,12 +23,15 @@ local default = {
|
|||||||
label_color = {255/255, 255/255, 255/255},
|
label_color = {255/255, 255/255, 255/255},
|
||||||
bg_color = {0, 0, 0},
|
bg_color = {0, 0, 0},
|
||||||
line_color = {1, 0, 0},
|
line_color = {1, 0, 0},
|
||||||
|
highlight_color = {0, 0, 1},
|
||||||
func = default_func,
|
func = default_func,
|
||||||
label = "skip",
|
label = "skip",
|
||||||
}
|
}
|
||||||
|
|
||||||
function world:load(entity, data)
|
function world:load(entity, data)
|
||||||
self.data = data or default
|
self.data = data or default
|
||||||
|
self.data.temp_color = self.data.bg_color
|
||||||
|
self.mouse = "not click"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- x1 y1 -- (x1 + w1) y1
|
-- x1 y1 -- (x1 + w1) y1
|
||||||
@ -41,6 +44,46 @@ local function is_inside(x1,y1,w1,h1, x2,y2)
|
|||||||
y2 < y1+h1
|
y2 < y1+h1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function transform(x, y, w, h, ox, oy,lox, loy, s)
|
||||||
|
x = x * s
|
||||||
|
y = y * s
|
||||||
|
ox = ox * s
|
||||||
|
oy = oy * s
|
||||||
|
lox = lox *s
|
||||||
|
loy = loy * s
|
||||||
|
w = w * s
|
||||||
|
h = h * s
|
||||||
|
x = x + ox
|
||||||
|
y = y + oy
|
||||||
|
|
||||||
|
return x, y, w, h, ox, oy, lox, loy
|
||||||
|
end
|
||||||
|
|
||||||
|
function world:update(dt)
|
||||||
|
local xm, ym = love.mouse.getPosition()
|
||||||
|
local x, y, w, h, ox, oy, lox, loy, s = self.data.pos[1], self.data.pos[2],
|
||||||
|
self.data.wh[1], self.data.wh[2],
|
||||||
|
self.data.origin[1], self.data.origin[2],
|
||||||
|
self.data.label_origin[1], self.data.label_origin[2],
|
||||||
|
self.data.scale
|
||||||
|
x, y, w, h, ox, oy, lox, loy = transform(x, y, w, h, ox, oy, lox, loy, s)
|
||||||
|
if (is_inside(x, y, w, h, xm, ym)) then
|
||||||
|
self.data.temp_color = self.data.highlight_color
|
||||||
|
if (love.mouse.isDown(1)) then
|
||||||
|
if (self.mouse == "not click") then
|
||||||
|
self.mouse = "click"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if (self.mouse == "click") then
|
||||||
|
self.mouse = "not click"
|
||||||
|
self.data.func()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self.data.temp_color = self.data.bg_color
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function draw_text(text, x, y, c)
|
local function draw_text(text, x, y, c)
|
||||||
local font_ix = test.draw_font_start()
|
local font_ix = test.draw_font_start()
|
||||||
test.draw_font_set_base_color(c[1], c[2], c[3])
|
test.draw_font_set_base_color(c[1], c[2], c[3])
|
||||||
@ -83,9 +126,8 @@ local function draw_box(x, y, w, h, c)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function draw_button(text, x, y, w, h, ox, oy, lox, loy, ct, cl, cb)
|
local function draw_button(text, x, y, w, h, ox, oy, lox, loy, s, ct, cl, cb)
|
||||||
x = x + ox
|
x, y, w, h, ox, oy, lox, loy = transform(x, y, w, h, ox, oy, lox, loy, s)
|
||||||
y = y + oy
|
|
||||||
test.draw_line_quad_start()
|
test.draw_line_quad_start()
|
||||||
draw_box(x, y, w, h, cb)
|
draw_box(x, y, w, h, cb)
|
||||||
draw_outline(x, y, w, h, cl)
|
draw_outline(x, y, w, h, cl)
|
||||||
@ -99,7 +141,8 @@ function world:ui_draw()
|
|||||||
self.data.pos[1], self.data.pos[2], self.data.wh[1], self.data.wh[2],
|
self.data.pos[1], self.data.pos[2], self.data.wh[1], self.data.wh[2],
|
||||||
self.data.origin[1], self.data.origin[2],
|
self.data.origin[1], self.data.origin[2],
|
||||||
self.data.label_origin[1], self.data.label_origin[2],
|
self.data.label_origin[1], self.data.label_origin[2],
|
||||||
self.data.label_color, self.data.line_color, self.data.bg_color
|
self.data.scale,
|
||||||
|
self.data.label_color, self.data.line_color, self.data.temp_color
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
36
game/love_src/src/new/world/main_menu/data/main_menu.lua
Normal file
36
game/love_src/src/new/world/main_menu/data/main_menu.lua
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
local vm = require"lib.vornmath"
|
||||||
|
local wm = require"world_map"
|
||||||
|
|
||||||
|
local lw, lh = love.graphics.getDimensions()
|
||||||
|
|
||||||
|
local function to_play()
|
||||||
|
load_world(wm["town"])
|
||||||
|
end
|
||||||
|
|
||||||
|
local wh = vm.vec2(120, 60)
|
||||||
|
local l_wh = vm.vec2(50, 25)
|
||||||
|
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
type = "button",
|
||||||
|
name = "button_to_play",
|
||||||
|
components = {
|
||||||
|
button = require"love_src.src.new.world.main_menu.components.button"
|
||||||
|
},
|
||||||
|
data = {
|
||||||
|
button = {
|
||||||
|
pos = vm.vec2(lw/2, lh/2),
|
||||||
|
wh = wh,
|
||||||
|
scale = 1,
|
||||||
|
origin = vm.vec2(-wh[1]/2, -wh[2]/2),
|
||||||
|
label_origin = vm.vec2(l_wh[1]/2, l_wh[2]/2),
|
||||||
|
label_color = {255/255, 255/255, 255/255},
|
||||||
|
bg_color = {0, 1, 0},
|
||||||
|
line_color = {1, 0, 0},
|
||||||
|
highlight_color = {0, 0, 1},
|
||||||
|
func = to_play,
|
||||||
|
label = "Play",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
36
game/love_src/src/new/world/main_menu/data/monastery.lua
Normal file
36
game/love_src/src/new/world/main_menu/data/monastery.lua
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
local vm = require"lib.vornmath"
|
||||||
|
local wm = require"world_map"
|
||||||
|
|
||||||
|
local lw, lh = love.graphics.getDimensions()
|
||||||
|
|
||||||
|
local function to_track_choose()
|
||||||
|
load_world(wm["track_choose"])
|
||||||
|
end
|
||||||
|
|
||||||
|
local wh = vm.vec2(120, 60)
|
||||||
|
local l_wh = vm.vec2(50, 25)
|
||||||
|
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
type = "button",
|
||||||
|
name = "button_to_race",
|
||||||
|
components = {
|
||||||
|
button = require"love_src.src.new.world.main_menu.components.button"
|
||||||
|
},
|
||||||
|
data = {
|
||||||
|
button = {
|
||||||
|
pos = vm.vec2(lw/2, lh/2),
|
||||||
|
wh = wh,
|
||||||
|
scale = 1,
|
||||||
|
origin = vm.vec2(-wh[1]/2, -wh[2]/2),
|
||||||
|
label_origin = vm.vec2(l_wh[1]/2, l_wh[2]/2),
|
||||||
|
label_color = {255/255, 255/255, 255/255},
|
||||||
|
bg_color = {0, 1, 0},
|
||||||
|
line_color = {1, 0, 0},
|
||||||
|
highlight_color = {0, 0, 1},
|
||||||
|
func = to_track_choose,
|
||||||
|
label = "Next Race",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
62
game/love_src/src/new/world/main_menu/data/town.lua
Normal file
62
game/love_src/src/new/world/main_menu/data/town.lua
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
local vm = require"lib.vornmath"
|
||||||
|
local wm = require"world_map"
|
||||||
|
|
||||||
|
local lw, lh = love.graphics.getDimensions()
|
||||||
|
|
||||||
|
local function to_track_choose()
|
||||||
|
load_world(wm["track_choose"])
|
||||||
|
end
|
||||||
|
|
||||||
|
local function to_monastery()
|
||||||
|
load_world(wm["monastery"])
|
||||||
|
end
|
||||||
|
|
||||||
|
local wh = vm.vec2(120, 60)
|
||||||
|
local l_wh = vm.vec2(50, 25)
|
||||||
|
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
type = "button",
|
||||||
|
name = "button_to_track_choose",
|
||||||
|
components = {
|
||||||
|
button = require"love_src.src.new.world.main_menu.components.button"
|
||||||
|
},
|
||||||
|
data = {
|
||||||
|
button = {
|
||||||
|
pos = vm.vec2(lw/2 + wh[1], lh/2),
|
||||||
|
wh = wh,
|
||||||
|
scale = 1,
|
||||||
|
origin = vm.vec2(-wh[1]/2, -wh[2]/2),
|
||||||
|
label_origin = vm.vec2(l_wh[1]/2, l_wh[2]/2),
|
||||||
|
label_color = {255/255, 255/255, 255/255},
|
||||||
|
bg_color = {0, 1, 0},
|
||||||
|
line_color = {1, 0, 0},
|
||||||
|
highlight_color = {0, 0, 1},
|
||||||
|
func = to_track_choose,
|
||||||
|
label = "Next Race",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "button",
|
||||||
|
name = "button_to_monastery",
|
||||||
|
components = {
|
||||||
|
button = require"love_src.src.new.world.main_menu.components.button"
|
||||||
|
},
|
||||||
|
data = {
|
||||||
|
button = {
|
||||||
|
pos = vm.vec2(lw/2 - wh[1], lh/2),
|
||||||
|
wh = wh,
|
||||||
|
scale = 1,
|
||||||
|
origin = vm.vec2(-wh[1]/2, -wh[2]/2),
|
||||||
|
label_origin = vm.vec2(l_wh[1]/2, l_wh[2]/2),
|
||||||
|
label_color = {255/255, 255/255, 255/255},
|
||||||
|
bg_color = {0, 1, 0},
|
||||||
|
line_color = {1, 0, 0},
|
||||||
|
highlight_color = {0, 0, 1},
|
||||||
|
func = to_monastery,
|
||||||
|
label = "Monastery",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
62
game/love_src/src/new/world/main_menu/data/track_choose.lua
Normal file
62
game/love_src/src/new/world/main_menu/data/track_choose.lua
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
local vm = require"lib.vornmath"
|
||||||
|
local wm = require"world_map"
|
||||||
|
|
||||||
|
local lw, lh = love.graphics.getDimensions()
|
||||||
|
|
||||||
|
local function to_track_1()
|
||||||
|
load_world(wm["track_1"])
|
||||||
|
end
|
||||||
|
|
||||||
|
local function to_track_2()
|
||||||
|
load_world(wm["track_2"])
|
||||||
|
end
|
||||||
|
|
||||||
|
local wh = vm.vec2(120, 60)
|
||||||
|
local l_wh = vm.vec2(50, 25)
|
||||||
|
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
type = "button",
|
||||||
|
name = "button_to_track_1",
|
||||||
|
components = {
|
||||||
|
button = require"love_src.src.new.world.main_menu.components.button"
|
||||||
|
},
|
||||||
|
data = {
|
||||||
|
button = {
|
||||||
|
pos = vm.vec2(lw/2 + wh[1], lh/2),
|
||||||
|
wh = wh,
|
||||||
|
scale = 1,
|
||||||
|
origin = vm.vec2(-wh[1]/2, -wh[2]/2),
|
||||||
|
label_origin = vm.vec2(l_wh[1]/2, l_wh[2]/2),
|
||||||
|
label_color = {255/255, 255/255, 255/255},
|
||||||
|
bg_color = {0, 1, 0},
|
||||||
|
line_color = {1, 0, 0},
|
||||||
|
highlight_color = {0, 0, 1},
|
||||||
|
func = to_track_1,
|
||||||
|
label = "Track 1",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "button",
|
||||||
|
name = "button_to_track_2",
|
||||||
|
components = {
|
||||||
|
button = require"love_src.src.new.world.main_menu.components.button"
|
||||||
|
},
|
||||||
|
data = {
|
||||||
|
button = {
|
||||||
|
pos = vm.vec2(lw/2 - wh[1], lh/2),
|
||||||
|
wh = wh,
|
||||||
|
scale = 1,
|
||||||
|
origin = vm.vec2(-wh[1]/2, -wh[2]/2),
|
||||||
|
label_origin = vm.vec2(l_wh[1]/2, l_wh[2]/2),
|
||||||
|
label_color = {255/255, 255/255, 255/255},
|
||||||
|
bg_color = {0, 1, 0},
|
||||||
|
line_color = {1, 0, 0},
|
||||||
|
highlight_color = {0, 0, 1},
|
||||||
|
func = to_track_2,
|
||||||
|
label = "Track 2",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -42,6 +42,7 @@ local default_entities = {
|
|||||||
label_color = {255/255, 255/255, 255/255},
|
label_color = {255/255, 255/255, 255/255},
|
||||||
bg_color = {0, 1, 0},
|
bg_color = {0, 1, 0},
|
||||||
line_color = {1, 0, 0},
|
line_color = {1, 0, 0},
|
||||||
|
highlight_color = {0, 0, 1},
|
||||||
func = to_race,
|
func = to_race,
|
||||||
label = "play",
|
label = "play",
|
||||||
}
|
}
|
||||||
@ -49,10 +50,7 @@ local default_entities = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function world:load(data, entities_data)
|
function world:setup()
|
||||||
self.data = data or default
|
|
||||||
self.entities_data = entities_data or default_entities
|
|
||||||
|
|
||||||
for _, d in pairs(self.entities_data) do
|
for _, d in pairs(self.entities_data) do
|
||||||
local e = {
|
local e = {
|
||||||
type = d.type,
|
type = d.type,
|
||||||
@ -67,6 +65,13 @@ function world:load(data, entities_data)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function world:load(data, entities_data)
|
||||||
|
self.data = data
|
||||||
|
self.entities_data = entities_data
|
||||||
|
|
||||||
|
self:setup()
|
||||||
|
end
|
||||||
|
|
||||||
function world:update(dt)
|
function world:update(dt)
|
||||||
for _, e in ipairs(self.entities) do
|
for _, e in ipairs(self.entities) do
|
||||||
for t, c in pairs(e.components) do
|
for t, c in pairs(e.components) do
|
||||||
|
|||||||
@ -70,12 +70,7 @@ function world:new()
|
|||||||
self.entities = {}
|
self.entities = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function world:load(data, entities_data)
|
function world:setup()
|
||||||
self.data = data or default
|
|
||||||
self.is_loaded = true
|
|
||||||
|
|
||||||
self.entities_data = entities_data or entities_default
|
|
||||||
|
|
||||||
local map
|
local map
|
||||||
for _, d in pairs(self.entities_data) do
|
for _, d in pairs(self.entities_data) do
|
||||||
local e = {
|
local e = {
|
||||||
@ -101,7 +96,15 @@ function world:load(data, entities_data)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function world:load(data, entities_data)
|
||||||
|
self.data = data or default
|
||||||
|
self.is_loaded = true
|
||||||
|
|
||||||
|
self.entities_data = entities_data or entities_default
|
||||||
|
|
||||||
|
self:setup()
|
||||||
end
|
end
|
||||||
|
|
||||||
function world:update(dt)
|
function world:update(dt)
|
||||||
|
|||||||
@ -190,26 +190,56 @@ end
|
|||||||
|
|
||||||
local wm = require("world_map")
|
local wm = require("world_map")
|
||||||
|
|
||||||
world = {
|
local world = {};
|
||||||
["main_menu"] = require("love_src.src.new.world.main_menu.init")(),
|
|
||||||
["race"] = require("love_src.src.new.world.race.init")(),
|
local world_data = {
|
||||||
-- ["top_down_race"] = require("love_src.src.world.top_down_race")(),
|
["main_menu"] = {
|
||||||
-- ["main_menu"] = require("love_src.src.world.main_menu")(),
|
world = require("love_src.src.new.world.main_menu.init")(),
|
||||||
-- ["1_intro"] = require("love_src.src.world.1_intro")(),
|
data = {},
|
||||||
-- ["2_town_square"] = require("love_src.src.world.2_town_square")(),
|
entities_data = require("love_src.src.new.world.main_menu.data.main_menu"),
|
||||||
-- ["race"] = require("love_src.src.world.race")(),
|
},
|
||||||
-- ["train"] = require("love_src.src.world.train")(),
|
["town"] = {
|
||||||
};
|
world = require("love_src.src.new.world.main_menu.init")(),
|
||||||
|
data = {},
|
||||||
|
entities_data = require("love_src.src.new.world.main_menu.data.town"),
|
||||||
|
},
|
||||||
|
["monastery"] = {
|
||||||
|
world = require("love_src.src.new.world.main_menu.init")(),
|
||||||
|
data = {},
|
||||||
|
entities_data = require("love_src.src.new.world.main_menu.data.monastery"),
|
||||||
|
},
|
||||||
|
["track_choose"] = {
|
||||||
|
world = require("love_src.src.new.world.main_menu.init")(),
|
||||||
|
data = {},
|
||||||
|
entities_data = require("love_src.src.new.world.main_menu.data.track_choose"),
|
||||||
|
},
|
||||||
|
["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"),
|
||||||
|
},
|
||||||
|
["track_2"] = {
|
||||||
|
world = require("love_src.src.new.world.race.init")(),
|
||||||
|
-- data = {},
|
||||||
|
-- entities_data = require("love_src.src.new.world.main_menu.data.track_choose"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
current = wm["main_menu"]
|
current = wm["main_menu"]
|
||||||
|
|
||||||
function load_world(world_to_load)
|
function load_world(world_to_load)
|
||||||
|
print(current)
|
||||||
current = world_to_load
|
current = world_to_load
|
||||||
world[current]:reload()
|
print(current)
|
||||||
|
local c_w = world_data[current]
|
||||||
|
world[current] = c_w.world
|
||||||
|
world[current]:load(c_w.data, c_w.entities_data)
|
||||||
|
-- world[current]:reload()
|
||||||
end
|
end
|
||||||
|
|
||||||
function love_load()
|
function love_load()
|
||||||
world[current]:load()
|
load_world(current)
|
||||||
|
-- world[current]:load()
|
||||||
end
|
end
|
||||||
|
|
||||||
function love_update(dt)
|
function love_update(dt)
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
return {
|
return {
|
||||||
-- ["top_down_race"] = "top_down_race",
|
-- ["top_down_race"] = "top_down_race",
|
||||||
["main_menu"] = "main_menu",
|
["main_menu"] = "main_menu",
|
||||||
["1_intro"] = "1_intro",
|
["town"] = "town",
|
||||||
["2_town_square"] = "2_town_square",
|
["monastery"] = "monastery",
|
||||||
["race"] = "race",
|
["track_choose"] = "track_choose",
|
||||||
|
["track_1"] = "track_1",
|
||||||
|
["track_2"] = "track_2",
|
||||||
|
-- ["1_intro"] = "1_intro",
|
||||||
|
-- ["2_town_square"] = "2_town_square",
|
||||||
|
-- ["race"] = "race",
|
||||||
-- ["train"] = "train"
|
-- ["train"] = "train"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user