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.

109 lines
4.0 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. 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. -- mob stuff
  53. MOB_BEEPER = load_texture("mob_beeper.png"),
  54. MOB_SPOODER = load_texture("mob_spooder.png"),
  55. MOB_VELKOOZ = load_texture("mob_velkooz.png"),
  56. MOB_VELKOOZ1 = load_texture("mob_velkooz1.png"),
  57. MOB_VELKOOZ2 = load_texture("mob_velkooz2.png"),
  58. MOB_VELKOOZ3 = load_texture("mob_velkooz3.png"),
  59. }
  60. function pack_texture_into_sprite(
  61. texture,
  62. width,
  63. height,
  64. color,
  65. s1,
  66. s2,
  67. t1,
  68. t2
  69. )
  70. local width, height = width or texture.width, height or texture.height
  71. local sprite = am.sprite{
  72. texture = texture,
  73. s1 = s1 or 0, s2 = s2 or 1, t1 = t1 or 0, t2 = t2 or 1,
  74. x1 = 0, x2 = width, width = width,
  75. y1 = 0, y2 = height, height = height
  76. }
  77. if color then sprite.color = color end
  78. return sprite
  79. end
  80. function update_sprite(sprite, texture, width, height, s1, t1, s2, t2)
  81. local s1, t1, s2, t2 = s1 or 0, t1 or 0, s2 or 1, t2 or 1
  82. local width, height = width or texture.width, height or texture.height
  83. sprite.source = {
  84. texture = texture,
  85. s1 = s1, t1 = t1, s2 = s2, t2 = t2,
  86. x1 = 0, x2 = width, width = width,
  87. y1 = 0, y2 = height, height = height
  88. }
  89. end