Created
September 3, 2023 13:48
-
-
Save Achie72/aca9927575cce69f07308594a3529d83 to your computer and use it in GitHub Desktop.
PICO-8 1k byte shmup rundown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pico-8 cartridge // http://www.pico-8.com | |
| version 36 | |
| __lua__ | |
| --[[ | |
| a - ammo | |
| h,v - ship coord | |
| t - frames (ticks) 0-30 | |
| w - wave spawner, holds when the next wave will spawn | |
| d - difficulty counter | |
| l - lifes | |
| b - bullets {} | |
| e - enmeies {} | |
| p - p is not needed I think, leftover junk | |
| r -- rnd() remap for fewer chars | |
| k - del() remap for smae | |
| eb - enemy bullets {} | |
| ht - hearts {} | |
| ld - score holder in the end | |
| ]] | |
| a,h,v,t,w,d,l,b,e,p,r,k,eb,ht,ld=20,64,100,0,0,0,10,{},{},{},rnd,del,{},{},0 -- shorter variable names | |
| function ce(a,b,c,d,e) if (((a-b)*(a-b)) + (c-d)*(c-d) <= e*e) then return true else return false end end -- distance based collision | |
| ::_:: -- goto label | |
| if time() < 3 then goto title else -- titles screen check | |
| cls()t+=1 -- frame counter | |
| if(t%2==1)add(b,{x=r(128),y=0,t=1,b=0,c=1+flr(r(2))*6}) -- every second add a type1 bullett, these are the starts in the bg with negative momentum | |
| if(t>30)then t,d=0,d+0.005 end -- reset frame counter to loop in 0-30, increase difficulty | |
| if(w<time())then --spawn new alien, i don't even use t, lol | |
| i={x=r(120),y=-2,t=r(3),s=r({1,2}),sp=time()+r()}add(e,i) | |
| o=2-d | |
| if(o<0.1)o=0.1 -- dafuq is this tbh | |
| w=time()+(2-d) | |
| end | |
| if(btn(⬅️))h-=2 -- controls | |
| if(btn(➡️))h+=2 | |
| if(btn(⬆️))v-=2 | |
| if(btn(⬇️))v+=2 | |
| if(0<(h+6) and h<20 and v>99 and v<113)a+=1 --ammo reload on proximity, could use ce collision | |
| if(btnp(❎)and(a>1))a=a-2add(b,{x=h,y=v,t=0,b=0,c=9}) -- shoot bullets, see type=0 those are hurting bullets going up, 1is stars in bg going down | |
| for a in all(b) do -- bullet movement update | |
| if a.b==0 then | |
| m=a.t*4 -- here we *4 the movement of starts (type 1 bullets) | |
| if(a.t==0)m=-2 -- flip movement to bullets, they should go up not down | |
| a.y+=m -- move all bullets (remember, stars are non colliding grey bullets) | |
| if((a.y>128)or(a.y<0)) k(b,a) -- remove them if they are under or over screen | |
| end | |
| tex=a.t==0 and "✽" or "." -- dot is star, shuriken is bullets | |
| ?tex,a.x,a.y,a.c -- print them on screen | |
| end | |
| for q in all(e) do -- enemy update loop | |
| q.y,z,c=q.y+1,q.y,q.x -- save some stuff for cars | |
| if q.s==1 and q.sp < time() then ebu={x=q.x,y=q.y+4,s=r()*2+1}add(eb,ebu) q.sp=time()+r()*4 end -- shooting enemies, adding bullets | |
| te = q.s==1 and "☉" or "😐" -- enemy texture switch based on type | |
| ?te,q.x,q.y,8 -- print enemy on screen | |
| if(z>128)k(e,q)l-=1 -- if enemy makes past screen, delete and lose a life | |
| for a in all(b) do | |
| p,o=a.x,a.y -- enemy and bullet collision | |
| if(a.t==0)and ce(p,q.x,o,q.y,3)then k(e,q)k(a,b)end | |
| end | |
| end | |
| for b in all(eb) do -- enemy bullet udate | |
| b.y+=b.s -- move down | |
| if b.y > 128 then k(eb,b) end -- delete if under | |
| if ce(h,b.x,v,b.y,3) then k(eb,b) l-=1 end -- player collision check | |
| ?"●",b.x-2,b.y-2,r({8,2}) -- print with random color of dark or bright red | |
| end | |
| if time()%15 == 0 then hr={x=r(128),y=0} add(ht,hr) end -- hearth spawning in | |
| for hr in all(ht) do -- hearth update | |
| hr.y+=1 | |
| if ce(h,hr.x,v,hr.y,4) then k(ht,hr) l+=1 end -- player collision to heal | |
| ?"♥",hr.x-3,hr.y-3,rnd(15) -- print | |
| end | |
| ?"/ホ\\",h-7,v-2,11 -- player ship print | |
| ?"⬆️"..flr(a/2),110,0,9 -- ammo number print | |
| ?"⬆️",2,100,9 -- ammo print | |
| ?"♥"..l,0,0,11 -- health print | |
| if(t%5==1)?"◆",h-3,v+3,10 -- ship flame | |
| if(l<=0) then ld=time() end -- on game end save time | |
| -- Copies the graphics buffer to the screen, then synchronizes to the next frame at 30 frames per second. This basically is our | |
| -- _draw() basically if you want to spare tokens not wrinting function _draw() end | |
| flip() -- draw call | |
| if l>0 then goto _ else goto over end -- if game is going, jump back to _ with goto and keep the loop alive, if not jump to over | |
| end | |
| ::title:: -- title loop, which jumps back to _ to keep the game alive | |
| cls() | |
| ?"1k defender",44,62,rnd({6,7}) | |
| flip() | |
| goto _ -- loop back up to keep game alive | |
| ::over:: -- over label which prints the score and stops the game | |
| ?ld,64,64,11 -- print time survived | |
| __gfx__ | |
| 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
| 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
| 00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
| 00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
| 00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
| 00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment