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.

105 lines
4.0 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
  1. ----- [[ WARZONE 2 - HEXAGONAL GRID RESOURCE BASED TOWER DEFENSE GAME]] --------
  2. --[[ author@churchianity.ca
  3. ]]
  4. require"hex"
  5. require"util"
  6. ------ [[ GLOBALS ]] -----------------------------------------------------------
  7. local win = am.window{
  8. -- BASE RESOLUTION = 3/4 * WXGA Standard 16:10
  9. width = 1280 * 3 / 4, -- 960px
  10. height = 800 * 3 / 4, -- 600px
  11. title = "Warzone 2: Electric Boogaloo",
  12. resizable = false
  13. }
  14. local layout = layout(vec2(-268, win.top - 10))
  15. local map = rectangular_map(45, 31)
  16. local world = am.group{}:tag"world"
  17. ----- [[ SPRITES ]] ------------------------------------------------------------
  18. -- modified ethan shoonover solarized colortheme
  19. am.ascii_color_map = {
  20. E = vec4( 22/255, 22/255, 29/255, 1), -- eigengrau
  21. K = vec4( 0, 43/255, 54/255, 1), -- dark navy
  22. k = vec4( 7/255, 54/255, 66/255, 1), -- navy
  23. L = vec4( 88/255, 110/255, 117/255, 1), -- gray1
  24. l = vec4(101/255, 123/255, 131/255, 1), -- gray2
  25. s = vec4(131/255, 148/255, 150/255, 1), -- gray3
  26. S = vec4(147/255, 161/255, 161/255, 1), -- gray4
  27. w = vec4(238/255, 232/255, 213/255, 1), -- bone
  28. W = vec4(253/255, 246/255, 227/255, 1), -- white
  29. y = vec4(181/255, 137/255, 0, 1), -- yellow
  30. o = vec4(203/255, 75/255, 22/255, 1), -- orange
  31. r = vec4(220/255, 50/255, 47/255, 1), -- red
  32. m = vec4(211/255, 54/255, 130/255, 1), -- magenta
  33. v = vec4(108/255, 113/255, 196/255, 1), -- violet
  34. b = vec4( 38/255, 139/255, 210/255, 1), -- blue
  35. c = vec4( 42/255, 161/255, 152/255, 1), -- cyan
  36. g = vec4(133/255, 153/255, 0, 1) -- green
  37. }
  38. local titlebutton =
  39. [[
  40. KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
  41. KwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwK
  42. KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
  43. KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
  44. KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
  45. KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
  46. KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
  47. KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
  48. KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
  49. KwkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
  50. KkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkK
  51. KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
  52. ]]
  53. ----- FUNCTIONS ----------------------------------------------------------
  54. function show_axes()
  55. local xaxis = am.line(vec2(win.left, 0), vec2(win.right, 0))
  56. local yaxis = am.line(vec2(0, win.top), vec2(0, win.bottom))
  57. win.scene:append(am.translate(0, 0) ^ am.group{xaxis, yaxis}:tag"axes")
  58. end
  59. function show_hex_coords()
  60. win.scene:action(function()
  61. win.scene:remove("coords")
  62. local mouse = cube_to_offset(pixel_to_cube(win:mouse_position(), layout))
  63. if mouse.x > 0 and mouse.x < 45 and mouse.y > 0 and mouse.y < 31 then
  64. local coords = am.group{
  65. am.translate(win.right - 25, win.top - 10)
  66. ^ am.text(string.format("%d,%d", mouse.x, mouse.y)):tag"coords"}
  67. win.scene:append(coords)
  68. end
  69. end)
  70. end
  71. function init()
  72. for hex,_ in pairs(map) do
  73. local pix = cube_to_pixel(hex, layout)
  74. local helper = cube_to_offset(hex)
  75. local r = math.random()
  76. local g = math.random()
  77. local b = math.random()
  78. local a = 1 - ((helper.x + 23)^2)/500 + ((helper.y + 16)^2)/500
  79. local color = vec4(r, g, b, a)
  80. local tag = tostring(hex.x, hex.y)
  81. world:append(am.circle(pix, layout.size.x, color, 6):tag(tag))
  82. end
  83. win.scene = world
  84. end
  85. ----- [[ MAIN ]] ---------------------------------------------------------------
  86. init()
  87. show_hex_coords()