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
2.5 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
5 years ago
  1. settings = am.load_state("settings", "json") or {
  2. fullscreen = false,
  3. window_width = 1920,
  4. window_height = 1080,
  5. music_volume = 0.1,
  6. sfx_volume = 0.1,
  7. }
  8. math.randomseed(os.time())
  9. math.random()
  10. math.random()
  11. math.random()
  12. math.random()
  13. do
  14. win = am.window{
  15. width = settings.window_width,
  16. height = settings.window_height,
  17. title = "hexyz",
  18. mode = settings.fullscreen and "fullscreen" or "windowed",
  19. highdpi = true,
  20. letterbox = true,
  21. resizable = true, -- user should probably set their resolution instead of resizing the window, but hey.
  22. }
  23. end
  24. -- asset interfaces and/or trivial code
  25. require "color"
  26. require "sound"
  27. require "texture"
  28. require "src/entity"
  29. require "src/extra"
  30. require "src/geometry"
  31. require "src/hexyz"
  32. require "src/game"
  33. require "src/gui"
  34. require "src/grid"
  35. require "src/mob"
  36. require "src/projectile"
  37. require "src/tower"
  38. function main_action(self)
  39. self"hex_backdrop""rotate".angle = math.wrapf(self"hex_backdrop""rotate".angle - 0.002 * am.delta_time, math.pi*2)
  40. end
  41. function make_main_scene_toolbelt()
  42. local options = {
  43. {
  44. label = "new game",
  45. action = function(self) end
  46. },
  47. {
  48. label = "load game",
  49. action = function(self) game_init(am.load_state("save", "json")) end
  50. },
  51. {
  52. label = "map editor",
  53. action = function(self) log("map editor not implemented") end
  54. },
  55. {
  56. label = "settings",
  57. action = function(self) end
  58. },
  59. }
  60. --local map = hex_rectangular_map(10, 20, HEX_ORIENTATION.POINTY)
  61. return group
  62. end
  63. function main_scene()
  64. local group = am.group()
  65. local map = hex_hexagonal_map(30)
  66. local hex_backdrop = (am.rotate(0) ^ am.group()):tag"hex_backdrop"
  67. for i,_ in pairs(map) do
  68. for j,n in pairs(map[i]) do
  69. local color = map_elevation_color(n)
  70. color = color{a=color.a - 0.1}
  71. local node = am.translate(hex_to_pixel(vec2(i, j), vec2(HEX_SIZE)))
  72. ^ am.circle(vec2(0), HEX_SIZE, vec4(0), 6)
  73. node"circle":action(am.tween(1, { color = color }))
  74. hex_backdrop:append(node)
  75. end
  76. end
  77. group:append(hex_backdrop)
  78. group:append(am.translate(0, 200) ^ am.sprite("res/logo.png"))
  79. group:append(make_main_scene_toolbelt())
  80. group:action(main_action)
  81. return group
  82. end
  83. win.scene = am.group()
  84. game_init()
  85. noglobals()