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.

57 lines
1.7 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
  1. ----- [[ WARZONE 2 - HEXAGONAL GRID RESOURCE BASED TOWER DEFENSE GAME]] -------
  2. --[[ author@churchianity.ca
  3. ]]
  4. require "hex"
  5. ----- [[ DUMMY FUNCTIONS ]] ------------------------------------------------------
  6. function draw_axes()
  7. xaxis = am.line(vec2(-win.width / 2, 0) , vec2(win.width / 2, 0))
  8. yaxis = am.line(vec2(0, -win.height / 2), vec2(0, win.height / 2))
  9. title_scene:append(xaxis)
  10. title_scene:append(yaxis)
  11. end
  12. function rcolor()
  13. return vec4(math.random(20, 80) / 100)
  14. end
  15. ----- [[ BLAH BLAH LBAH ]] -----------------------------------------------
  16. local win = am.window {
  17. title = "Warzone 2: Electric Boogaloo",
  18. -- BASE RESOLUTION = 3/4 * WXGA Standard 16:10 Aspect Ratio
  19. width = 1280 * 3 / 4, -- 960
  20. height = 800 * 3 / 4} -- 600
  21. local layout = layout_init({win.left, win.bottom})
  22. ----- [[ MAP RENDERING ]] ------------------------------------------------
  23. function render_map(layout)
  24. map = map_rectangular_init(layout, 45, 31)
  25. hexagons = am.group()
  26. for _,v in pairs(map) do
  27. hexagons:append(am.circle(vec2(unpack(v)), layout.size[1], rcolor(), 6))
  28. end
  29. return hexagons
  30. end
  31. ----- [[ MAIN ]] -----------------------------------------------------------
  32. local game_scene = render_map(layout)
  33. local test_scene = am.group()
  34. win.scene = am.group{test_scene, game_scene}
  35. test_scene:action(function()
  36. hexpos = pixel_to_hex(win:mouse_position().x, win:mouse_position().y, layout)
  37. x, y = unpack(map_retrieve(map, hexpos))
  38. test_scene:remove_all("text")
  39. test_scene:append(am.translate(x, y) ^ am.text(string.format("%d, %d", hexpos[1], hexpos[2])))
  40. end)