getready.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. --[========================================================================[--
  2. Get Ready 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 getready = {}
  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 wait_time = 1.2
  24. local scroll_in_time = 1.2
  25. local quad, prev_x, canvas
  26. local DIV = love_version >= 11000000 and 255 or 1
  27. function getready.load()
  28. quad = lg.newQuad(0, 0, 1, 1, main.ww, main.wh)
  29. canvas = lg.newCanvas(main.ww, main.wh) -- for scrolling
  30. end
  31. function getready.activate()
  32. if getready.fromstart then
  33. timer = -wait_time
  34. else
  35. timer = 0
  36. end
  37. prev_x = main.ww + 8
  38. end
  39. function getready.keypressed(k, r)
  40. if r then return end
  41. if k == "escape" then
  42. return main.dialog("EXIT TO MENU?", main.tomenu)
  43. end
  44. if k == "f3" then
  45. main.restore = true
  46. screens.game.newgame()
  47. getready.fromstart = true
  48. getready.activate()
  49. end
  50. end
  51. function getready.update(dt)
  52. timer = timer + dt
  53. if timer >= scroll_in_time then
  54. main.activate(screens.game)
  55. return
  56. end
  57. end
  58. function getready.draw()
  59. local game = screens.game
  60. lg.setScissor(game.vx, game.vy, game.vw, game.vh)
  61. local x = (main.ww + 8)
  62. if timer > 0 then
  63. x = math.floor(x * (1 - timer/scroll_in_time))
  64. end
  65. if getready.fromstart and timer < 0 then
  66. lg.setColor(0/DIV,0/DIV,0/DIV,255/DIV)
  67. lg.rectangle("fill", game.vx, game.vy, game.vw, game.vh)
  68. lg.setColor(255/DIV,255/DIV,255/DIV,255/DIV)
  69. main.centertext("GET READY", game.vx+game.vw/2, game.vy+game.vh/2)
  70. end
  71. if timer >= 0 then
  72. -- Drawing part of a canvas onto itself causes artifacts,
  73. -- therefore we draw to our local canvas and copy the result back.
  74. lg.setCanvas(canvas)
  75. lg.clear()
  76. if x >= 0 then
  77. quad:setViewport((prev_x-x), 0, game.vw-(prev_x-x), game.vh)
  78. lg.draw(main.canvas, quad, 0, 0)
  79. prev_x = x
  80. end
  81. if x <= game.vw then
  82. lg.setScissor(x + game.vx, game.vy, game.vw-x, game.vh)
  83. local vpx = math.floor(game.state.ship.x+0.5-game.vw/2)
  84. local vpy = math.floor(game.state.ship.y+0.5-game.vh/2)
  85. if vpy < 0 then vpy = 0 end
  86. if vpy > 2048-game.vh then vpy = 2048-game.vh end
  87. game.tiles_draw(vpx-x, vpy)
  88. game.orbs_draw(vpx-x, vpy)
  89. lg.setScissor(game.vx, game.vy, game.vw, game.vh)
  90. end
  91. lg.setColor(120/DIV,150/DIV,150/DIV,255/DIV)
  92. lg.rectangle("fill", x-8, 0, 8, main.wh)
  93. lg.setColor(255/DIV,255/DIV,255/DIV,255/DIV)
  94. -- Draw back to the main canvas
  95. lg.setCanvas(main.canvas)
  96. lg.draw(canvas)
  97. end
  98. lg.setScissor()
  99. end
  100. function getready.resize(neww, newh)
  101. canvas = lg.newCanvas(main.ww, main.wh)
  102. quad = lg.newQuad(0, 0, 1, 1, main.ww, main.wh)
  103. end
  104. return getready