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

  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. CURTAIN = load_texture("curtain1.png"),
  28. SOUND_ON1 = load_texture("sound-on.png"),
  29. SOUND_OFF = load_texture("sound-off.png"),
  30. -- gui stuff
  31. BUTTON1 = load_texture("button1.png"),
  32. WIDER_BUTTON1 = load_texture("wider_button1.png"),
  33. GEAR = load_texture("gear.png"),
  34. SELECT_BOX = load_texture("select_box.png"),
  35. -- tower stuff
  36. TOWER_WALL = load_texture("tower_wall.png"),
  37. TOWER_WALL_ICON = load_texture("tower_wall_icon.png"),
  38. TOWER_GATTLER = load_texture("tower_gattler.png"),
  39. TOWER_GATTLER_ICON = load_texture("tower_gattler_icon.png"),
  40. TOWER_HOWITZER = load_texture("tower_howitzer.png"),
  41. TOWER_HOWITZER_ICON = load_texture("tower_howitzer_icon.png"),
  42. TOWER_REDEYE = load_texture("tower_redeye.png"),
  43. TOWER_REDEYE_ICON = load_texture("tower_redeye_icon.png"),
  44. TOWER_MOAT = load_texture("tower_moat.png"),
  45. TOWER_MOAT_ICON = load_texture("tower_moat_icon.png"),
  46. TOWER_RADAR = load_texture("tower_radar.png"),
  47. TOWER_RADAR_ICON = load_texture("tower_radar_icon.png"),
  48. TOWER_LIGHTHOUSE = load_texture("tower_lighthouse.png"),
  49. TOWER_LIGHTHOUSE_ICON = load_texture("tower_lighthouse_icon.png"),
  50. -- mob stuff
  51. MOB_BEEPER = load_texture("mob_beeper.png"),
  52. MOB_SPOODER = load_texture("mob_spooder.png"),
  53. MOB_VELKOOZ = load_texture("mob_velkooz.png"),
  54. MOB_VELKOOZ1 = load_texture("mob_velkooz1.png"),
  55. MOB_VELKOOZ2 = load_texture("mob_velkooz2.png"),
  56. MOB_VELKOOZ3 = load_texture("mob_velkooz3.png"),
  57. }
  58. function pack_texture_into_sprite(
  59. texture,
  60. width,
  61. height,
  62. color,
  63. s1,
  64. s2,
  65. t1,
  66. t2
  67. )
  68. local width, height = width or texture.width, height or texture.height
  69. local sprite = am.sprite{
  70. texture = texture,
  71. s1 = s1 or 0, s2 = s2 or 1, t1 = t1 or 0, t2 = t2 or 1,
  72. x1 = 0, x2 = width, width = width,
  73. y1 = 0, y2 = height, height = height
  74. }
  75. if color then sprite.color = color end
  76. return sprite
  77. end
  78. function update_sprite(sprite, texture, width, height, s1, t1, s2, t2)
  79. local s1, t1, s2, t2 = s1 or 0, t1 or 0, s2 or 1, t2 or 1
  80. local width, height = width or texture.width, height or texture.height
  81. sprite.source = {
  82. texture = texture,
  83. s1 = s1, t1 = t1, s2 = s2, t2 = t2,
  84. x1 = 0, x2 = width, width = width,
  85. y1 = 0, y2 = height, height = height
  86. }
  87. end