diff --git a/color.lua b/color.lua index cb0c448..475f588 100644 --- a/color.lua +++ b/color.lua @@ -5,7 +5,7 @@ COLORS = { TRANSPARENT1 = vec4(0.4), -- tones - WHITE = vec4(1, 1, 0.95, 1), + WHITE = vec4(1, 1, 0.98, 1), PALE_SILVER = vec4(193/255, 178/255, 171/255, 1), BLACK = vec4(0, 0, 0.05, 1), VERY_DARK_GRAY = vec4(35/255, 35/255, 25/255, 1), diff --git a/conf.lua b/conf.lua index 70efd8c..360aaf9 100644 --- a/conf.lua +++ b/conf.lua @@ -2,7 +2,7 @@ title = "hexyz" author = "nick hayashi" shortname = "hexyz" -version = "1.0.0" +version = "0.1.1" support_email = "hayashi.nicholas@gmail.com" copyright_message = "Copyright © 2021 Nick Hayashi" diff --git a/main.lua b/main.lua index a53d5a5..4f987f6 100644 --- a/main.lua +++ b/main.lua @@ -27,6 +27,7 @@ do end -- asset interfaces and/or trivial code +require "conf" require "color" require "sound" require "texture" @@ -44,7 +45,17 @@ require "src/tower" function main_action(self) - self"hex_backdrop""rotate".angle = math.wrapf(self"hex_backdrop""rotate".angle - 0.005 * am.delta_time, math.pi*2) + if win:key_pressed("escape") then + if win.scene("game") then + win.scene("game").paused = false + win.scene:remove(self) + else + --win:close() + end + end + if self"hex_backdrop" then + self"hex_backdrop""rotate".angle = math.wrapf(self"hex_backdrop""rotate".angle - 0.005 * am.delta_time, math.pi*2) + end end function make_main_scene_toolbelt() @@ -52,38 +63,41 @@ function make_main_scene_toolbelt() false, false, false, - false, { texture = TEXTURES.NEW_GAME_HEX, action = function() game_init() end }, + false, { texture = TEXTURES.LOAD_GAME_HEX, action = function() game_init(am.load_state("save", "json")) end }, false, + false, + false, + { + texture = TEXTURES.MAP_EDITOR_HEX, + action = function() alert("not yet :)") end + }, { texture = TEXTURES.SETTINGS_HEX, - action = function() end + action = function() alert("not yet :)") end }, { texture = TEXTURES.ABOUT_HEX, - action = function() end + action = function() alert("not yet :)") end }, false, - false, - false, { - texture = TEXTURES.MAP_EDITOR_HEX, - action = function() log("map editor not implemented") end - }, - false + texture = TEXTURES.QUIT_HEX, + action = function() win:close() end + } } local spacing = 160 -- calculate the dimensions of the whole grid - local grid_width = 10 + local grid_width = 8 local grid_height = 2 local hhs = hex_horizontal_spacing(spacing) local hvs = hex_vertical_spacing(spacing) @@ -100,8 +114,9 @@ function make_main_scene_toolbelt() 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 color = option and COLORS.TRANSPARENT or vec4(0.3) local node = am.translate(position) - ^ pack_texture_into_sprite(texture, texture.width, texture.height, COLORS.TRANSPARENT) + ^ pack_texture_into_sprite(texture, texture.width, texture.height, color) hex_map_set(map, i, j, { node = node, @@ -109,18 +124,26 @@ function make_main_scene_toolbelt() }) local tile = hex_map_get(map, i, j) + local selected = false 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() + if tile.option then + if hex == hex_ then + if not selected then + play_sfx(SOUNDS.SELECT1) + end + selected = true + tile.node"sprite".color = vec4(1) + + if win:mouse_pressed("left") then + tile.option.action() + end + else + selected = false + tile.node"sprite".color = COLORS.TRANSPARENT end - else - tile.node"sprite".color = COLORS.TRANSPARENT end end) @@ -132,25 +155,34 @@ function make_main_scene_toolbelt() return am.translate(pixel_offset) ^ group end -function main_scene() +function main_scene(do_backdrop) local group = am.group() - local map = hex_hexagonal_map(30) - local hex_backdrop = (am.rotate(0) ^ am.group()):tag"hex_backdrop" - for i,_ in pairs(map) do - for j,n in pairs(map[i]) do - local color = map_elevation_color(n) - color = color{a=color.a - 0.1} + if do_backdrop then + local map = hex_hexagonal_map(30) + local hex_backdrop = (am.rotate(0) ^ am.group()):tag"hex_backdrop" + for i,_ in pairs(map) do + for j,n in pairs(map[i]) do + local color = map_elevation_color(n) + color = color{a=color.a - 0.1} - local node = am.translate(hex_to_pixel(vec2(i, j), vec2(HEX_SIZE))) - ^ am.circle(vec2(0), HEX_SIZE, vec4(0), 6) + local node = am.translate(hex_to_pixel(vec2(i, j), vec2(HEX_SIZE))) + ^ am.circle(vec2(0), HEX_SIZE, vec4(0), 6) - node"circle":action(am.tween(1, { color = color })) + node"circle":action(am.tween(1, { color = color })) - hex_backdrop:append(node) + hex_backdrop:append(node) + end end + group:append(hex_backdrop) + else + group:append(am.rect(win.left, win.bottom, win.right, win.top, COLORS.TRANSPARENT)) end - group:append(hex_backdrop) + + group:append( + am.translate(win.right - 10, win.bottom + 20) + ^ am.text(version, COLORS.WHITE, "right") + ) local logo_height = 480 group:append(am.translate(0, win.top - 20 - logo_height/2) ^ am.sprite("res/logo.png")) @@ -162,6 +194,6 @@ function main_scene() return group end -win.scene = main_scene() +win.scene = main_scene(true) noglobals() diff --git a/res/abouthex.png b/res/abouthex.png index 6754485..5e88296 100644 Binary files a/res/abouthex.png and b/res/abouthex.png differ diff --git a/res/loadgamehex.png b/res/loadgamehex.png index d6d5b91..d4f791b 100644 Binary files a/res/loadgamehex.png and b/res/loadgamehex.png differ diff --git a/res/mapeditorhex.png b/res/mapeditorhex.png index 8ada9b1..e2ad95e 100644 Binary files a/res/mapeditorhex.png and b/res/mapeditorhex.png differ diff --git a/res/newgamehex.png b/res/newgamehex.png index 96363c4..5008f8b 100644 Binary files a/res/newgamehex.png and b/res/newgamehex.png differ diff --git a/res/quithex.png b/res/quithex.png new file mode 100644 index 0000000..0b5cf86 Binary files /dev/null and b/res/quithex.png differ diff --git a/res/settingshex.png b/res/settingshex.png index 0b7ed6c..213a591 100644 Binary files a/res/settingshex.png and b/res/settingshex.png differ diff --git a/res/shaded_hex.png b/res/shaded_hex.png new file mode 100644 index 0000000..d3d0378 Binary files /dev/null and b/res/shaded_hex.png differ diff --git a/src/game.lua b/src/game.lua index 08de570..d8bdec6 100644 --- a/src/game.lua +++ b/src/game.lua @@ -117,23 +117,7 @@ end local function game_pause() win.scene("game").paused = true - win.scene:append(am.group{ - am.rect(win.left, win.bottom, win.right, win.top, COLORS.TRANSPARENT), - gui_textfield(vec2(-300, 0), vec2(200, 100)), - } - :tag"pause_menu") - - win.scene:action(function(self) - if win:key_pressed("escape") then - win.scene:remove("pause_menu") - win.scene("game").paused = false - return true - - elseif win:key_pressed("f4") then - game_end() - return true - end - end) + win.scene:append(main_scene(false):tag"pause_menu") end local function game_deserialize(json_string) @@ -179,6 +163,8 @@ end local function game_serialize() local serialized = table.shallow_copy(state) + serialized.version = version + serialized.seed = state.map.seed serialized.map = nil -- we re-generate the entire map from the seed on de-serialize diff --git a/src/tower.lua b/src/tower.lua index 4b9783f..504dc45 100644 --- a/src/tower.lua +++ b/src/tower.lua @@ -231,7 +231,6 @@ function tower_deserialize(json_string) local tower = entity_basic_json_parse(json_string) for i,h in pairs(tower.hexes) do - log(h) tower.hexes[i] = vec2(tower.hexes[i][1], tower.hexes[i][2]) end diff --git a/texture.lua b/texture.lua index d6eef11..d37e243 100644 --- a/texture.lua +++ b/texture.lua @@ -13,13 +13,14 @@ end TEXTURES = { LOGO = load_texture("res/logo.png"), GEM1 = load_texture("res/gem1.png"), - SHADED_HEX = load_texture("res/shaded_hex1.png"), + SHADED_HEX = load_texture("res/shaded_hex.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"), + QUIT_HEX = load_texture("res/quithex.png"), -- gui stuff BUTTON1 = load_texture("res/button1.png"),