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.

110 lines
3.3 KiB

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. clear_color = vec4(22/255, 22/255, 29/255, 1)
  13. }
  14. local title
  15. local world
  16. local layout = hex_layout()
  17. local map = hex_hexagonal_map(24)
  18. ----- [[ SPRITES ]] ------------------------------------------------------------
  19. local titlebutton = [[
  20. KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
  21. KwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwK
  22. KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
  23. KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
  24. KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
  25. KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
  26. KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
  27. KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
  28. KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
  29. KwbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
  30. KbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbK
  31. KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
  32. ]]
  33. function world_init()
  34. world = am.group{}
  35. world:action(coroutine.create(function()
  36. for hex,_ in pairs(map) do
  37. world:append(am.circle(hex_to_pixel(hex, layout), 12, rrgb(1), 6))
  38. am.wait(am.delay(0.01))
  39. end
  40. end))
  41. win.scene = world
  42. end
  43. function init()
  44. local titlemenu = am.group{
  45. am.translate(0, 150)
  46. ^ {am.scale(6.5)
  47. ^ am.text("WARZONE 2", vec4(0, 0, 0, 1)),
  48. am.scale(6.3, 6.7)
  49. ^ am.text("WARZONE 2")},
  50. am.translate(0, 80)
  51. ^ am.text("a tower defense game"),
  52. am.translate(0, 0)
  53. ^ {am.scale(3)
  54. ^ am.sprite(titlebutton),
  55. am.text("NEW GAME")},
  56. am.translate(0, -40)
  57. ^ {am.scale(3)
  58. ^ am.sprite(titlebutton),
  59. am.text("LOAD GAME")},
  60. am.translate(0, -80)
  61. ^ {am.scale(3)
  62. ^ am.sprite(titlebutton),
  63. am.text("SETTINGS")},
  64. am.translate(0, -120)
  65. ^ {am.scale(3)
  66. ^ am.sprite(titlebutton),
  67. am.text("QUIT")},
  68. am.translate(0, -250)
  69. ^ am.text("by nick hayashi")
  70. }
  71. local backdrop = am.group()
  72. for hex,_ in pairs(map) do
  73. local center = hex_to_pixel(hex, layout)
  74. backdrop:append(am.circle(center, 12, rhue(1), 6))
  75. end
  76. title = am.group{
  77. am.translate(win.right, win.bottom)
  78. ^ am.scale(3.5, 1.5)
  79. ^ am.rotate(0)
  80. ^ backdrop,
  81. titlemenu
  82. }:action(function()
  83. title"rotate".angle = am.frame_time / 36
  84. end)
  85. win.scene = title
  86. end
  87. ----- [[ MAIN ]] ---------------------------------------------------------------
  88. init()