shmup.p8 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. pico-8 cartridge // http://www.pico-8.com
  2. version 32
  3. __lua__
  4. --https://ztiromoritz.github.io/pico-8-shooter/
  5. --https://github.com/ztiromoritz/pico-8-shooter/tree/master/p8
  6. function fps()
  7. f = stat(7)
  8. print("fps: "..f, 0, 120, 1)
  9. end
  10. t=0
  11. bullets={}
  12. function init_stars()
  13. stars={}
  14. star_cols={1,2,5,6,7,12}
  15. warp_f=3
  16. for i=1,#star_cols do
  17. for j=1,10 do
  18. local s={
  19. x=rnd(128),
  20. y=rnd(128),
  21. z=i,
  22. c=star_cols[i]
  23. }
  24. add(stars,s)
  25. end
  26. end
  27. end
  28. function init_enemies()
  29. enemies={}
  30. for i=1,10 do
  31. add(enemies, {
  32. sp=4,
  33. m_x=i*16,
  34. m_y=60-i*8,
  35. x=-32,
  36. y=-32,
  37. r=12,
  38. })
  39. end
  40. end
  41. function draw_enemies()
  42. for e in all(enemies) do
  43. spr(e.sp,e.x,e.y)
  44. end
  45. end
  46. function update_enemies()
  47. for e in all(enemies) do
  48. e.x = e.r*sin(t/50) + e.m_x
  49. e.y = e.r*cos(t/50) + e.m_y
  50. end
  51. end
  52. function init_player()
  53. player={
  54. h=3,
  55. sp=1,
  56. x=64,
  57. y=64,
  58. }
  59. end
  60. function draw_health()
  61. inc=10
  62. for i=1,player.h do
  63. spr(2,(inc*i),1)
  64. end
  65. end
  66. function draw_player()
  67. spr(player.sp,player.x,player.y)
  68. end
  69. function update_player()
  70. if(t%6<3) then
  71. player.sp=0
  72. else
  73. player.sp=1
  74. end
  75. end
  76. function fire()
  77. local b={
  78. sp=3,
  79. x=player.x,
  80. y=player.y,
  81. dx=0,
  82. dy=-3,
  83. }
  84. add(bullets,b)
  85. end
  86. function draw_bullets()
  87. for b in all(bullets) do
  88. spr(b.sp,b.x,b.y)
  89. end
  90. end
  91. function draw_stars()
  92. for s in all(stars) do
  93. pset(s.x,s.y,s.c)
  94. end
  95. end
  96. function update_stars()
  97. for s in all(stars) do
  98. s.y+=s.z*warp_f/10
  99. if s.y>128 then
  100. s.y=0
  101. s.x=rnd(128)
  102. end
  103. end
  104. end
  105. function _init()
  106. player_xpos=64
  107. player_ypos=64
  108. init_stars()
  109. init_player()
  110. init_enemies()
  111. end
  112. function _update60()
  113. t=t+1
  114. if ( t > 1000) then t=0 end
  115. for b in all(bullets) do
  116. b.x+=b.dx
  117. b.y+=b.dy
  118. if b.x < 0 or b.x > 128 or
  119. b.y < 0 or b.y > 128 then
  120. del(bullets,b)
  121. end
  122. end
  123. if (btn(0) and player.x > 0) player.x -= 2
  124. if (btn(1) and player.x < 127) player.x += 2
  125. if (btn(2) and player.y > 0) player.y -= 2
  126. if (btn(3) and player.y < 127) player.y += 2
  127. if btnp(4) then fire() end
  128. update_stars()
  129. update_player()
  130. update_enemies()
  131. end
  132. function _draw()
  133. cls()
  134. fps()
  135. draw_health()
  136. draw_stars()
  137. draw_player()
  138. draw_bullets()
  139. draw_enemies()
  140. end
  141. __gfx__
  142. 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  143. 005dd500005dd500005dd500000000000b3333b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  144. 0455554004555540045555400000000000b33b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  145. 04466440044664400446644000088000000bb0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  146. 07466470074664700746647000088000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  147. 07898970079898700700007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  148. 57089075570980755700007500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  149. 55008055550800555500005500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000