shmup.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. -- title: untitled shmup
  2. -- author: game developer
  3. -- desc: something like Gradius/Nemesis/Salamander/Life Force
  4. -- script: lua
  5. t=0
  6. local bullet_speed = 6
  7. local bullet_timer = 0
  8. local bullet_timer_start = 10
  9. local player_bullets = {}
  10. local player = {
  11. x=0,y=0,
  12. vx=0,vy=0,
  13. speed=1.5,
  14. sp=256,
  15. fire_t=0,
  16. fire_held=false,
  17. }
  18. -- TODO: various types
  19. function add_bullet()
  20. sfx(0, 'D-6', 10, 0, 11, 4)
  21. table.insert(player_bullets, {
  22. x=player.x + 10,
  23. y=player.y + 5,
  24. vx = 0,
  25. vy = 0,
  26. })
  27. end
  28. function draw_player()
  29. spr(player.sp, player.x, player.y, 0, 1, 0, 0, 2, 2)
  30. end
  31. function draw_bullets()
  32. for key,val in ipairs(player_bullets) do
  33. spr(258, val.x, val.y, 0)
  34. end
  35. end
  36. function handle_input()
  37. player.vx = 0
  38. player.vy = 0
  39. if btn(0) then
  40. player.vy=-player.speed
  41. end
  42. if btn(1) then
  43. player.vy=player.speed
  44. end
  45. if btn(2) then
  46. player.vx=-player.speed
  47. end
  48. if btn(3) then
  49. player.vx=player.speed
  50. end
  51. -- slow down diagonal movements
  52. if player.vx * player.vy ~= 0 then
  53. player.vx = player.vx * 0.707
  54. player.vy = player.vy * 0.707
  55. end
  56. player.x = player.x + player.vx
  57. player.y = player.y + player.vy
  58. player.fire_held = false
  59. if btn(4) then
  60. if player.fire_t <= 0 then
  61. player.fire_t = bullet_timer_start
  62. add_bullet()
  63. else
  64. player.fire_t = player.fire_t - 1
  65. end
  66. player.fire_held = true
  67. else
  68. player.fire_t = 0
  69. end
  70. end
  71. function TIC()
  72. handle_input()
  73. for key,val in ipairs(player_bullets) do
  74. val.x = val.x + bullet_speed
  75. if val.x > 240 then
  76. table.remove(player_bullets, key)
  77. end
  78. end
  79. cls(0)
  80. draw_player()
  81. draw_bullets()
  82. dbg(tostring(player.fire_t), 0)
  83. dbg(tostring(player.fire_held), 1)
  84. dbg(tostring(player.vx), 2)
  85. dbg(tostring(player.vy), 3)
  86. t=t+1
  87. end
  88. function dbg(msg, line_no)
  89. print(msg, 5, line_no * 7, 5, true, 1, true)
  90. end
  91. -- <SPRITES>
  92. -- 000:00000000000000000000000000000000ede00000ecdef0000edddef00fcccc8b
  93. -- 001:000000000000000000000000000000000000000000000000000000009cde0000
  94. -- 002:0000000000000000000000004040440030303300000000000000000000000000
  95. -- 016:cf9edd99dfb8eeee00db8ddd00008cce00000000000000000000000000000000
  96. -- 017:aaeddcefeeeccde0ccde00000000000000000000000000000000000000000000
  97. -- </SPRITES>
  98. -- <WAVES>
  99. -- 000:123345667889abbcdeff1fedcba86642
  100. -- </WAVES>
  101. -- <SFX>
  102. -- 000:00d050808060c040d020e020f010f010f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000502000000000
  103. -- </SFX>
  104. -- <PALETTE>
  105. -- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
  106. -- </PALETTE>