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.

68 lines
2.0 KiB

  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. function show_hex_coords()
  16. win.scene:action(function()
  17. x, y = unpack(pixel_to_hex(win:mouse_position().x, win:mouse_position().y, layout))
  18. test_scene = (
  19. am.translate(vec2(unpack(hex_to_pixel(x, y, layout))))
  20. ^ am.text(string.format("%d, %d", x, y)))
  21. end)
  22. end
  23. local win = am.window {
  24. title = "Warzone 2: Electric Boogaloo",
  25. -- BASE RESOLUTION = 3/4 * WXGA Standard 16:10 Aspect Ratio
  26. width = 1280 * 3 / 4, -- 960
  27. height = 800 * 3 / 4} -- 600
  28. local layout = layout({11, 11},
  29. FLAT_ORIENTATION,
  30. vec2(win.left, win.bottom),
  31. 45, 31)
  32. ----- [[ MAP RENDERING ]] ------------------------------------------------
  33. function render_map(layout)
  34. coords = rect_map_store(layout)
  35. map = am.group()
  36. for _,v in pairs(coords) do
  37. map:append(am.circle(vec2(unpack(v)), layout.size[1], rcolor(), 6))
  38. end
  39. return map
  40. end
  41. ----- [[ MAIN ]] -----------------------------------------------------------
  42. local game_scene = render_map(layout)
  43. local test_scene = am.group()
  44. win.scene = am.group{test_scene, game_scene}
  45. test_scene:action(function()
  46. x, y = unpack(pixel_to_hex(win:mouse_position().x, win:mouse_position().y, layout))
  47. test_scene:replace("text",
  48. am.translate(vec2(unpack(hex_to_pixel(x, y, layout))))
  49. ^ am.text(string.format("%d, %d", x, y)))
  50. am.delay(1)
  51. end)