Browse Source

Messing around

spesk1 3 years ago
parent
commit
97861b9de8
3 changed files with 374 additions and 0 deletions
  1. 57 0
      shmup.html
  2. 145 0
      shmup.js
  3. 172 0
      shmup.p8

File diff suppressed because it is too large
+ 57 - 0
shmup.html


File diff suppressed because it is too large
+ 145 - 0
shmup.js


+ 172 - 0
shmup.p8

@@ -0,0 +1,172 @@
+pico-8 cartridge // http://www.pico-8.com
+version 32
+__lua__
+--https://ztiromoritz.github.io/pico-8-shooter/
+--https://github.com/ztiromoritz/pico-8-shooter/tree/master/p8 
+function fps()
+  f = stat(7)
+  print("fps: "..f, 0, 120, 1)
+end
+
+t=0
+bullets={}
+
+function init_stars()
+  stars={}
+  star_cols={1,2,5,6,7,12}
+  warp_f=3
+  for i=1,#star_cols do
+    for j=1,10 do
+      local s={
+        x=rnd(128),
+        y=rnd(128),
+        z=i,
+        c=star_cols[i]
+      }
+      add(stars,s)
+    end
+  end
+end
+
+function init_enemies()
+  enemies={}
+  for i=1,10 do
+    add(enemies, {
+      sp=4,
+      m_x=i*16,
+      m_y=60-i*8,
+      x=-32,
+      y=-32,
+      r=12,
+    })
+  end
+end
+
+function draw_enemies()
+  for e in all(enemies) do
+    spr(e.sp,e.x,e.y)
+  end
+end
+
+function update_enemies()
+  for e in all(enemies) do
+    e.x = e.r*sin(t/50) + e.m_x
+    e.y = e.r*cos(t/50) + e.m_y
+  end
+end
+
+function init_player()
+  player={
+    h=3,
+    sp=1,
+    x=64,
+    y=64,
+  }
+end
+
+function draw_health()
+  inc=10
+  for i=1,player.h do
+    spr(2,(inc*i),1)
+  end 
+end
+
+function draw_player()
+  spr(player.sp,player.x,player.y)
+end
+
+function update_player()
+  if(t%6<3) then
+    player.sp=0
+  else
+    player.sp=1
+  end
+end
+
+function fire()
+  local b={
+    sp=3,
+    x=player.x,
+    y=player.y,
+    dx=0,
+    dy=-3,
+  }
+  add(bullets,b)
+end
+
+function draw_bullets()
+  for b in all(bullets) do 
+    spr(b.sp,b.x,b.y)
+  end
+end
+
+function draw_stars()
+  for s in all(stars) do
+    pset(s.x,s.y,s.c)
+  end
+end
+
+function update_stars()
+  for s in all(stars) do
+    s.y+=s.z*warp_f/10
+    if s.y>128 then
+      s.y=0
+      s.x=rnd(128)
+    end
+  end
+end
+
+function _init()
+  player_xpos=64
+  player_ypos=64
+  init_stars()
+  init_player()
+  init_enemies()
+end
+
+function _update60()
+  t=t+1
+  if ( t > 1000) then t=0 end
+
+  for b in all(bullets) do
+    b.x+=b.dx
+    b.y+=b.dy
+    if b.x < 0 or b.x > 128 or
+      b.y < 0 or b.y > 128 then
+      del(bullets,b)
+    end
+  end
+
+  if (btn(0) and player.x > 0) player.x -= 2
+  if (btn(1) and player.x < 127) player.x += 2
+  if (btn(2) and player.y > 0) player.y -= 2
+  if (btn(3) and player.y < 127) player.y += 2
+  if btnp(4) then fire() end
+
+  update_stars()
+  update_player()
+  update_enemies()
+end
+
+function _draw()
+  cls()
+  fps()
+  draw_health()
+  draw_stars()
+  draw_player()
+  draw_bullets()
+  draw_enemies()
+end
+
+
+
+
+__gfx__
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+005dd500005dd500005dd500000000000b3333b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+0455554004555540045555400000000000b33b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+04466440044664400446644000088000000bb0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+07466470074664700746647000088000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+07898970079898700700007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+57089075570980755700007500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+55008055550800555500005500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Some files were not shown because too many files changed in this diff