diff --git a/hex.lua b/hex.lua index 3178cfb..3dee70d 100644 --- a/hex.lua +++ b/hex.lua @@ -7,8 +7,9 @@ but nearly always the former. -- RESOURCES USED TO DEVELOP THIS LIBRARY, AND FOR WHICH I AM GRATEFUL - https://redblobgames.com/grid/hexagons - simply amazing. - http://amulet.xyz/doc - amulet documentation + https://catlikecoding.com/unity/tutorials/hex-map/ + https://redblobgames.com/grid/hexagons + http://amulet.xyz/doc ]] ----- [[ GENERALLY USEFUL FUNCTIONS ]] ----------------------------------------- @@ -38,6 +39,15 @@ function hex_neighbour(hex, direction) return hex + HEX_DIRECTIONS[(6 + (direction % 6)) % 6 + 1] end +-- TODO +function hex_rotate_left(hex) + +end + +function hex_rotate_right(hex) + +end + -- rounds hexes. without this, pixel_to_hex returns fractional coordinates. function hex_round(s, t) local rs = round(s) @@ -75,7 +85,7 @@ local POINTY = {M = mat2(3.0^0.5, 3.0^0.5/2.0, 0.0, 3.0/2.0), -- stores layout information that does not pertain to map shape function hex_layout(origin, size, orientation) return {origin = origin or vec2(0), - size = size or vec2(11), + size = size or vec2(12), orientation = orientation or FLAT} end @@ -141,10 +151,10 @@ function hex_spiral_map(center, radius) return map end --- returns unordered parallelogram-shaped map of |width| and |height|. +-- returns unordered parallelogram-shaped map of |width| and |height|. function hex_parallelogram_map(width, height) local map = {} - local mt = {__index={width=width, height=height}} + local mt = {__index={width=width, height=height}} setmetatable(map, mt) @@ -171,8 +181,8 @@ function hex_triangular_map(size) return map end --- returns unordered hexagonal map of |radius|. -function hex_hexagonal_map(radius) +-- returns unordered hexagonal map of |radius|. +function hex_hexagonal_map(radius) local map = {} local mt = {__index={radius=radius}} @@ -189,18 +199,18 @@ function hex_hexagonal_map(radius) return map end --- returns unordered rectangular map of |width| and |height|. +-- returns unordered rectangular map of |width| and |height|. function hex_rectangular_map(width, height) local map = {} local mt = {__index={width=width, height=height}} - setmetatable(map, mt) + setmetatable(map, mt) for s = 0, width do for t = 0, height do map[vec2(s, t - math.floor(s/2))] = true end end - return map + return map end diff --git a/main.lua b/main.lua index 61352b4..211bb4e 100644 --- a/main.lua +++ b/main.lua @@ -5,56 +5,103 @@ require "hex" require "util" +------ [[ GLOBALS ]] ----------------------------------------------------------- + local win = am.window{ -- BASE RESOLUTION = 3/4 * WXGA Standard 16:10 width = 1280 * 3 / 4, -- 960px height = 800 * 3 / 4, -- 600px + title = "Warzone 2: Electric Boogaloo", + clear_color = vec4(22/255, 22/255, 29/255, 1) + } - title = "Warzone 2: Electric Boogaloo"} - -local title = am.group() -local world = am.group() -local layout = hex_layout(vec2(-368, win.bottom)) -local map = hex_rectangular_map(45, 31) -local titlemap = hex_spiral_map(vec2(0), 10) -local titlelayout = hex_layout(vec2(win.right, win.bottom)) +local title +local world +local layout = hex_layout() +local map = hex_hexagonal_map(24) -function show_axes() - xaxis = am.line(vec2(win.left, 0), vec2(win.right, 0)) - yaxis = am.line(vec2(0, win.top), vec2(0, win.bottom)) - world:append(am.group{xaxis, yaxis}:tag("axes")) -end +----- [[ SPRITES ]] ------------------------------------------------------------ +local titlebutton = [[ +KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK +KwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwK +KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK +KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK +KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK +KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK +KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK +KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK +KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK +KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK +KbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK +KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK + ]] function world_init() + world = am.group{} world:action(coroutine.create(function() for hex,_ in pairs(map) do - world:append(am.circle(hex_to_pixel(hex, layout), 11, rrgb(1), 6)) + world:append(am.circle(hex_to_pixel(hex, layout), 12, rrgb(1), 6)) am.wait(am.delay(0.01)) end end)) - + win.scene = world end function init() - local rotatable = am.group(am.rotate(45):tag"rotatable") - local backdrop = am.group{rotatable} - for _,hex in pairs(titlemap) do - local center = hex_to_pixel(hex, titlelayout) - rotatable:append(am.circle(center, 11, rrgb(1), 6)) + local titlemenu = am.group{ + am.translate(0, 150) + ^ {am.scale(6.5) + ^ am.text("WARZONE 2", vec4(0, 0, 0, 1)), + am.scale(6.3, 6.7) + ^ am.text("WARZONE 2")}, + + am.translate(0, 80) + ^ am.text("a tower defense game"), + + am.translate(0, 0) + ^ {am.scale(3) + ^ am.sprite(titlebutton), + am.text("NEW GAME")}, + + am.translate(0, -40) + ^ {am.scale(3) + ^ am.sprite(titlebutton), + am.text("LOAD GAME")}, + + am.translate(0, -80) + ^ {am.scale(3) + ^ am.sprite(titlebutton), + am.text("SETTINGS")}, + + am.translate(0, -120) + ^ {am.scale(3) + ^ am.sprite(titlebutton), + am.text("QUIT")}, + + am.translate(0, -250) + ^ am.text("by nick hayashi") + } + + local backdrop = am.group() + + for hex,_ in pairs(map) do + local center = hex_to_pixel(hex, layout) + backdrop:append(am.circle(center, 12, rhue(1), 6)) end - local line1 = am.text("WARZONE 2") - local line2 = am.text("Electric Boogaloo") - local line3 = am.text("by Nick Hayashi") - local title = am.group{backdrop, - am.translate(0, 150) ^ am.scale(4) ^ line1, - am.translate(0, 100) ^ am.scale(3) ^ line2, - am.translate(0, 60) ^ am.scale(1) ^ line3 - }:action(function() - rotatable"rotatable".angle = (am.frame_time / 5) - end) - win.scene = title + title = am.group{ + am.translate(win.right, win.bottom) + ^ am.scale(3.5, 1.5) + ^ am.rotate(0) + ^ backdrop, + + titlemenu + }:action(function() + title"rotate".angle = am.frame_time / 36 + end) + + win.scene = title end ----- [[ MAIN ]] --------------------------------------------------------------- diff --git a/util.lua b/util.lua index 50a1147..aa08a0c 100644 --- a/util.lua +++ b/util.lua @@ -1,9 +1,21 @@ -function rrgb(a) - local R = math.random(20, 80) / 100 - local G = math.random(20, 80) / 100 - local B = math.random(20, 80) / 100 +function rhue(a) + local R = math.random(35, 75) / 100 + local G = math.random(35, 75) / 100 + local B = math.random(35, 75) / 100 local A = a or math.random() return vec4(R, G, B, A) end + +function rmono() + return vec4(1, 1, 1, math.random()) +end + + +function show_axes() + xaxis = am.line(vec2(win.left, 0), vec2(win.right, 0)) + yaxis = am.line(vec2(0, win.top), vec2(0, win.bottom)) + world:append(am.group{xaxis, yaxis}:tag("axes")) +end +