menu.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. --[========================================================================[--
  2. Menu screen code for Thrust II Reloaded.
  3. Copyright © 2015 Pedro Gimeno Fortea
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. --]========================================================================]--
  20. local menu = {}
  21. local menuimage
  22. local has_save
  23. local t
  24. local playing
  25. local period = 1.9961678004535148 -- 88031 samples / 44100 Hz
  26. local bar1, bar2
  27. local barc
  28. function menu.load()
  29. menuimage = lg.newImage("img/mainmenu.png")
  30. snd = la.newSource("snd/menu.wav")
  31. snd:setLooping(true)
  32. end
  33. function menu.activate()
  34. has_save = lfs.isFile("saved.txt")
  35. playing = false
  36. end
  37. function menu.deactivate()
  38. snd:stop()
  39. end
  40. function menu.pause(paused)
  41. if playing then
  42. if paused then snd:pause() else snd:play() end
  43. end
  44. end
  45. function menu.update(dt)
  46. if not playing then
  47. playing = true
  48. t = period/2
  49. snd:play()
  50. bar1 = main.wh/2
  51. bar2 = bar1
  52. barc = 1
  53. else
  54. t = t + dt
  55. if t >= period then
  56. t = t - period
  57. end
  58. bar1 = main.wh/2 - (t-period/2)/period * main.wh*0.78
  59. bar2 = main.wh/2 + (t-period/2)/period * main.wh*0.78
  60. barc = barc + dt * 50
  61. end
  62. lti.sleep(0.02)
  63. end
  64. function menu.draw()
  65. if playing then
  66. local c = math.floor(barc) % 6 + 1
  67. local b = c % 2 c = (c - b) / 2
  68. local r = c % 2 c = (c - r) / 2
  69. local g = c % 2
  70. lg.setColor(r*192, g*192, b*192)
  71. lg.rectangle("fill", 0, bar1-2, main.ww, 5)
  72. lg.rectangle("fill", 0, bar2-2, main.ww, 5)
  73. end
  74. lg.setColor(255,255,255)
  75. lg.draw(menuimage, 0, 0)
  76. lg.setColor(0,192,192)
  77. lg.print("FROM FIREBIRD SOFTWARE", 144, 144)
  78. lg.setColor(0,192,0)
  79. lg.print("@^ A.ROGERS 1986", 192, 176)
  80. lg.print("@^ P.GIMENO 2015", 192, 200)
  81. lg.setColor(192,192,192)
  82. lg.print("1....START GAME", 192, 272)
  83. lg.print("2....DEFINE KEYS", 192, 304)
  84. if has_save then
  85. lg.print("3....LOAD GAME", 192, 336)
  86. end
  87. lg.setColor(255,255,255)
  88. end
  89. function menu.textinput(c)
  90. if c == "1" then
  91. main.restore = false
  92. game.newgame()
  93. main.activate(game)
  94. elseif c == "2" then
  95. main.activate(redef)
  96. elseif c == "3" and has_save then
  97. main.restore = true
  98. game.newgame()
  99. main.activate(game)
  100. end
  101. end
  102. return menu