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.

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