commit f70ea190a9fa48198ad8a5881495da4eeb6ff609 Author: churchianity Date: Sun Feb 10 21:48:34 2019 -0500 Second major commit diff --git a/Warzone2gdd b/Warzone2gdd new file mode 100644 index 0000000..ce18947 --- /dev/null +++ b/Warzone2gdd @@ -0,0 +1,35 @@ + + +Warzone 2 is a concept for a browser-based, hexagonal grid tower defense game. + +The working title is informal and will be changed. +It comes from a browser flash game called Warzone Tower Defense. + +Javascript, html5 Canvas will be the host. + + Concept: + + In warzone tower defense (the original), the most powerful tower you can +purchase is the wall block. It isn't a proper tower at 1/4 the real-estate - +not to mention the fact it does not have offensive capabilities. The best +strategy revolves around figuring out the optimal defensive structure to erect +with wall blocks. Warzone 2 wants to continue with this strong gameplay theme +of the construction of defensive structures. This differs from the typical +tower defense in that the towers really aren't the primary focus. The focus +is the landscape + defensive structre on and around which you build the towers. + + Supporting this theme is a hexagonal 2D grid - 3D would be too avant-garde. +Having 50% more directional choice for units will in theory make for much more +interesting defensive structures. Along with it is random map generation. + + Hex tiles will have a variety of properties: + + - Height Level [-2 .. 2] + Tiles can be raised or lowered relative to others. This will effect + building, towers, enemy pathing and more. + + - Plot + Tiles can contain natural resources or hazards on top of its natural + texture. + + - diff --git a/hex.lua b/hex.lua new file mode 100644 index 0000000..e0c2031 --- /dev/null +++ b/hex.lua @@ -0,0 +1,117 @@ +--[[ AXIAL/CUBE COORDINATE SYSTEM FOR AMULET/LUA]] +--[[ + + all hexes in functions are assumed to be amulet vectors. + in amulet, vector arithmetic works already with [ + - * / ] + things like equality and distance are implemented here. + + some algorithms use axial coordinates for hexes: vec2(s, t) + others use cube coordinates: vec3(s, t, z) where s + t + z = 0 + this is for simplicity - many algorithms don't care about the + third coordinate, and if they do, the missing coordinate can + be calculated from the other two. + + -- note on orientation: + because of the way amulet draws hexagons, it's much easier to assume + the user wants to use the flat map. rotation after the fact to + achieve other orienations is probably possible, but might have some + aliasing issues. TODO work on this. + + some of the primary resources used to develop this library: + - https://redblobgames.com/grid/hexagons - simply amazing. + - http://amulet.xyz/doc - amulet documentation + - TODO that place that had the inner circle/outer circle ratio?? + + ]] + + +-- GENERALLY USEFUL FUNCTIONS -------------------------------------------------- + +function round(n) + return n % 1 >= 0.5 and math.ceil(n) or math.floor(n) +end + + +-- HEX CONSTANTS --------------------------------------------------------------- + + -- all possible vector directions from a given hex by edge +HEX_DIRECTIONS = {vec2( 1 , 0), + vec2( 1 , -1), + vec2( 0 , -1), + vec2(-1 , 0), + vec2(-1 , 1), + vec2( 0 , 1)} + +-- HEX UTILITY FUNCTIONS ------------------------------------------------------- + +function hex_equals(a, b) + return a.s == a.t and b.s == b.t +end + +function hex_nequals(a, b) + return not hex_equals(a, b) +end + +function hex_length(hex) + return ((math.abs(hex.s) + math.abs(hex.t) + math.abs(-hex.s - hex.t)) / 2) +end + +function hex_distance(a, b) + return hex_length(a - b) +end + +function hex_direction(direction) + return HEX_DIRECTIONS[direction] +end + +function hex_neighbour(hex, direction) + return hex + HEX_DIRECTIONS[direction] +end + +function hex_round(hex) + rs = round(hex.s) + rt = round(hex.t) + rz = round(-hex.s + -hex.t) + + sdelta = math.abs(rs - hex.s) + tdelta = math.abs(rt - hex.t) + zdelta = math.abs(rz + hex.s + hex.t) + + if sdelta > tdelta and sdelta > zdelta then + rs = -rt - rz + elseif tdelta > zdelta then + rt = -rs - rz + else + rz = -rs - rt + end + + return vec2(rs, rt) +end + +-- COORDINATE CONVERSION FUNCTIONS --------------------------------------------- + + -- forward & inverse matrices used for coordinate conversion +local M = mat2(3.0/2.0, 0.0, 3.0^0.5/2.0, 3.0^0.5 ) +local W = mat2(2.0/3.0, 0.0, -1.0/3.0 , 3.0^0.5/3.0) + + -- hex to screen +function hex_to_pixel(hex) + + x = (M[1][1] * hex.s + M[1][2] * hex.t) * map.size + y = (M[2][1] * hex.s + M[2][2] * hex.t) * map.size + + return vec2(x + map.origin.x, y + map.origin.y) +end + + -- screen to hex +function pixel_to_hex(pix) + pix = vec2(pix.x - map.origin.x) / map.size, + (pix.y - map.origin.y) / map.size + + s = W[1][1] * pix.x + W[1][2] * pix.y + t = W[2][1] * pix.x + W[2][2] * pix.y + + return hex_round(vec2(s, t)) +end + +-- MAP FUNCTIONS --------------------------------------------------------------- diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..8cb20c0 --- /dev/null +++ b/main.lua @@ -0,0 +1,32 @@ +--[[ WARZONE 2 - HEXAGONAL GRID RESOURCE BASED TOWER DEFENSE GAME]] +--[[ + + ]] + +require "hex" + +-- ENTRY POINT ----------------------------------------------------------------- +win = am.window { + title = "Warzone 2: Electric Boogaloo", + + -- BASE RESOLUTION = 3/4 * WXGA Standard 16:10 Aspect Ratio + width = 1280 * 3 / 4, + height = 800 * 3 / 4, + + clear_color = vec4(0, 0, 0, 0) +} + +-- GROUPS +local grid = am.group() + +--[[ +xaxis = am.line(vec2(-win.width / 2, 0) , vec2(win.width / 2, 0)) +yaxis = am.line(vec2(0, -win.height / 2), vec2(0, win.height / 2)) + +grid:append(xaxis) +grid:append(yaxis) +--]] + +win.scene = grid + +