Browse Source

added a readme.

master
churchianity 6 years ago
parent
commit
b4fedd5c5c
  1. 164
      '
  2. 67
      ;
  3. 61
      README.md
  4. 126
      hex.lua
  5. 141
      main.lua
  6. 8
      util.lua

164
'

@ -0,0 +1,164 @@
--[[ 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.
consequently, I have not implemented stretching. all hexagons are
assumed to be regular. you could implement this yourself by making
layout.size a vec2(sizex, sizey), but you would have to play with
transforms in the amulet library if you wanted to use amulet.
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 CONSTANTS -------------------------------------------------
-- GENERALLY USEFUL FUNCTIONS --------------------------------------------------
function round(n)
return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
end
function draw_axes(window, node)
xaxis = am.line(vec2(-window.width / 2, 0) , vec2(window.width / 2, 0))
yaxis = am.line(vec2(0, -window.height / 2), vec2(0, window.height / 2))
node:append(xaxis)
node:append(yaxis)
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, origin)
x = (M[1][1] * hex.s + M[1][2] * hex.t) * SIZE
y = (M[2][1] * hex.s + M[2][2] * hex.t) * SIZE
return vec2(x + origin.x, y + origin.y)
end
-- screen to hex
function pixel_to_hex(pix, origin)
pix = vec2(pix.x - origin.x) / SIZE,
(pix.y - origin.y) / 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 ---------------------------------------------------------------
function hexagonal_map(radius, origin)
for s = -radius, radius do
t1 = math.max(-radius, -s - radius)
t2 = math.min(radius, -s + radius)
for t = t1, t2 do
color = vec4(math.random(20, 80) / 100,
math.random(20, 80) / 100,
math.random(20, 80) / 100,
1)
map:append(am.circle(hex_to_pixel(vec2(s, t)), 24, color, 6))
end
end
end
function rectangular_map(width, height, origin)
for s = 0, height do
soffset = math.floor(s / 2)
for t = -soffset, width - soffset do
center = hex_to_pixel(vec2(s, t))
end
end
end
--]]

67
;

@ -0,0 +1,67 @@
----- [[ WARZONE 2 - HEXAGONAL GRID RESOURCE BASED TOWER DEFENSE GAME]] --------
--[[ author@churchianity.ca
]]
require "hex"
require "util"
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"}
local title = am.group()
local world = am.group()
local layout = hex_layout(vec2(-368, win.bottom))
local map = hex_rectangular_map(45, 31)
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
function world_init()
world:action(coroutine.create(function()
for hex,_ in pairs(map) do
world:append(am.circle(hex_to_pixel(hex, layout), 11, rrgb(1), 6))
am.wait(am.delay(0.01))
end
end))
end
function init()
titlemap = am.group()
for hex,_ in pairs(map) do
titlemap:append(am.rotate(45):tag("titlemap")
^ am.scale(3, 2)
^ am.circle(hex_to_pixel(hex, layout), 11, rrgb(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{titlemap,
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()
while true do
titlemap"titlemap".angle = am.frame_time * 4
end
end)
win.scene = title
end
----- [[ MAIN ]] ---------------------------------------------------------------
init()

61
README.md

@ -0,0 +1,61 @@
----- INTRODUCTION [1.1] ---------------------------------------------------
--[[ author@churchianity.ca
this is a library for using hexagonal grids in amulet/lua.
it is extremely incomplete. the following list of features is
either implemented shoddily, or not at all.
if you want an actual good resource, go to [1.9].
----- COORDINATE SYSTEMS [1.2] ----------------------------------------------
* as much coordinate manipulation as possible is done internally.
depending on the task, uses either Axial, Cube, or Doubled coordinates.
* three different ways of returning and sending coordinates:
1) amulet vectors
2) lua tables
3) individual coordinate numbers
so you can use what your graphics library likes best!
----- MAPS & MAP STORAGE [1.3] -------------------------------------------------
some map shapes: parallelogram, rectangular, hexagonal, triangular. (and more)
* storage system based on map shape - see chart:
________________________________________________________________________
| SHAPE : MAP STORAGE |
|------------------------------------------------------------------------|
| parallelogram : unordered, hash-like OR ordered, array-like |
| rectangular : unordered, hash-like OR ordered, array-like |
| hexagonal : unordered, hash-like OR ordered, array-like |
| triangular : unordered, hash-like OR ordered, array-like |
| ring : ordered, array-like |
| spiral : ordered, array-like** |
| arbitrary : unordered, hash-like |
|________________________________________________________________________|
** note that a spiral map is just a hexagonal one with a particular order.
----- CONVENTIONS AND TERMINOLOGY [1.8] -----------------------------------------
because so many different kinds of coordinate pairs, trios
----- RESOURCES USED TO DEVELOP THIS LIBRARY, AND FOR WHICH I AM GRATEFUL [1.9] -
* https://catlikecoding.com/unity/tutorials/hex-map/
-> unity tutorial for hexagon grids with some useful generalized math.
* https://youtube.com/watch?v=fNk_zzaMoSs&list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab
-> amazing series on linear algebra by 3Blue1Brown
* https://redblobgames.com/grid/hexagons
-> now THE resource on hexagonal grids on the internet.
* http://amulet.xyz/doc
-> amulet documentation.
]]

126
hex.lua

@ -1,16 +1,3 @@
----- [[ AXIAL/CUBE COORDINATE HEXAGON LIBRARY FOR AMULET/LUA]] ----------------
--[[ author@churchianity.ca
-- INTRODUCTION
this is a hexagonal grid library for amulet/lua.
it uses axial coordinates or cube/hex coordinates when necessary.
by amulet convention, hexes are either vec2(s, t) or vec3(s, t, z)
but nearly always the former.
-- RESOURCES USED TO DEVELOP THIS LIBRARY, AND FOR WHICH I AM GRATEFUL
https://catlikecoding.com/unity/tutorials/hex-map/
https://redblobgames.com/grid/hexagons
http://amulet.xyz/doc
]]
----- [[ GENERALLY USEFUL FUNCTIONS ]] -----------------------------------------
@ -22,7 +9,7 @@ end
----- [[ HEX CONSTANTS & UTILITY FUNCTIONS ]] ----------------------------------
-- all possible vector directions from a given hex by edge
local HEX_DIRECTIONS = {vec2( 1 , 0),
local CUBE_DIRECTIONS = {vec2( 1 , 0),
vec2( 1 , -1),
vec2( 0 , -1),
vec2(-1 , 0),
@ -30,43 +17,45 @@ local HEX_DIRECTIONS = {vec2( 1 , 0),
vec2( 0 , 1)}
-- return hex vector direction via integer index |direction|.
function hex_direction(direction)
return HEX_DIRECTIONS[(6 + (direction % 6)) % 6 + 1]
function cube_direction(direction)
return CUBE_DIRECTIONS[(6 + (direction % 6)) % 6 + 1]
end
-- return hexagon adjacent to |hex| in integer index |direction|.
function hex_neighbour(hex, direction)
function cube_neighbour(hex, direction)
return hex + HEX_DIRECTIONS[(6 + (direction % 6)) % 6 + 1]
end
-- TODO
function hex_rotate_left(hex)
-- TODO rotations are different depending on the coordinate system you use.
-- implement this for cube/axial, and doubled.
function cube_rotate_left(hex)
end
function hex_rotate_right(hex)
function cube_rotate_right(hex)
end
-- rounds hexes. without this, pixel_to_hex returns fractional coordinates.
function hex_round(s, t)
local rs = round(s)
local rt = round(t)
local rz = round(-s - t)
-- rounds a float coordinate trio |x, y, z| to its nearest integer coordinate trio.
-- TODO make work with a table {x, y, z} and vec3(x, y, z)
function cube_round(x, y, z)
local rx = round(x)
local ry = round(y)
local rz = round(z)
local sdelta = math.abs(rs - s)
local tdelta = math.abs(rt - t)
local zdelta = math.abs(rz - (-s - t))
local xdelta = math.abs(rx - x)
local ydelta = math.abs(ry - y)
local zdelta = math.abs(rz - z)
if sdelta > tdelta and sdelta > zdelta then
rs = -rt - rz
elseif tdelta > zdelta then
rt = -rs - rz
if xdelta > ydelta and xdelta > zdelta then
rx = -ry - rz
elseif ydelta > zdelta then
rx = -ry - rz
else
rz = -rs - rt
rz = -rx - ry
end
return vec2(rs, rt)
return vec3(rx, ry, rz)
end
----- [[ LAYOUT, ORIENTATION & COORDINATE CONVERSION ]] -----------------------
@ -81,26 +70,25 @@ local POINTY = {M = mat2(3.0^0.5, 3.0^0.5/2.0, 0.0, 3.0/2.0),
W = mat2(3.0^0.5/3.0, -1.0/3.0, 0.0, 2.0/3.0),
start_angle = 0.5}
-- TODO encapsulate hex_to_pixel and pixel_to_hex in layout table.
-- stores layout information that does not pertain to map shape
function hex_layout(origin, size, orientation)
-- stores layout: information that does not pertain to map shape
function layout(origin, size, orientation)
return {origin = origin or vec2(0),
size = size or vec2(12),
size = size or vec2(11),
orientation = orientation or FLAT}
end
-- hex to screen
function hex_to_pixel(hex, layout)
function cube_to_pixel(cube, layout)
local M = layout.orientation.M
local x = (M[1][1] * hex.s + M[1][2] * hex.t) * layout.size.x
local y = (M[2][1] * hex.s + M[2][2] * hex.t) * layout.size.y
local x = (M[1][1] * cube.x + M[1][2] * cube.y) * layout.size.x
local y = (M[2][1] * cube.x + M[2][2] * cube.y) * layout.size.y
return vec2(x + layout.origin.x, y + layout.origin.y)
end
-- screen to hex
function pixel_to_hex(pix, layout)
function pixel_to_cube(pix, layout)
local W = layout.orientation.W
local pix = (pix - layout.origin) / layout.size
@ -108,28 +96,47 @@ function pixel_to_hex(pix, layout)
local s = W[1][1] * pix.x + W[1][2] * pix.y
local t = W[2][1] * pix.x + W[2][2] * pix.y
return hex_round(s, t)
return cube_round(s, t, -s - t)
end
-- TODO test
function hex_corner_offset(layout, corner)
function hex_corner_offset(corner, layout)
local angle = 2.0 * math.pi * layout.orientation.start_angle + corner / 6
return vec2(layout.size.x * math.cos(angle), layout.size.y * math.sin(angle))
end
-- TODO make do stuff
function hex_corners(layout, hex)
function hex_corners(hex, layout)
local corners = {}
end
function cube_to_offset(cube)
end
function offset_to_cube(off)
end
function cube_to_doubled(cube)
return vec2(cube.x, 2 * (-cube.x - cube.y) + cube.x)
end
function doubled_to_cube(dbl)
return vec2(dbl.x, (dbl.y - dbl.x) / 2)
end
----- [[ MAP STORAGE & RETRIEVAL ]] --------------------------------------------
--[[
TODO make all functions work regardless of layout. as it stands, they kind
of do, just not always nicely.
]]
-- TODO make all functions work regardless of layout.
-- returns ordered ring-shaped map of |radius| from |center|.
function hex_ring_map(center, radius)
function ring_map(center, radius)
local map = {}
local mt = {__index={center=center, radius=radius}}
setmetatable(map, mt)
local walk = center + HEX_DIRECTIONS[6] * radius
for i = 1, 6 do
@ -141,9 +148,15 @@ function hex_ring_map(center, radius)
return map
end
-- returns ordered hexagonal map of |radius| rings from |center|.
function hex_spiral_map(center, radius)
--[[ returns ordered hexagonal map of |radius| rings from |center|.
the only difference between hex_spiral_map and hex_hexagonal_map is that
hex_spiral_map is ordered, in a spiral path from the |center|.
]]
function spiral_map(center, radius)
local map = {center}
local mt = {__index={center=center, radius=radius}}
setmetatable(map, mt)
for i = 1, radius do
table.append(map, hex_ring_map(center, i))
@ -152,7 +165,7 @@ function hex_spiral_map(center, radius)
end
-- returns unordered parallelogram-shaped map of |width| and |height|.
function hex_parallelogram_map(width, height)
function parallelogram_map(width, height)
local map = {}
local mt = {__index={width=width, height=height}}
@ -167,7 +180,7 @@ function hex_parallelogram_map(width, height)
end
-- returns unordered triangular map of |size|.
function hex_triangular_map(size)
function triangular_map(size)
local map = {}
local mt = {__index={size=size}}
@ -182,7 +195,7 @@ function hex_triangular_map(size)
end
-- returns unordered hexagonal map of |radius|.
function hex_hexagonal_map(radius)
function hexagonal_map(radius)
local map = {}
local mt = {__index={radius=radius}}
@ -200,7 +213,7 @@ function hex_hexagonal_map(radius)
end
-- returns unordered rectangular map of |width| and |height|.
function hex_rectangular_map(width, height)
function rectangular_map(width, height)
local map = {}
local mt = {__index={width=width, height=height}}
@ -214,3 +227,6 @@ function hex_rectangular_map(width, height)
return map
end
----- [[ TESTS ]] --------------------------------------------------------------

141
main.lua

@ -2,8 +2,8 @@
--[[ author@churchianity.ca
]]
require "hex"
require "util"
require"hex"
require"util"
------ [[ GLOBALS ]] -----------------------------------------------------------
@ -12,99 +12,86 @@ local win = am.window{
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)
resizable = false
}
local title
local world
local layout = hex_layout()
local map = hex_hexagonal_map(24)
local layout = layout(vec2(-268, win.bottom))
local map = rectangular_map(45, 31)
local world = am.group{}:tag"world"
----- [[ SPRITES ]] ------------------------------------------------------------
local titlebutton = [[
-- modified ethan shoonover solarized colortheme
am.ascii_color_map = {
E = vec4( 22/255, 22/255, 29/255, 1), -- eigengrau
K = vec4( 0, 43/255, 54/255, 1), -- dark navy
k = vec4( 7/255, 54/255, 66/255, 1), -- navy
L = vec4( 88/255, 110/255, 117/255, 1), -- gray1
l = vec4(101/255, 123/255, 131/255, 1), -- gray2
s = vec4(131/255, 148/255, 150/255, 1), -- gray3
S = vec4(147/255, 161/255, 161/255, 1), -- gray4
w = vec4(238/255, 232/255, 213/255, 1), -- bone
W = vec4(253/255, 246/255, 227/255, 1), -- white
y = vec4(181/255, 137/255, 0, 1), -- yellow
o = vec4(203/255, 75/255, 22/255, 1), -- orange
r = vec4(220/255, 50/255, 47/255, 1), -- red
m = vec4(211/255, 54/255, 130/255, 1), -- magenta
v = vec4(108/255, 113/255, 196/255, 1), -- violet
b = vec4( 38/255, 139/255, 210/255, 1), -- blue
c = vec4( 42/255, 161/255, 152/255, 1), -- cyan
g = vec4(133/255, 153/255, 0, 1) -- green
}
local titlebutton =
[[
KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
KwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwK
KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
KbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
KkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
]]
]]
----- [[ FUNCTIONS ]] ----------------------------------------------------------
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), 12, rrgb(1), 6))
am.wait(am.delay(0.01))
end
end))
win.scene = world
function show_axes()
local xaxis = am.line(vec2(win.left, 0), vec2(win.right, 0))
local yaxis = am.line(vec2(0, win.top), vec2(0, win.bottom))
win.scene:append(am.translate(0, 0) ^ am.group{xaxis, yaxis}:tag"axes")
end
function init()
function show_hex_coords()
win.scene:action(function()
win.scene:remove("coords")
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 mouse = axial_to_doubled(pixel_to_hex(win:mouse_position(), layout))
local backdrop = am.group()
if mouse.x > 0 and mouse.x < 45 and mouse.y < 0 and mouse.y > -63 then
local coords = am.group{
am.translate(win.left + 30, win.top - 10)
^ am.text(string.format("%d,%d", mouse.x, mouse.y)):tag"coords"}
win.scene:append(coords)
end
end)
end
function init()
for hex,_ in pairs(map) do
local center = hex_to_pixel(hex, layout)
backdrop:append(am.circle(center, 12, rhue(1), 6))
local pix = hex_to_pixel(hex, layout)
world:append(am.circle(pix, 11, rhue(1), 6))
end
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
win.scene = world
end
----- [[ MAIN ]] ---------------------------------------------------------------
init()
show_hex_coords()

8
util.lua

@ -11,11 +11,3 @@ 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
Loading…
Cancel
Save