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.

107 lines
3.5 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
  1. ----- [[ WARZONE 2 - HEXAGONAL GRID RESOURCE BASED TOWER DEFENSE GAME]] -------
  2. --[[ author@churchianity.ca
  3. ]]
  4. require "hex"
  5. ----- [[ DUMMY FUNCTIONS ]] ----------------------------------------------------
  6. function show_hex_coords()
  7. grid:action(function()
  8. grid:remove("text")
  9. mouse_position = vec2(win:mouse_position().x, win:mouse_position().y)
  10. if mouse_position.x < 268 then
  11. hex = map.retrieve(mouse_position)
  12. grid:append(am.translate(win.left + 30, win.top - 10)
  13. ^ am.text(string.format("%d,%d", hex.s, hex.t)))
  14. end
  15. end)
  16. end
  17. function rcolor()
  18. return vec4(math.random(20, 80) / 100,
  19. math.random(20, 80) / 100,
  20. math.random(20, 80) / 100,
  21. 1)
  22. end
  23. SPRITES = {"BoulderHills1.png", "BoulderHills2.png", "BoulderHills2.png",
  24. "Brambles1.png", "Brambles2.png", "Brambles3.png", "Brambles4.png",
  25. "BrownHills1.png", "BrownHills2.png", "BrownHills3.png",
  26. "Grass1.png", "Grass2.png", "Grass3.png", "Grass4.png", "Grass5.png", "Hills1.png", "Hills2.png", "Hills3.png", "Hills4.png", "Hills5.png",
  27. "HillsGreen1.png", "HillsGreen2.png", "HillsGreen3.png",
  28. "LightGrass1.png", "LightGrass2.png", "LightGrass3.png",
  29. "LowHills1.png", "LowHills2.png", "LowHills3.png", "LowHills4.png",
  30. "Mountains1.png", "Mountains2.png", "Mountains3.png",
  31. "Mud1.png", "Mud2.png", "Mud3.png", "Mud4.png", "Mud5.png",
  32. "Orchards1.png", "Orchards2.png", "Orchards3.png", "Orchards4.png",
  33. "PineForest1.png", "PineForest2.png", "PineForest3.png",
  34. "Woods1.png", "Woods2.png", "Woods3.png", "Woods4.png"}
  35. function rsprite()
  36. return string.format("res/%s", SPRITES[math.random(#SPRITES)])
  37. end
  38. ----- [[ BLAH BLAH LBAH ]] -----------------------------------------------
  39. win = am.window {
  40. title = "Warzone 2: Electric Boogaloo",
  41. -- BASE RESOLUTION = 3/4 * WXGA Standard 16:10 Aspect Ratio
  42. width = 1280 * 3 / 4, -- 960
  43. height = 800 * 3 / 4} -- 600
  44. ----- [[ MAP RENDERING ]] ------------------------------------------------
  45. function grid_init()
  46. grid = am.group()
  47. map = rectmap_init(layout_init(vec2(win.left, win.bottom)), 45, 31)
  48. grid:action(function()
  49. for hex,pix in pairs(map) do
  50. grid:append(am.circle(pix, map.layout.size.x, rcolor(), 6))
  51. end
  52. return true
  53. end)
  54. grid:append(am.translate(350, 200)
  55. ^ am.scale(2)
  56. ^ am.sprite("2.png"))
  57. show_hex_coords()
  58. return grid
  59. end
  60. function toolbar_init()
  61. local toolbar = am.group()
  62. local toolbar_bg = vec4(0.4, 0.6, 0.8, 1)
  63. toolbar:append(am.rect(268, win.top, win.right, win.bottom, toolbar_bg))
  64. toolbar:append(am.particles2d({source_pos=vec2(win.width/2-268, win.top),
  65. source_pos_var=vec2(0, 600),
  66. angle=math.pi/4,
  67. start_color=vec4(0.9),
  68. gravity=vec2(100),
  69. start_color_var=rcolor(),
  70. start_size=3}))
  71. return toolbar
  72. end
  73. function game_init()
  74. return am.group{grid_init(), toolbar_init()}
  75. end
  76. ----- [[ MAIN ]] -----------------------------------------------------------
  77. local map = {}
  78. win.scene = game_init()
  79. show_hex_coords()