Browse Source

we kinda have a main menu now

master
Nicholas Hayashi 4 years ago
parent
commit
f87689cd54
  1. 5
      color.lua
  2. 89
      main.lua
  3. BIN
      res/abouthex.png
  4. BIN
      res/loadgamehex.png
  5. BIN
      res/mapeditorhex.png
  6. BIN
      res/newgamehex.png
  7. BIN
      res/settingshex.png
  8. 13
      src/hexyz.lua
  9. 6
      src/tower.lua
  10. 6
      texture.lua

5
color.lua

@ -10,6 +10,7 @@ COLORS = {
BLACK = vec4(0, 0, 0.05, 1), BLACK = vec4(0, 0, 0.05, 1),
VERY_DARK_GRAY = vec4(35/255, 35/255, 25/255, 1), VERY_DARK_GRAY = vec4(35/255, 35/255, 25/255, 1),
TRUE_BLACK = vec4(0, 0, 0, 1), TRUE_BLACK = vec4(0, 0, 0, 1),
EIGENGRAU = vec4(0, 0, 0.02, 1),
-- non-standard ??? hues -- non-standard ??? hues
WATER = vec4(0.12, 0.25, 0.3, 1), WATER = vec4(0.12, 0.25, 0.3, 1),
@ -20,6 +21,8 @@ COLORS = {
-- hues -- hues
CLARET = vec4(139/255, 30/255, 63/255, 1), CLARET = vec4(139/255, 30/255, 63/255, 1),
SUNRAY = vec4(228/255, 179/255, 99/255, 1), SUNRAY = vec4(228/255, 179/255, 99/255, 1),
GREEN_YELLOW = vec4(204/255, 255/255, 102/255, 1)
GREEN_YELLOW = vec4(204/255, 255/255, 102/255, 1),
BLUE = vec4(50/255, 50/255, 180/255, 1),
MAGENTA = vec4(183/255, 0/255, 213/255, 1),
} }

89
main.lua

@ -49,26 +49,92 @@ end
function make_main_scene_toolbelt() function make_main_scene_toolbelt()
local options = { local options = {
false,
false,
false,
false,
{ {
label = "new game", label = "new game",
action = function(self) end
texture = TEXTURES.NEW_GAME_HEX,
action = function() end
}, },
{ {
label = "load game", label = "load game",
action = function(self) game_init(am.load_state("save", "json")) end
texture = TEXTURES.LOAD_GAME_HEX,
action = function() game_init(am.load_state("save", "json")) end
}, },
false,
{ {
label = "map editor",
action = function(self) log("map editor not implemented") end
label = "settings",
texture = TEXTURES.SETTINGS_HEX,
action = function() end
}, },
{ {
label = "settings",
action = function(self) end
label = "about",
texture = TEXTURES.ABOUT_HEX,
action = function() end
},
false,
false,
false,
{
label = "map editor",
texture = TEXTURES.MAP_EDITOR_HEX,
action = function() log("map editor not implemented") end
}, },
false
} }
--local map = hex_rectangular_map(10, 20, HEX_ORIENTATION.POINTY)
return group
local spacing = 160
-- calculate the dimensions of the whole grid
local grid_width = 10
local grid_height = 2
local hhs = hex_horizontal_spacing(spacing)
local hvs = hex_vertical_spacing(spacing)
local grid_pixel_width = grid_width * hhs
local grid_pixel_height = grid_height * hvs
local pixel_offset = vec2(-grid_pixel_width/2, win.bottom + hex_height(spacing)/2 + 20)
local map = hex_rectangular_map(grid_width, grid_height, HEX_ORIENTATION.POINTY)
local group = am.group()
local option_index = 1
for i,_ in pairs(map) do
for j,_ in pairs(map[i]) do
local hex = vec2(i, j)
local position = hex_to_pixel(hex, vec2(spacing), HEX_ORIENTATION.POINTY)
local option = options[option_index]
local texture = option and option.texture or TEXTURES.SHADED_HEX
local node = am.translate(position)
^ pack_texture_into_sprite(texture, texture.width, texture.height, COLORS.TRANSPARENT)
hex_map_set(map, i, j, {
node = node,
option = option
})
local tile = hex_map_get(map, i, j)
node:action(function(self)
local mouse = win:mouse_position()
local hex_ = pixel_to_hex(mouse - pixel_offset, vec2(spacing), HEX_ORIENTATION.POINTY)
if hex == hex_ and tile.option then
tile.node"sprite".color = vec4(1)
if win:mouse_pressed("left") then
tile.option.action()
end
else
tile.node"sprite".color = COLORS.TRANSPARENT
end
end)
group:append(node)
option_index = option_index + 1
end
end
return am.translate(pixel_offset) ^ group
end end
function main_scene() function main_scene()
@ -91,7 +157,9 @@ function main_scene()
end end
group:append(hex_backdrop) group:append(hex_backdrop)
group:append(am.translate(0, 200) ^ am.sprite("res/logo.png"))
local logo_height = 480
group:append(am.translate(0, win.top - 20 - logo_height/2) ^ am.sprite("res/logo.png"))
group:append(make_main_scene_toolbelt()) group:append(make_main_scene_toolbelt())
group:action(main_action) group:action(main_action)
@ -100,6 +168,7 @@ function main_scene()
end end
win.scene = am.group() win.scene = am.group()
game_init()
win.scene = main_scene()
--game_init()
noglobals() noglobals()

BIN
res/abouthex.png

After

Width: 282  |  Height: 290  |  Size: 60 KiB

BIN
res/loadgamehex.png

After

Width: 282  |  Height: 290  |  Size: 52 KiB

BIN
res/mapeditorhex.png

After

Width: 283  |  Height: 290  |  Size: 59 KiB

BIN
res/newgamehex.png

After

Width: 282  |  Height: 290  |  Size: 61 KiB

BIN
res/settingshex.png

After

Width: 282  |  Height: 290  |  Size: 59 KiB

13
src/hexyz.lua

@ -18,6 +18,9 @@ end
if not table.append then if not table.append then
end end
if not table.filter then
end
-- wherever 'orientation' appears as an argument, use one of these two, or set a default just below -- wherever 'orientation' appears as an argument, use one of these two, or set a default just below
HEX_ORIENTATION = { HEX_ORIENTATION = {
@ -389,7 +392,6 @@ function hex_hexagonal_map(radius, seed)
end end
-- Returns Unordered Rectangular Map of |width| and |height| with Simplex Noise -- Returns Unordered Rectangular Map of |width| and |height| with Simplex Noise
-- @TODO - this doesn't work for pointy orientations
function hex_rectangular_map(width, height, orientation, seed) function hex_rectangular_map(width, height, orientation, seed)
local orientation = orientation or HEX_DEFAULT_ORIENTATION local orientation = orientation or HEX_DEFAULT_ORIENTATION
local seed = seed or math.random(width * height) local seed = seed or math.random(width * height)
@ -417,7 +419,14 @@ function hex_rectangular_map(width, height, orientation, seed)
end end
end end
elseif orientation == HEX_ORIENTATION.POINTY then elseif orientation == HEX_ORIENTATION.POINTY then
error("don't use this, it's broken")
for i = 0, height - 1 do
local i_offset = math.floor(i/2)
for j = -i_offset, width - i_offset - 1 do
hex_map_set(map, j, i, 0)
end
end
else
error("bad orientation value")
end end
return setmetatable(map, { __index = { return setmetatable(map, { __index = {

6
src/tower.lua

@ -131,9 +131,9 @@ function make_tower_node(tower_type)
elseif tower_type == TOWER_TYPE.HOWITZER then elseif tower_type == TOWER_TYPE.HOWITZER then
return am.group{ return am.group{
am.circle(vec2(0), HEX_SIZE, COLORS.VERY_DARK_GRAY{a=0.8}, 6),
am.circle(vec2(0), HEX_SIZE, COLORS.VERY_DARK_GRAY, 6),
am.rotate(state.time or 0) ^ am.group{ am.rotate(state.time or 0) ^ am.group{
pack_texture_into_sprite(TEXTURES.CANNON1, HEX_PIXEL_HEIGHT*2, HEX_PIXEL_WIDTH*3) -- CHONK
pack_texture_into_sprite(TEXTURES.CANNON1, HEX_PIXEL_HEIGHT*1.5, HEX_PIXEL_WIDTH*2) -- CHONK
} }
} }
elseif tower_type == TOWER_TYPE.LIGHTHOUSE then elseif tower_type == TOWER_TYPE.LIGHTHOUSE then
@ -163,7 +163,7 @@ function make_tower_node(tower_type)
} }
} }
elseif tower_type == TOWER_TYPE.WALL then elseif tower_type == TOWER_TYPE.WALL then
return am.circle(vec2(0), HEX_SIZE, COLORS.VERY_DARK_GRAY, 6)
return am.circle(vec2(0), HEX_SIZE, COLORS.VERY_DARK_GRAY{a=0.75}, 6)
elseif tower_type == TOWER_TYPE.MOAT then elseif tower_type == TOWER_TYPE.MOAT then
return am.circle(vec2(0), HEX_SIZE, COLORS.WATER{a=1}, 6) return am.circle(vec2(0), HEX_SIZE, COLORS.WATER{a=1}, 6)

6
texture.lua

@ -15,6 +15,12 @@ TEXTURES = {
GEM1 = load_texture("res/gem1.png"), GEM1 = load_texture("res/gem1.png"),
SHADED_HEX = load_texture("res/shaded_hex1.png"), SHADED_HEX = load_texture("res/shaded_hex1.png"),
NEW_GAME_HEX = load_texture("res/newgamehex.png"),
LOAD_GAME_HEX = load_texture("res/loadgamehex.png"),
SETTINGS_HEX = load_texture("res/settingshex.png"),
MAP_EDITOR_HEX = load_texture("res/mapeditorhex.png"),
ABOUT_HEX = load_texture("res/abouthex.png"),
-- gui stuff -- gui stuff
BUTTON1 = load_texture("res/button1.png"), BUTTON1 = load_texture("res/button1.png"),
WIDER_BUTTON1 = load_texture("res/wider_button1.png"), WIDER_BUTTON1 = load_texture("res/wider_button1.png"),

Loading…
Cancel
Save