main.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. -- title: cylshooter
  2. -- author: pixelbath
  3. -- desc: short description
  4. -- site: website link
  5. -- license: MIT License (change this to your license of choice)
  6. -- version: 0.1
  7. -- script: lua
  8. -- The idea:
  9. -- like Resogun, a cylindrical shooter
  10. -- 1. render map
  11. -- 2. fix column-by-column, raycast style
  12. -- 3. how to draw background?
  13. -- 1. render bg map offscreen
  14. -- 2. memcpy to onscreen
  15. -- 3. render fg map offscreen
  16. -- 4. memcpy/pix the fg to the screen?
  17. local world = {}
  18. local entities = {}
  19. local player = {
  20. x=0, y=0,
  21. vx=0, vy=0,
  22. speed=1.5,
  23. }
  24. function player:update()
  25. self.vx = 0
  26. self.vy = 0
  27. if btn(0) then
  28. self.vy=-self.speed
  29. end
  30. if btn(1) then
  31. self.vy=self.speed
  32. end
  33. if btn(2) then
  34. self.vx=-self.speed
  35. end
  36. if btn(3) then
  37. self.vx=self.speed
  38. end
  39. -- slow down diagonal movements
  40. if self.vx * self.vy ~= 0 then
  41. self.vx = self.vx * 0.707
  42. self.vy = self.vy * 0.707
  43. end
  44. self.x = self.x + self.vx
  45. self.y = self.y + self.vy
  46. end
  47. function player:draw()
  48. rect(self.x, self.y, 8, 8, 4)
  49. end
  50. function world:add_entity(en)
  51. table.insert(entities, en)
  52. end
  53. function world:update()
  54. for key,val in ipairs(entities) do
  55. entities[key]:update()
  56. end
  57. end
  58. function world:draw()
  59. for key,val in ipairs(entities) do
  60. entities[key]:draw()
  61. end
  62. end
  63. world:add_entity(player)
  64. function TIC()
  65. cls()
  66. world:update()
  67. world:draw()
  68. end
  69. -- <PALETTE>
  70. -- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
  71. -- </PALETTE>