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.

111 lines
4.1 KiB

3 years ago
  1. local IMG_FILE_PREFIX = "res/img/"
  2. local function load_texture(filepath)
  3. local path = IMG_FILE_PREFIX .. filepath
  4. local status, texture = pcall(am.texture2d, path)
  5. if status then
  6. return texture
  7. else
  8. log("failed to load texture at path: " .. path)
  9. return am.texture2d(IMG_FILE_PREFIX .. "bagel.jpg")
  10. end
  11. end
  12. TEXTURES = {
  13. -- note that in amulet, if you prefix paths with './', they fail to be found in the exported data.pak
  14. WHITE = load_texture("white-texture.png"),
  15. LOGO = load_texture("logo.png"),
  16. GEM1 = load_texture("gem1.png"),
  17. SHADED_HEX = load_texture("shaded_hex.png"),
  18. NEW_GAME_HEX = load_texture("newgamehex.png"),
  19. SAVE_GAME_HEX = load_texture("savegamehex.png"),
  20. LOAD_GAME_HEX = load_texture("loadgamehex.png"),
  21. SETTINGS_HEX = load_texture("settingshex.png"),
  22. MAP_EDITOR_HEX = load_texture("mapeditorhex.png"),
  23. ABOUT_HEX = load_texture("abouthex.png"),
  24. QUIT_HEX = load_texture("quithex.png"),
  25. UNPAUSE_HEX = load_texture("unpausehex.png"),
  26. MAIN_MENU_HEX = load_texture("mainmenuhex.png"),
  27. SEED_COLON_TEXT = load_texture("seed_colon_text.png"),
  28. CURTAIN = load_texture("curtain1.png"),
  29. SOUND_ON1 = load_texture("sound-on.png"),
  30. SOUND_OFF = load_texture("sound-off.png"),
  31. -- gui stuff
  32. BUTTON1 = load_texture("button1.png"),
  33. WIDER_BUTTON1 = load_texture("wider_button1.png"),
  34. GEAR = load_texture("gear.png"),
  35. SELECT_BOX = load_texture("select_box.png"),
  36. TOWER_WALL0 = load_texture("wall0.png"),
  37. -- tower stuff
  38. TOWER_WALL = load_texture("tower_wall.png"),
  39. TOWER_WALL_ICON = load_texture("tower_wall_icon.png"),
  40. TOWER_GATTLER = load_texture("tower_gattler.png"),
  41. TOWER_GATTLER_ICON = load_texture("tower_gattler_icon.png"),
  42. TOWER_HOWITZER = load_texture("tower_howitzer.png"),
  43. TOWER_HOWITZER_ICON = load_texture("tower_howitzer_icon.png"),
  44. TOWER_REDEYE = load_texture("tower_redeye.png"),
  45. TOWER_REDEYE_ICON = load_texture("tower_redeye_icon.png"),
  46. TOWER_MOAT = load_texture("tower_moat.png"),
  47. TOWER_MOAT_ICON = load_texture("tower_moat_icon.png"),
  48. TOWER_RADAR = load_texture("tower_radar.png"),
  49. TOWER_RADAR_ICON = load_texture("tower_radar_icon.png"),
  50. TOWER_LIGHTHOUSE = load_texture("tower_lighthouse.png"),
  51. TOWER_LIGHTHOUSE_ICON = load_texture("tower_lighthouse_icon.png"),
  52. TOWER_FARM = load_texture("farm2.png"),
  53. TOWER_FARM_ICON = load_texture("farm2.png"),
  54. -- mob stuff
  55. MOB_BEEPER = load_texture("mob_beeper.png"),
  56. MOB_SPOODER = load_texture("mob_spooder.png"),
  57. MOB_VELKOOZ = load_texture("mob_velkooz.png"),
  58. MOB_VELKOOZ1 = load_texture("mob_velkooz1.png"),
  59. MOB_VELKOOZ2 = load_texture("mob_velkooz2.png"),
  60. MOB_VELKOOZ3 = load_texture("mob_velkooz3.png"),
  61. }
  62. function pack_texture_into_sprite(
  63. texture,
  64. width,
  65. height,
  66. color,
  67. s1,
  68. s2,
  69. t1,
  70. t2
  71. )
  72. local width, height = width or texture.width, height or texture.height
  73. local sprite = am.sprite{
  74. texture = texture,
  75. s1 = s1 or 0, s2 = s2 or 1, t1 = t1 or 0, t2 = t2 or 1,
  76. x1 = 0, x2 = width, width = width,
  77. y1 = 0, y2 = height, height = height
  78. }
  79. if color then sprite.color = color end
  80. return sprite
  81. end
  82. function update_sprite(sprite, texture, width, height, s1, t1, s2, t2)
  83. local s1, t1, s2, t2 = s1 or 0, t1 or 0, s2 or 1, t2 or 1
  84. local width, height = width or texture.width, height or texture.height
  85. sprite.source = {
  86. texture = texture,
  87. s1 = s1, t1 = t1, s2 = s2, t2 = t2,
  88. x1 = 0, x2 = width, width = width,
  89. y1 = 0, y2 = height, height = height
  90. }
  91. end