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.

121 lines
4.6 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
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. ----- WARZONE 2 - HEXAGONAL GRID RESOURCE BASED TOWER DEFENSE GAME -------------
  2. -- author@churchianity.ca
  3. require"hex"
  4. require"util"
  5. ------ GLOBALS -----------------------------------------------------------------
  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. title = "Warzone 2: Electric Boogaloo",
  11. resizable = false
  12. }
  13. local layout = layout(vec2(-268, win.top - 10))
  14. local map = rectangular_map(45, 31)
  15. local world = am.group{}:tag"world"
  16. -- modified ethan shoonover solarized colortheme
  17. am.ascii_color_map = {
  18. E = vec4( 22/255, 22/255, 29/255, 1), -- eigengrau
  19. K = vec4( 0, 43/255, 54/255, 1), -- dark navy
  20. k = vec4( 7/255, 54/255, 66/255, 1), -- navy
  21. L = vec4( 88/255, 110/255, 117/255, 1), -- gray1
  22. l = vec4(101/255, 123/255, 131/255, 1), -- gray2
  23. s = vec4(131/255, 148/255, 150/255, 1), -- gray3
  24. S = vec4(147/255, 161/255, 161/255, 1), -- gray4
  25. w = vec4(238/255, 232/255, 213/255, 1), -- bone
  26. W = vec4(253/255, 246/255, 227/255, 1), -- white
  27. y = vec4(181/255, 137/255, 0, 1), -- yellow
  28. o = vec4(203/255, 75/255, 22/255, 1), -- orange
  29. r = vec4(220/255, 50/255, 47/255, 1), -- red
  30. m = vec4(211/255, 54/255, 130/255, 1), -- magenta
  31. v = vec4(108/255, 113/255, 196/255, 1), -- violet
  32. b = vec4( 38/255, 139/255, 210/255, 1), -- blue
  33. c = vec4( 42/255, 161/255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KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
  50. ]]
  51. ----- FUNCTIONS ----------------------------------------------------------
  52. function show_axes()
  53. local xaxis = am.line(vec2(win.left, 0), vec2(win.right, 0))
  54. local yaxis = am.line(vec2(0, win.top), vec2(0, win.bottom))
  55. win.scene:append(am.translate(0, 0) ^ am.group{xaxis, yaxis}:tag"axes")
  56. end
  57. function show_hex_coords()
  58. win.scene:action(function()
  59. win.scene:remove("coords")
  60. win.scene:remove("select")
  61. local hex = pixel_to_cube(win:mouse_position(), layout)
  62. local mouse = cube_to_offset(hex)
  63. if mouse.x > 0 and mouse.x < map.width and
  64. mouse.y > 0 and mouse.y < map.height then
  65. local coords = am.group{
  66. am.translate(win.right - 25, win.top - 10)
  67. ^ am.text(string.format("%d,%d", mouse.x, mouse.y)):tag"coords"}
  68. win.scene:append(coords)
  69. local mask = vec4(1, 1, 1, 0.2)
  70. local pix = cube_to_pixel(hex, layout)
  71. world:append(am.circle(pix, layout.size.x, mask, 6):tag"select")
  72. end
  73. end)
  74. end
  75. function init()
  76. world:action(coroutine.create(function()
  77. local gui = am.rect(win.left, win.top, -268, win.bottom):tag"gui"
  78. world:append(gui)
  79. for hex,_ in pairs(map) do
  80. local pix = cube_to_pixel(hex, layout)
  81. local off = cube_to_offset(hex)
  82. local tag = tostring(hex)
  83. local color
  84. if off.x == 0 or off.x == map.width or
  85. off.y == 0 or off.y == map.height then
  86. color = rhue(0.3)
  87. else
  88. color = rhue(1 - math.max(((off.x-23)/30)^2, ((off.y-16)/20)^2))
  89. end
  90. world"gui".color = vec4(0, 43/255, 54/255, am.frame_time / 20)
  91. world:prepend(am.circle(pix, layout.size.x, color, 6):tag(tag))
  92. am.wait(am.delay(0.01))
  93. end
  94. end))
  95. win.scene = world
  96. end
  97. ----- [[ MAIN ]] ---------------------------------------------------------------
  98. init()
  99. show_hex_coords()