main.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. -- title: 1bit shmup
  2. -- author: pixelbath
  3. -- desc: idk
  4. -- script: lua
  5. t=0
  6. local bullet_speed = 6
  7. local bullet_timer = 0
  8. local bullet_timer_start = 10
  9. -- props: x, y, vx, vy, type
  10. local player_bullets = {}
  11. local player = {
  12. x=20,y=60,
  13. vx=0,vy=0,
  14. speed=1.5,
  15. sp=257,
  16. fire_t=0,
  17. fire_held=false,
  18. gun_type=1,
  19. gun_level=1,
  20. }
  21. local enemies = {}
  22. function add_enemy(en_type, xpos, ypos)
  23. table.insert(enemies, {
  24. x=xpos, y=ypos,
  25. type=en_type,
  26. t=0,
  27. })
  28. end
  29. function mod(a, b)
  30. return math.floor(a-(math.floor(a/b)*b))
  31. end
  32. -- TODO: various types
  33. function add_bullet()
  34. sfx(0, 'D-6', 10, 0, 11, 4)
  35. table.insert(player_bullets, {
  36. x=player.x + 8,
  37. y=player.y + 3,
  38. vx = 0,
  39. vy = 0,
  40. })
  41. end
  42. function draw_player()
  43. local engine_spr = 274
  44. if player.vx > 0 then
  45. engine_spr = 306
  46. elseif player.vx < 0 then
  47. engine_spr = 290
  48. end
  49. -- draw engine fire then player
  50. -- spr(engine_spr, player.x-8, player.y+1)
  51. spr(player.sp, player.x, player.y, 0, 1, 0, 0, 2, 2)
  52. end
  53. function draw_bullets()
  54. for key,val in ipairs(player_bullets) do
  55. spr(291, val.x, val.y, 0, 1, 0, 0, 2, 1)
  56. end
  57. end
  58. -- also handle powerups since they're colliders
  59. function draw_enemies()
  60. end
  61. function handle_input()
  62. player.vx = 0
  63. player.vy = 0
  64. if btn(0) then
  65. player.vy=-player.speed
  66. end
  67. if btn(1) then
  68. player.vy=player.speed
  69. end
  70. if btn(2) then
  71. player.vx=-player.speed
  72. end
  73. if btn(3) then
  74. player.vx=player.speed
  75. end
  76. -- slow down diagonal movements
  77. if player.vx * player.vy ~= 0 then
  78. player.vx = player.vx * 0.707
  79. player.vy = player.vy * 0.707
  80. end
  81. player.x = player.x + player.vx
  82. player.y = player.y + player.vy
  83. if player.x < 5 then player.x = 5 end
  84. if player.x > 220 then player.x = 220 end
  85. if player.y < 5 then player.y = 5 end
  86. if player.y > 128 then player.y = 128 end
  87. player.fire_held = false
  88. if btn(4) then
  89. if player.fire_t <= 0 then
  90. player.fire_t = bullet_timer_start
  91. add_bullet()
  92. else
  93. player.fire_t = player.fire_t - 1
  94. end
  95. player.fire_held = true
  96. else
  97. player.fire_t = 0
  98. end
  99. -- debug
  100. if btnp(5) then
  101. player.gun_type = mod(player.gun_type + 1, 3) + 1
  102. end
  103. end
  104. function TIC()
  105. handle_input()
  106. for key,val in ipairs(player_bullets) do
  107. val.x = val.x + bullet_speed
  108. if val.x > 240 then
  109. table.remove(player_bullets, key)
  110. end
  111. end
  112. cls(0)
  113. draw_player()
  114. draw_bullets()
  115. dbg("type:"..tostring(player.gun_type), 0)
  116. dbg(tostring(player.fire_held), 1)
  117. dbg(tostring(mod(t/3, 5) + 1), 2)
  118. -- dbg(tostring(player.vy), 3)
  119. t=t+1
  120. end
  121. function dbg(msg, line_no)
  122. print(msg, 5, line_no * 7, 5, true, 1, true)
  123. end
  124. -- <SPRITES>
  125. -- 001:000000000000000000000ccc00cccccccccc00c000c00c000ccccccc0c0c0c0c
  126. -- 002:0000000000000000cc00000000000000000000000ccc0000ccccc000c000ccc0
  127. -- 003:0000000000000000000000cc000cccccccccc0c000c00c000ccccccc0ccccccc
  128. -- 004:0000000000000000cc00000000000000000000000ccc0000ccccc000cc00ccc0
  129. -- 005:00000000000000000000000000000ccc00cccccc0cc00c00cccccccc0ccccccc
  130. -- 006:000000000000000000000000cc000000000000000cc00000ccccc000ccc0ccc0
  131. -- 007:000000000000000000000000000000000000000000cccccc0c000000cccccccc
  132. -- 008:000000000000000000000000000000000000000000000000ccccc000ccccccc0
  133. -- 009:0000000000000000000000000000000000000ccc000cc0c0ccc00c000c00c000
  134. -- 010:00000000000000000000000000000000cc000000c00000000cccc0000000ccc0
  135. -- 011:00000000000000000000000000000ccc00ccc00cccc00c000c0000cc0cc0c000
  136. -- 012:000000000000000000000000cc000000000000000ccc0000c00cc0000000ccc0
  137. -- 013:0000000000000000000000cc000ccc0cccc000c000c00c000c0000cc0cc0c000
  138. -- 014:0000000000000000cc00000000000000000000000ccc0000c00cc0000000ccc0
  139. -- 017:0ccccccc00c00c00cccc00c000cccccc00000ccc000000000000000000000000
  140. -- 018:ccccc0000ccc00000000000000000000cc000000000000000000000000000000
  141. -- 019:0c0c0c0c00c00c00ccccc0c0000ccccc000000cc000000000000000000000000
  142. -- 020:c0ccc0000ccc00000000000000000000cc000000000000000000000000000000
  143. -- 021:cc0c0c0c0cc00c0000cccccc00000ccc00000000000000000000000000000000
  144. -- 022:c00cc0000cc0000000000000cc00000000000000000000000000000000000000
  145. -- 023:0ccccccc00cccccc000000000000000000000000000000000000000000000000
  146. -- 024:ccccc00000000000000000000000000000000000000000000000000000000000
  147. -- 025:ccc00c00000ccccc00000ccc0000000000000000000000000000000000000000
  148. -- 026:0ccc0000c0000000cc0000000000000000000000000000000000000000000000
  149. -- 027:0c0000ccccc00c0000ccc00c00000ccc00000000000000000000000000000000
  150. -- 028:c00cc0000ccc000000000000cc00000000000000000000000000000000000000
  151. -- 029:0c0000cc00c00c00ccc000c0000ccc0c000000cc000000000000000000000000
  152. -- 030:c00cc0000ccc00000000000000000000cc000000000000000000000000000000
  153. -- 033:000000000000000000000ccc00ccc00ccc0000c000c00c000c0000cc0cc0c000
  154. -- 034:0000000000000000cc00000000000000000000000ccc0000c00cc0000000ccc0
  155. -- 035:000000000c0c0ccc0000c0cc00000000000000000000c0cc0c0c0ccc00000000
  156. -- 036:00000000ccccccccccccccc00000000000000000ccccccc0cccccccc00000000
  157. -- 049:0c0000cc00c00c00cc0000c000ccc00c00000ccc000000000000000000000000
  158. -- 050:c00cc0000ccc00000000000000000000cc000000000000000000000000000000
  159. -- 051:0000c0c0000000000000000000000000000000000000000000000000000c0c0c
  160. -- 052:cc0cccc00000000cc0c0ccc000000000000000000c0cccc00000000cccccccc0
  161. -- </SPRITES>
  162. -- <WAVES>
  163. -- 000:123345667889abbcdeff1fedcba86642
  164. -- </WAVES>
  165. -- <SFX>
  166. -- 000:00d050808060c040d020e020f010f010f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000502000000000
  167. -- </SFX>
  168. -- <PALETTE>
  169. -- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
  170. -- </PALETTE>