hexyz is tower defense game, and a lua library for dealing with hexagonal grids
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.8 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. require"hex"
  2. require"util"
  3. --[[============================================================================
  4. ----- GLOBALS -----
  5. ==============================================================================]]
  6. local win = am.window{
  7. -- base resolution = 3/4 * WXGA standard 16:10
  8. width = 1280 * 3 / 4, -- 960px
  9. height = 800 * 3 / 4, -- 600px
  10. clear_color = vec4(0.01, 34/255, 45/255, 0),
  11. title = "Warzone 2: Electric Boogaloo",
  12. resizable = false,
  13. }
  14. local layout = layout(vec2(-268, win.top - 10))
  15. local map
  16. local world = am.group{}:tag"world"
  17. --[[============================================================================
  18. ----- FUNCTIONS -----
  19. ==============================================================================]]
  20. function show_hex_coords()
  21. world:action(function()
  22. world:remove("coords")
  23. world:remove("select")
  24. local hex = pixel_to_cube(win:mouse_position(), layout)
  25. local mouse = cube_to_offset(hex)
  26. if mouse.x > 0 and mouse.x < map.width and
  27. mouse.y > 0 and mouse.y < map.height then
  28. local coords = am.group{
  29. am.translate(win.right - 25, win.top - 10)
  30. ^ am.text(string.format("%d,%d", mouse.x, mouse.y)):tag"coords"}
  31. world:append(coords)
  32. local mask = vec4(1, 1, 1, 0.2)
  33. local pix = cube_to_pixel(hex, layout)
  34. world:append(am.circle(pix, layout.size.x, mask, 6):tag"select")
  35. end
  36. end)
  37. end
  38. function world_init()
  39. world:action(coroutine.create(function()
  40. -- init guiblock
  41. local bg = am.rect(win.left, win.top, -268, win.bottom):tag"bg"
  42. world:append(bg)
  43. -- init map
  44. map = rectangular_map(45, 31)
  45. for hex,elevation in pairs(map) do
  46. local pix = cube_to_pixel(hex, layout)
  47. local off = cube_to_offset(hex)
  48. local tag = tostring(hex)
  49. local color
  50. local mask
  51. -- testing noise with color
  52. color = vec4(1, 1, 1, (elevation + 1) / 2)
  53. -- determine cell shading mask based on map position
  54. --mask = vec4(0, 0, 0, math.max(((off.x-23)/30)^2, ((off.y-16)/20)^2))
  55. --color = color - mask
  56. world"bg".color = vec4(0, 43/255, 54/255, am.frame_time)
  57. world:prepend(am.circle(pix, layout.size.x, color, 6):tag(tag))
  58. am.wait(am.delay(0.01))
  59. end
  60. show_hex_coords()
  61. end))
  62. win.scene = world
  63. end
  64. --[[============================================================================
  65. ----- MAIN -----
  66. ==============================================================================]]
  67. world_init()