gamewon.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. --[========================================================================[--
  2. Game Won screen for Thrust II Reloaded.
  3. Copyright © 2015-2018 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 gamewon = {}
  21. local la,le,lfs,lf,lg,li,lj,lk,lm,lmo,lp,ls,lsys,lth,lt,lw = require'ns'()
  22. local timer
  23. local rays
  24. local gdt
  25. local rayspeed = 1000
  26. local function newray()
  27. local amplitude = 1
  28. local rnd = 2*amplitude*lm.random() - amplitude
  29. local angle = math.abs(rnd)^3
  30. if rnd < 0 then angle = -angle end
  31. local spdrnd = lm.random()*0.7+1
  32. local vx = math.sin(angle)*spdrnd
  33. local vy = -math.cos(angle)*spdrnd
  34. return { x = screens.game.vw/2 + screens.game.vx, y = 255,
  35. vx = vx, vy = vy,
  36. len = math.random()*65
  37. }
  38. end
  39. function gamewon.activate()
  40. timer = 0
  41. rays = {}
  42. end
  43. function gamewon.deactivate()
  44. rays = {}
  45. end
  46. function gamewon.update(dt)
  47. timer = timer + dt
  48. if timer > 35 then
  49. main.activate(screens.splash)
  50. return
  51. end
  52. if timer >= 5 and timer < 20 then
  53. for k,v in ipairs(rays) do
  54. v.y = v.y + v.vy * rayspeed * dt
  55. if v.y < 0 then
  56. if timer < 19.5 then
  57. rays[k] = newray()
  58. end
  59. else
  60. v.x = v.x + v.vx * rayspeed * dt
  61. end
  62. end
  63. local t = math.floor((timer-5) / 0.05) -- 0.1 is the spawn rate
  64. if t < 80 then -- max simultaneous rays
  65. rays[t] = newray()
  66. end
  67. end
  68. end
  69. function gamewon.draw()
  70. local y
  71. if timer < 2 then
  72. y = 90
  73. elseif timer < 3 then
  74. y = math.floor(90.5 - (timer-2)*90)
  75. else
  76. y = 0
  77. end
  78. local game = screens.game
  79. game.tiles_draw(math.floor(1856-game.vw/2), y)
  80. if timer < 5 then
  81. -- do nothing
  82. elseif timer < 20 then
  83. lg.setScissor(game.vx, game.vy, game.vw, game.vh)
  84. for k,v in ipairs(rays) do
  85. lg.line(v.x, v.y, v.x+v.vx*v.len, v.y+v.vy*v.len)
  86. end
  87. lg.setScissor()
  88. end
  89. end
  90. function gamewon.keypressed(k, r)
  91. if r then return end
  92. if k == "escape" then
  93. return main.dialog("EXIT TO MENU?", main.tomenu)
  94. end
  95. -- DEBUG
  96. if k == "f3" then
  97. gamewon.activate()
  98. end
  99. end
  100. return gamewon