Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --cruiser kid
- --@taeckerwyss 3cjam2017
- p={}--player
- p.x=0
- p.y=7--graunded player y is 7
- p.z=0--player z is usually 5
- p.vx=0--velocity
- p.vy=0
- p.sprx=0
- p.spry=0
- p.w=16
- p.h=16
- p.refire=0
- p.scl=1
- p.flip=false
- jogstate=0
- jogcount=0
- --0=alive
- --1=dead
- --2=respawn
- --3=invincible
- pstate=0
- pstatecounter=0
- xdown=false
- zdown=false
- bp={}--bullets:player
- be={}--bullets:enemy
- en={}--enemies
- smk={}--smoke
- xpl={}--explosions
- pts={}--lil numbers that appear when u get points
- todraw={}--elements to z sort and draw
- fnum=0--frame counter
- --states: menu, level, game, gameover
- gamestate="menu"
- lives=0
- lifeplus=0
- lvlnum=0
- lvlround=0
- spawnc=0
- spwnpool={}
- menutween=0
- menutime=0--frames this menu has been open
- title={}--title text
- gmovr={}--gameover text
- mrlog=""
- score=0
- scrmulti=1
- multi=0.5
- cartdata("_cruiser_kid_")
- hiscore=0
- hiscoretxt="0"
- newhi=false
- function _init()
- --dset(0,0) --clear highscore
- gethiscore()
- palt(7,true)
- palt(0,false)
- addtitle()
- addgmovr()
- entermenu()
- music(0,0,3)
- end
- function _update60()
- fnum+=1
- if gamestate=="menu" then
- domenu()
- elseif gamestate=="gameover" then
- dogameover()
- else
- playerupdate()
- if gamestate=="level" then
- if p.y<=7 then
- p.vx=0
- end
- dolevel()
- else
- spawnloop()
- --update objects
- playermotor()
- foreach(en,doen)
- foreach(bp,dobp)
- foreach(be,dobe)
- --collisions
- foreach(bp,colenbp)
- if pstate==0 then --no col with player if dead or invincible
- foreach(en,colenp)
- foreach(be,colbep)
- end
- end
- playerlateupdate()
- if lifeplus>0 then
- lifeplus-=1
- end
- end
- --fx
- foreach(xpl,doxpl)
- foreach(smk,dosmk)
- foreach(pts,dopts)
- xdown=btn(5)
- zdown=btn(4)
- end
- function _draw()
- cls()
- todraw={}
- camera(0,max(-10,-p.y*0.2))
- spr(64,0,-10,16,4)--sky
- drawflr()
- if gamestate=="menu" then
- foreach(title,drawtitle)
- zsort(todraw)
- foreach(todraw,drawtodraw)
- drawmenu()
- elseif gamestate=="gameover" then
- zsort(todraw)
- foreach(todraw,drawtodraw)
- drawgameover()
- elseif gamestate=="game" then
- drawgame()
- drawhud()
- else --gamestate=="level"
- drawgame()
- drawlevel()
- drawhud()
- end
- end
- function drawgame()--shared between gamestate "game" and "level"
- foreach(en,drawen)
- foreach(bp,drawbp)
- foreach(be,drawbe)
- drawplayer()
- foreach(smk,drawsmk)
- foreach(xpl,drawxpl)
- zsort(todraw)
- foreach(todraw,drawtodraw)
- foreach(pts,drawpts)
- camera(0,0)
- print(mrlog,0,0,7)
- end
- function multiup()
- multiset( min(multi+0.05,3.99) )
- end
- function multidown()
- multiset( max(multi-0.03*multi,0.5) )
- end
- function multibonus(amt)
- multiset( min(multi+amt,3.99) )
- end
- function multiset(n)
- multi=n
- scrmulti=ceil(multi)
- end
- function spawnloop()--called every frame. handle new enemy spawning
- if lvlround<=0 then
- if #en==0 then
- addlife()
- enterlevel()
- spawnc=60
- end
- else
- if #en==0 then
- spawnc=0
- else
- spawnc-=1
- end
- if spawnc<=0 then
- makemob()
- lvlround-=1
- spawnc=340
- end
- end
- end
- function nextlevel()
- lvlnum+=1
- lvlround=6+2*lvlnum
- spwnpool={}
- local tbl={}
- if lvlnum<=1 then
- spwnpool[1]={0,12} --cat
- spwnpool[2]={1,12} --shrimp
- spwnpool[3]={11,1}--cat+shrimp
- spwnpool[4]={2}--bat
- spwnpool[5]={3}--tank
- spwnpool[6]={11,2}--cat+bat
- elseif lvlnum==2 then
- spwnpool[1]={0,2}--cat+bat
- spwnpool[2]={12,2}--shrimp+bat
- spwnpool[3]={3}--tank
- spwnpool[4]={5}--men
- spwnpool[5]={13}--men
- spwnpool[6]={8}--gnomes
- elseif lvlnum==3 then
- spwnpool[1]={3}--tank
- spwnpool[2]={4}--apc
- spwnpool[3]={7,12}--men+shrimp
- spwnpool[4]={5}--men
- spwnpool[5]={13,2}--men+bats
- spwnpool[6]={14}--robots
- elseif lvlnum==4 then
- spwnpool[1]={14}--robots
- spwnpool[2]={6}--robots
- spwnpool[3]={1,10}--gnomes+shrimp
- spwnpool[4]={8}--gnomes
- spwnpool[5]={6,11}--robots+cats
- spwnpool[6]={16}--planes
- elseif lvlnum==5 then
- spwnpool[1]={4}--apc
- spwnpool[2]={0,4}--apc+cats
- spwnpool[3]={12,2}--shrimp+bats
- spwnpool[4]={11,2}--cats+bats
- spwnpool[5]={5}--men
- spwnpool[6]={3}--tank
- elseif lvlnum==6 then
- spwnpool[1]={7,2}--men+bats
- spwnpool[2]={14}--robots
- spwnpool[3]={5,6}--robots+men
- spwnpool[4]={10,2}--gnomes+bats
- spwnpool[5]={15}--2x tank
- elseif lvlnum==7 then
- spwnpool[1]={7,16}--men+planes
- spwnpool[2]={14}--robots
- spwnpool[3]={5,6}--robots+men
- spwnpool[4]={10,16}--gnomes+planes
- spwnpool[5]={15}--2x tank
- elseif lvlnum==8 then
- spwnpool[1]={8,2,1}--gnomes+bats+shrimp
- spwnpool[2]={14,8}--gnomes+robots
- spwnpool[3]={10,6}--gnomes+men
- spwnpool[4]={2,16}--planes+bats
- spwnpool[5]={9}--turtle
- elseif lvlnum==9 then
- spwnpool[1]={6,0,11}--robots+2x cats
- spwnpool[2]={2,2,2}--3x bats
- spwnpool[3]={13,13}--2x men
- spwnpool[4]={4}--apc
- spwnpool[5]={9}--turtle
- elseif lvlnum==10 then
- spwnpool[1]={6}--robots
- spwnpool[2]={4}--apc
- spwnpool[3]={9}--turtle
- spwnpool[4]={3}--tank
- spwnpool[5]={5,13}--men
- spwnpool[6]={16,13}--planes+men
- elseif lvlnum==11 then
- spwnpool[1]={8,3}--gnomes+tank
- spwnpool[2]={10,4}--gnomes+apc
- spwnpool[3]={12,1,12}--shrimp
- spwnpool[4]={15,0}--2x tanks
- spwnpool[5]={6,14}--robots
- else
- spwnpool[1]={0,11,2,3}
- spwnpool[2]={12,4}
- spwnpool[3]={9,1}
- spwnpool[3]={9}
- spwnpool[4]={15}
- spwnpool[5]={8,8,8}
- spwnpool[6]={7,6}
- spwnpool[7]={14,14}
- spwnpool[8]={3,10}
- spwnpool[9]={10,4}
- spwnpool[10]={16,0}
- spwnpool[11]={16,6}
- end
- end
- function makemob()
- r=flr(rnd(#spwnpool))+1
- spawn(spwnpool[r])
- end
- function spawn(t)--t is a table of enemy types
- local k
- for i=1,#t do
- k=t[i]
- if k==0 then spwnrow( 0, 3+rnd(3), 100+rnd(20)) --0 row of cats
- spwnrow( 0, 3+rnd(3), 140+rnd(30))
- elseif k==1 then spwnchain( 1, 6+rnd(4), 25, 20) --1 troop of shrimp
- elseif k==2 then spwnchain( 2, 4+rnd(4), 80, 15) --2 squad of bats
- elseif k==3 then adden(rnd(110)-55, 120, 3) --3 one tank
- elseif k==4 then spwnantichain( 4, 3+rnd(2), 40, 60) --4 platoon of apcs
- elseif k==5 then spwnrow( 5, 2+rnd(3), 110+rnd(20)) --5 squad of men
- spwnrow( 5, 2+rnd(3), 150+rnd(20))
- elseif k==6 then spwnrow( 6, 2+rnd(2), 110+rnd(20)) --6 squad of robots
- spwnrow( 6, 2+rnd(2), 150+rnd(20))
- elseif k==7 then spwnantichain( 5, 4+rnd(4), 30, 20) --7 platoon of men
- elseif k==8 then spwnantichain( 7, 4+rnd(3), 20, 15) --8 platoon of gnomes
- elseif k==9 then adden(rnd(110)-55, 105, 8) --9 one turtle
- elseif k==10 then spwnrow(7, 2+rnd(3), 110+rnd(20)) --10 squad of gnomes
- spwnrow(7, 2+rnd(3), 150+rnd(20))
- elseif k==11 then spwnantichain( 0, 5+rnd(4), 40, 15) --11 platoon of cats
- elseif k==12 then spwnantichain( 1, 6+rnd(4), 50, 15) --12 scattering of shrimp
- elseif k==13 then spwnchain( 5, 5+rnd(3), 5, 15) --13 chain of men
- elseif k==14 then spwnchain( 6, 4+rnd(3), 10, 15) --14 chain on robots
- elseif k==15 then spwnrow(3, 2, 120) --15 pair of tanks
- elseif k==16 then spwnchain( 9, 3+rnd(3), 40, 25) --16 squad of planes
- end
- end
- end
- function spwnrow(t,n,z)
- n=flr(n)
- local a=120/(n-1)
- for i=0,n-1 do
- adden(a*i-60,z+rnd(2),t)
- end
- end
- function spwnchain(t,n,xrng,zrng)
- n=flr(n)
- local x=rnd(100)-50
- local z=105
- for i=1,n do
- adden(x,z,t)
- x=max(min(x+rnd(2*xrng)-xrng, 55),-55)
- z+=zrng+rnd(zrng*0.2)
- end
- end
- function spwnantichain(t,n,xmin,zrng)
- n=flr(n)
- local x=rnd(100)-50
- local z=105
- local xmin2=2*xmin
- for i=1,n do
- adden(x,z,t)
- local w=110+x-(x+xmin2)
- local rndo=rnd(w)-55
- if rndo>x-xmin then
- rndo+=xmin2
- end
- x=rndo
- z+=zrng
- end
- end
- function adden(x,z,t)
- local e={}
- e.x=x
- e.z=z
- e.t=t
- --defaults
- e.y=0
- e.vx,e.vy,e.vz=0,0,0.25
- e.w,e.h=16,16--width/height in px on spritesheet
- e.scl=1.5--scale
- e.sprx,e.spry = 64,16--sprite coordinates
- e.points,e.bonus = 100,0.05
- e.shadow,e.flip = false,false
- e.counter=0
- e.hp=1
- e.nudge=2
- e.parts={}
- if t==0 then--cat
- e.vz=0.4
- e.scl=1
- e.hp=6
- e.agetowiggle=rnd(30)
- e.parts.flip=e.flip
- local butt={}
- butt.sprx,butt.spry=0,16
- butt.x,butt.y,butt.z,butt.w,butt.h,butt.scl = 0,0,0,16,16,e.scl
- butt.xo,butt.yo,butt.zo=0,0,1.8
- add(e.parts,butt)
- elseif t==1 then --shrimp
- e.vz=0.25
- e.sprx,e.spry=64,64
- e.w=8
- e.hp=2
- e.scl=1
- e.offset=rnd(1)
- e.offset2=flr(rnd(20))
- elseif t==2 then --bat
- e.bonus = 0.2
- e.vz=0.25
- e.y=30
- e.sprx=80
- e.h=8
- e.shadow = true
- e.points = 200
- e.counter=rnd(3)
- elseif t==3 then --tank
- e.bonus = 0.6
- e.sprx=48
- e.hp=18
- e.points=1000
- e.range=35+rnd(20)
- e.state=0
- e.scl=4
- e.offset=rnd(1)
- e.nudge=0
- local butt={}
- butt.sprx,butt.spry=32,16
- butt.x,butt.y,butt.z,butt.w,butt.h,butt.scl = 0,0,0,16,16,e.scl
- butt.xo,butt.yo,butt.zo=0,0,3
- add(e.parts,butt)
- elseif t==4 then --apc
- e.bonus = 0.75
- e.sprx=112
- e.hp=10
- e.vz=0.45
- e.points=800
- e.scl=3
- e.counter=rnd(1)
- e.offset=rnd(1)
- e.nudge=0.1
- local butt={}
- butt.sprx,butt.spry=16,16
- butt.x,butt.y,butt.z,butt.w,butt.h,butt.scl = 0,0,0,16,16,e.scl
- butt.xo,butt.yo,butt.zo=0,0,2.5
- add(e.parts,butt)
- elseif t==5 then -- man
- e.bonus = 0.1
- e.hp=3
- e.flipcounter=rnd(1)
- e.w=8
- e.sprx=96
- e.points = 300
- e.vz=0.25+rnd(0.05)
- elseif t==6 then -- robot
- e.bonus = 0.15
- e.hp=6
- e.flipcounter=rnd(1)
- e.w=8
- e.sprx=104
- e.points = 400
- e.scl=2.1
- e.vz=0.15+rnd(0.05)
- e.shootang=-0.12
- elseif t==7 then -- gnome
- e.bonus = 0.3
- e.hp=8
- e.flipcounter=rnd(1)
- e.points = 300
- e.sprx,e.spry=32,64
- e.points = 400
- e.vz=0.1
- e.shootang=-0.12
- e.scl=2.2
- e.floory=e.h*e.scl*0.5
- e.airborn=false
- elseif t==8 then -- turtle
- e.bonus = 0.8
- e.w,e.h=32,32
- e.sprx,e.spry = 0,64
- e.points = 2000
- e.hp=30
- e.nudge=0
- e.state=0
- e.vz=0.25
- e.scl=3
- e.range=30+rnd(20)
- local butt={}
- butt.sprx,butt.spry=48,80
- butt.x,butt.y,butt.z,butt.w,butt.h,butt.scl = 0,0,0,16,16,e.scl*2
- butt.xo,butt.yo,butt.zo=0,0,6.5
- add(e.parts,butt)
- elseif t==9 then --plane
- e.bonus = 0.3
- e.vz=0.3
- e.y=30
- e.hp=4
- e.sprx,e.spry=80,64
- e.w=32
- e.shadow = true
- e.points = 300
- e.counter=rnd(3)
- e.scl=1.5
- e.offset=rnd(1)
- end
- e.y+=e.h*e.scl*0.5
- e.age=0
- e.hurt=0
- add(en,e)
- end
- function doen(i)
- if i.hurt>0 then
- i.hurt-=1
- end
- if i.z<100 then
- i.age+=1
- --cat
- if i.t==0 then
- if i.age>i.agetowiggle then
- i.agetowiggle+=5+rnd(20)
- i.flip=not i.flip
- i.parts[1].flip=i.flip
- end
- --shrimp
- elseif i.t==1 then
- i.counter+=1
- if p.x-i.x>30 then
- i.vx=0.15
- elseif p.x<-30 then
- i.vx=-0.15
- else
- i.vx=0
- end
- i.vx+=sin(0.01*i.age+i.offset)
- if (i.age+i.offset2)%20 ==0 then
- i.flip=not i.flip
- end
- --bat
- elseif i.t==2 then
- if fnum%28==0 then
- if i.spry==24 then
- i.spry=16
- else
- i.spry=24
- if i.z<70 then
- i.counter+=1
- if i.counter>=4 then
- eshoot(i.x,i.y,i.z, 0,-0.25,0.4, 8)
- i.counter=0
- end
- end
- end
- end
- -- tank
- elseif i.t==3 then
- if i.state==0 then
- if i.z<70 then
- i.state=1+flr(rnd(2))
- i.nudge=1
- end
- else
- i.counter+=1
- if i.x>64 then i.x=64 end
- if i.x<-64 then i.x=-64 end
- i.vx=sin(0.002*fnum+i.offset)*0.4+sin(0.009*i.age)*0.6
- if i.z>i.range then
- i.vz=0.25
- elseif i.vz>0 then
- i.vz*=0.9
- end
- if i.state==1 then
- if i.counter==100 or i.counter==160 then
- shootspread( i.x,7,i.z, 0.5, 8, 4+flr(rnd(3)), 0.03)
- elseif i.counter>300 then
- i.counter,i.state=0,2
- end
- else--i.state==2
- if i.counter%20==1 then
- shootat( i.x,i.y+20,i.z, p.x,7,p.z, 0.5, 8)
- elseif i.counter>=80 then
- i.counter,i.state=0,1
- end
- end
- end
- -- apc
- elseif i.t==4 then
- i.vx=sin(0.015*i.age+i.offset)*0.5
- if i.z<70 and i.z>20 then
- i.counter+=0.017
- if i.counter>=1 then
- i.counter=0
- shootbeamat( i.x,i.y+20,i.z, p.x,7,p.z, 0.55, 0.04, 3, 8)
- end
- end
- -- man
- elseif i.t==5 then
- i.vx=min(1,max(-1, i.vx+rnd(0.02)-0.01))
- if i.z<90 then
- i.flipcounter+=0.12
- if i.flipcounter>=1 then
- i.flip= not i.flip
- i.flipcounter=0
- end
- if i.z<60 then
- if i.z>20 then
- i.counter+=1
- if i.counter>=80 then
- shootat( i.x,i.y,i.z, p.x,p.y,p.z, 0.5, 12)
- i.counter=0
- end
- end
- end
- end
- -- robot
- elseif i.t==6 then
- if i.z<90 then
- i.vz=sin(i.age*0.01)*0.1+0.15
- i.flipcounter+=0.1
- if i.flipcounter>=1 then
- i.flip= not i.flip
- i.flipcounter=0
- end
- if i.z<60 then
- i.vx=min(1,max(-1, i.vx+rnd(0.04)-0.02))
- i.counter+=1
- if i.counter>=60 and i.counter<78 then
- if i.counter%4==0 then
- shootyangle(i.x,i.y,i.z, i.shootang , 0.5, 6)
- i.shootang+=0.06
- end
- end
- end
- end
- -- gnome
- elseif i.t==7 then
- if abs(i.x)>60 then
- i.x=min(60,max(-60,i.x))
- i.vx*=-1
- end
- if i.airborn then
- if i.y>i.floory then
- i.vy-=0.2
- else--landed
- sfx(21,3)
- i.vx=rnd(1)-0.5
- i.vy=0
- i.vz=0.05
- i.y=i.floory
- i.airborn=false
- end
- else
- i.flipcounter+=0.15
- if i.flipcounter>=1 then
- i.flip=not i.flip
- i.flipcounter=0
- end
- i.counter+=1
- if i.counter == 90 and i.z<70 then
- shootspread( i.x,i.y,i.z, 0.7, 10, 4, 0.005)
- elseif i.counter >= 95 then
- sfx(22,3)
- local angle=rnd(0.46)-0.23
- i.vx=sin(angle)
- i.vy=3
- i.vz=cos(angle)*0.7
- i.airborn=true
- i.counter=0
- i.flip=not i.flip
- end
- end
- --turtle
- elseif i.t==8 then
- if i.state==0 then
- if i.z<70 then
- i.state=1
- i.nudge=0.5
- end
- else
- i.counter+=1
- i.vx=sin(i.age*0.001)*0.3
- if i.z>i.range then
- i.vz=0.2
- elseif i.vz != 0 then
- i.vz=0
- end
- if i.state==1 or i.state==3 then
- if i.counter>140 then
- i.counter=0
- i.state+=1
- end
- elseif i.state==2 then
- if i.counter%40==20 then
- shootbeamat( i.x,i.y+20,i.z, p.x,p.y,p.z, 0.56, 0.04, 4, 14)
- elseif i.counter>120 then
- i.counter,i.state=0,3
- end
- else--i.state==4
- if i.counter%12==1 then
- shootyangle(i.x,12,i.z, sin(i.counter*.005)*.2, 0.45, 8)
- elseif i.counter>=200 then
- i.counter,i.state=0,1
- end
- end
- end
- elseif i.t==9 then
- i.vy=sin(0.008*i.age+i.offset)*0.3
- if i.counter<1 and i.z<50 then
- i.counter=1
- shootbeamat( i.x,i.y+8,i.z, p.x,7,p.z, 0.4, 0.04, 5, 8)
- end
- end
- end
- i.x+=i.vx
- i.y+=i.vy
- i.z-=i.vz
- if i.z<=0 then
- del(en,i)
- end
- end
- function damage(nme,amt)
- multiup()
- nme.hp-=amt
- nme.z+=nme.nudge
- if nme.hp<=0 then
- killen(nme)
- return
- end
- sfx(9+flr(rnd(4)),2)
- nme.hurt=3
- end
- function killen(i)
- getpoints(i.points,i.x,i.y,i.z)
- multibonus(i.bonus)
- if i.bonus<0.3 then
- sfx(15,3)
- else
- sfx(16,3)
- end
- addxpl(i.x, i.y, i.z, 40, false)
- del(en,i)
- end
- function drawen(i)
- local flashing=i.hurt>0
- drawsspr(i,i.shadow,flashing)
- if #i.parts>=1 then
- for k=1,#i.parts do
- i.parts[k].x=i.x+i.parts[k].xo
- i.parts[k].y=i.y+i.parts[k].yo
- i.parts[k].z=i.z+i.parts[k].zo
- drawsspr(i.parts[k],false,flashing)
- end
- end
- end
- function shootat(x,y,z, tx,ty,tz, spd, scl)
- eshoot(x,y,z, ((tx-x)/(tz-z))*-spd, ((ty-y)/(tz-z))*-spd, spd, scl)
- end
- function shootyangle(x,y,z, ang, spd, scl)
- eshoot(x,y,z, sin(ang)*spd*3,0,cos(ang)*spd, scl)
- end
- function shootxangle(x,y,z, vx, ang, spd, scl)
- eshoot(x,y,z, vx, sin(ang)*spd*2,cos(ang)*spd, scl)
- end
- function shootbeamat(x,y,z, tx,ty,tz, minspd, spdstep, n, scl)
- for i=0,n-1 do
- shootat( x,y,z, tx,ty,tz, minspd+spdstep*i, scl)
- end
- end
- function shootspread(x,y,z, spd, scl, num, step)--step is step in angles (.125 is a 45 degree angle)
- local cursr=(num-1)*step*-0.5
- for i=1,num do
- eshoot(x,y,z, sin(cursr)*spd*3,0,cos(cursr)*spd, scl)
- cursr+=step
- end
- end
- function eshoot(x,y,z, vx,vy,vz, scl)
- sfx(8,3)
- local bullet={}
- bullet.x=x
- bullet.y=y
- bullet.z=z
- bullet.vx=vx
- bullet.vy=vy
- bullet.vz=vz
- bullet.scl=1
- bullet.w=scl
- bullet.h=scl
- bullet.age=0
- add(be,bullet)
- end
- function dobe(i)
- i.age+=1
- i.x+=i.vx
- i.y+=i.vy
- i.z-=i.vz
- if i.z<0.1 or i.z>90 then
- del(be,i)
- end
- if i.y<0 then
- del(be,i)
- addsmk(i.x,0,i.z,i.w*0.1)
- end
- end
- function drawbe(i)
- local size=i.w*0.5
- if i.age<8 then
- size*=i.age*0.4
- end
- drawcirc(i.x, i.y, i.z, size, color(i.age*0.5%3), true)
- drawcirc(i.x, 0, i.z, i.w*0.3, 3, true)
- end
- --visualstuff
- function addsmkpuff(x,y,z,n,r)
- for i=0,n do
- local angle=rnd(1)
- local power=rnd(rnd(1))
- local smksize=rnd(1-power)
- power=power*r
- addsmk(x+sin(angle)*power, y+rnd(r-power), z+cos(angle)*power*0.15, smksize)
- end
- end
- function addsmkrnd(x,y,z,r,scl)
- addsmk(x+rnd(r)+rnd(r)-r, y+rnd(r)+rnd(r)-r, z, rnd(scl))
- end
- function addsmk(x,y,z,size)
- local smoke={}
- smoke.x=x
- smoke.y=y
- smoke.z=z
- smoke.age=1
- smoke.size=size
- smoke.grow=0.5+rnd(0.7)
- smoke.life=10+rnd(35)
- add(smk,smoke)
- end
- function dosmk(i)
- i.z-=0.15
- i.age+=1
- if i.age>i.life or i.z<1 then
- del(smk,i)
- end
- end
- function drawsmk(i)
- drawcirc( i.x, i.y, i.z, sqrt(i.age)*i.grow+i.size, 3, false)
- end
- function addxpl(x,y,z,scl,player)
- local xp={}
- xp.x=x
- xp.y=y
- xp.z=z
- xp.scl=scl
- xp.age=10
- if player then
- xp.age=0
- xp.offset=rnd(1)
- end
- add(xpl,xp)
- end
- function doxpl(i)
- i.age+=1
- if i.age>35 then
- del(xpl,i)
- end
- end
- function drawxpl(i)
- if i.age<10 then
- local colo=color(i.age%3)
- local anglo=0.07*(i.x+sqrt(i.age))+i.offset
- drawcross( i.x, i.y, i.z-0.1, 8*(10-i.age), anglo, 8)
- drawcirc( i.x, i.y, i.z, 0.2*i.scl*(10-i.age), colo, false)
- elseif i.age<16 then
- drawcirc( i.x, i.y, i.z, i.scl, color(0.5*i.age%3), true)
- else
- drawcirc( i.x, i.y, i.z, i.scl*i.age*0.04, 8, false)
- end
- end
- function getpoints(amt, x, y, z)
- local points=amt*scrmulti
- score+=ceil(points*.01)
- addpts(points,x,y,z)
- end
- function addpts(amt,x,y,z)
- local point={}
- local t=tostring(amt)
- point.c=#t
- for i=1,point.c do
- point[i]= sub(t,i,i+1)
- end
- local ok=ztoscalar(z)
- point.x=xcoord(x,ok)
- point.y=ycoord(y,ok)
- point.age=50+amt*0.05
- add(pts, point)
- end
- function dopts(i)
- i.age-=1
- if i.age<=0 then
- del(pts, i)
- end
- end
- -- player
- function drawpts(i)
- cursorx=i.x-i.c*2
- cursory=i.y-5
- for j=1,i.c do
- cursorx += 4
- print (i[j], cursorx, cursory+5*sin(0.02*(j*2+i.age)), color((i.age*0.1)%3))
- end
- end
- function playerupdate()--occurs in game or level screen
- if pstate==1 then return end
- if p.z<5 then
- p.z=min(5,p.z+0.1)
- end
- if p.y<=7 then
- pjog()
- else --airborn
- if pairborn() then
- sfx(13,3)
- p.vy=0
- p.y=7
- p.vx=min(1.2,max(-1.2,p.vx))
- addsmkpuff(p.x,0,p.z,4,16)
- elseif fnum%5==0 then
- addsmkrnd(p.x,p.y,p.z,4,1)
- end
- end
- end
- function playerlateupdate()
- if pstate==1 then return end
- applypvx()
- end
- function playermotor()--occurs only in game, not in level screen
- if pstate==1 then
- if pstatecount() then
- pspawn()
- end
- return end
- if pstate==2 then
- if pstatecount() then
- pstate=0
- end
- end
- if p.y<=7 then
- --directional control
- if btn(0) then
- p.vx=max(-1.2,p.vx-0.4)
- elseif btn(1) then
- p.vx=min(1.2,p.vx+0.4)
- else
- if p.vx>0 then
- p.vx=max(0,p.vx-0.4)
- elseif p.vx<0 then
- p.vx=min(0,p.vx+0.4)
- end
- end
- --jump
- if xpressed() then
- sfx(6,3)
- addsmkpuff(p.x, 0,5,6,25)
- p.vy=4.5
- if btn(0) then
- p.vx=-1.8
- elseif btn(1) then
- p.vx=1.8
- else
- p.vx=0
- end
- p.y+=p.vy*2
- jogstate=0
- jogcount=0
- if (p.vx>0.1) then
- p.sprx=64
- elseif (p.vx<-0.1) then
- p.sprx=48
- else
- p.sprx=0
- end
- end
- end
- --shoot
- if p.refire>0 then
- p.refire-=1
- elseif btn(4) then
- pshoot()
- p.refire=6
- end
- end
- function pjog()--jog
- if jogstate==1 then
- jogcount+=0.05
- p.sprx=16
- elseif jogstate==3 then
- jogcount+=0.05
- p.sprx=32
- else
- jogcount+=0.2
- p.sprx=0
- end
- if jogcount>1 then
- jogcount=0
- if jogstate==0 then
- addsmk(p.x-4,4,p.z,1)
- sfx(14,2)
- elseif jogstate==2 then
- addsmk(p.x+4,4,p.z,1)
- sfx(14,2)
- end
- jogstate=(jogstate+1)%4
- end
- end
- function pairborn()
- p.vy-=0.3
- p.y+=p.vy
- if p.y<=7 then--land
- return true
- end
- return false
- end
- function pstatecount()
- pstatecounter-=1
- return pstatecounter<=0
- end
- function playerkill()
- sfx(19,1)
- addxpl(p.x, p.y, p.z, 40, true)
- pstatecounter=60
- pstate=1
- p.y=7
- end
- function pspawn()
- multiset(0.5)
- lives-=1
- if lives<0 then
- entergameover()
- else
- preset()
- end
- end
- function preset()
- jogstate=0
- jogcount=0
- pstatecounter=180
- pstate=2
- p.x=0
- p.y=7
- p.z=0.1
- end
- function applypvx()
- p.x+=p.vx
- if p.x<-60 then
- p.x=-60
- p.vx=0
- elseif p.x>60 then
- p.x=60
- p.vx=0
- end
- end
- function drawplayer()
- if pstate==1 or ( pstate>=2 and flr(fnum*0.5)%2==0 )then --flash when invincible
- return
- end
- local pycache=p.y
- if p.y==7 then
- if jogstate==1 or jogstate==3 then
- p.y-=8*sin(jogcount*0.5)
- end
- end
- drawsspr(p,false, false)
- p.y=pycache
- end
- function pshoot()
- sfx(7,2)
- local shot={}
- shot.x=p.x
- shot.y=p.y
- shot.z=5
- shot.w=12
- shot.h=12
- shot.scl=1
- add(bp,shot)
- end
- function dobp(i)
- i.z+=1
- if i.z>70 then
- multidown()
- del(bp,i)
- end
- end
- function drawbp(i)
- drawcirc(i.x, i.y, i.z, i.w*0.4, 8, false)
- end
- -- collisions
- function colenbp(i)
- for j=1,#en do
- if checkcol(en[j],i) then
- damage(en[j],1)
- del(bp,i)
- return
- --hitfx
- end
- end
- end
- function colenp(i)
- if checkcol(i,p) then
- playerkill()
- end
- end
- function colbep(i)
- if checkcol(i,p) then
- playerkill()
- addsmk(i.x,0,i.z,i.w*0.1)
- del(be,i)
- end
- end
- --scenery
- function drawflr()
- local y
- for z=fnum*-0.25%14, 100, 14 do
- y=ycoord(0,ztoscalar(z))+1
- line(0, y, 140, y, 3)
- end
- end
- --gamestate/menu
- function newgame()
- multiset(0.5)
- smk={}
- xpl={}
- pts={}
- score=0
- lives = 4
- lvlnum=0
- lvlround=0
- preset()
- enterlevel()
- newhi=false
- end
- function tweenui()
- menutween+=1
- if menutween>=30 then
- return true
- end
- return false
- end
- function domenu()
- menutime+=1
- if menutween!=0 then
- if tweenui() then
- newgame()
- end
- else
- if xpressed() or zpressed() then
- menutween=1--close menu
- sfx(18,3)
- end
- end
- dotitle()
- end
- function dolevel()
- menutime+=1
- if menutween!=0 then
- if tweenui() then
- entergame()
- end
- else
- if menutime>300 or (xpressed() or zpressed()) then
- menutween=1--close menu
- sfx(18,3)
- end
- end
- end
- function dogameover()
- menutime+=1
- if menutween!=0 then
- if tweenui() then
- entermenu()
- end
- else
- if xpressed() or zpressed() then
- menutween=1--close menu
- sfx(18,3)
- end
- end
- foreach(gmovr,dogmovr)
- end
- function drawmenu()
- local t=menutween*3
- local hstxt="hi:"..hiscoretxt
- namebar("\148\139\131\144\145\151\150\129\144\151\142\135\135\129\144\142\143\143\143\129\144", -1-abs(menutween),3,0,false,true)
- namebar(" - 3cjam 2017 - @taeckerwyss", 120+abs(menutween),3,0,true)
- rectfill(2+t,3, 2+t+4*#hstxt,5, 0)
- print(hstxt,2+t,2,8)
- print("\139/\145 - move",40-t*3,74,8)
- print(" x - jump",40-t*3,90,8)
- print(" z - shoot",40-t*3,82,8)
- if menutween!=0 or flr(fnum*0.07)%4>0 then
- printcenter("press start",0,110-menutween*4,8)
- end
- if newhi and menutween==0 and flr(fnum*0.05)%3>0 then
- print("new!",#hstxt*4-4,5,color(0.5*fnum%3))
- end
- end
- function drawlevel()
- local t=menutween*3
- line(0,62+t, 128,62+t, 8)
- printcenter("zone "..lvlnum,0,64+t,8)
- line(0,71+t, 128,71+t, 8)
- printcenter("love is "..max(0,1001-lvlnum).."00 miles away",t,72+t,8)
- print("cruiser kid \144\144\144",16-t,57+t,8)
- end
- function drawgameover()
- namebar("game over - well played - try again? - ", 7-abs(menutween),3,0,false)
- namebar("[hint] - your multi drains if you miss shots - ", 112+abs(menutween),3,0,true)
- printcenter("hiscore",0,82+menutween*4,8)
- printcenter(hiscoretxt,0,90+menutween*4,8)
- foreach(gmovr,drawgmovrcirc)
- foreach(gmovr,drawgmovr)
- if newhi and menutween==0 and flr(fnum*0.07)%4>0 then
- print("new!",80,79,color(0.5*fnum%3))
- end
- end
- function entermenu()
- sfx(17,2)
- menutween=-30
- gamestate="menu"
- menutime=0
- end
- function enterlevel()
- sfx(17,2)
- p.refire=3
- bp={}
- be={}
- en={}
- nextlevel()
- menutween=-30
- gamestate="level"
- menutime=0
- end
- function entergameover()
- sfx(20,3)
- if score>hiscore then
- sethiscore(score)
- newhi=true
- else
- newhi=false
- end
- startgmovr()
- menutween=-30
- gamestate="gameover"
- menutime=0
- end
- function entergame()
- gamestate="game"
- end
- function gethiscore()
- hiscore=dget(0)
- hiscoretxt="$ "..hiscore.."00"
- end
- function sethiscore(i)
- hiscore=i
- hiscoretxt="$ "..hiscore.."00"
- dset(0,hiscore)
- end
- function addlife()
- lives+=1
- sfx(23,1)
- lifeplus=60
- end
- function drawlifeplus()
- if lifeplus<=0 then return end
- print("+1", 23, 100+lifeplus*0.25, color(1+fnum*0.25%2))
- end
- function drawhud()
- rectfill(0,108,128,128,0)
- local scrstring="$ "..score.."00"
- print(scrstring,124-#scrstring*4,112,8)
- scrstring="hi:"..hiscoretxt
- print(scrstring,124-#scrstring*4,121,3)
- line(34,109, 34,128, 3)
- line(66,109, 66,128, 3)
- line(40,126, 60,126, 3)
- pset(40,125,3)
- pset(45,125,3)
- pset(50,125,3)
- pset(55,125,3)
- pset(60,125,3)
- line(40,126, 40+multi*5,126, 8)
- line(40,125, 40+multi*5,125, 8)
- local multicolor=3
- if scrmulti>1 then
- multicolor=8
- end
- print("multi", 41,110,3)
- print("x"..scrmulti, 47,116,multicolor)
- local colr=3
- if lives==0 and flr(fnum*0.04)%2==0 then
- colr=8
- end
- print("\134", 8, 109, colr)
- print("\137x"..lives, 8, 112, colr)
- print("zone-"..lvlnum,3,121,3)
- drawlifeplus()
- end
- function addtitle()
- local ts={224,225,226,227,228,229,225,230,227,231}
- for i=1,10 do
- local letr={}
- letr.x=-110+20*i
- if (i>7) letr.x+=16
- letr.y=60
- letr.z=100
- letr.cntrz=20+abs(letr.x*0.12)
- letr.cntry=60
- letr.sp=ts[i]
- add(title,letr)
- end
- end
- function dotitle()
- local anglo
- for i=1,10 do
- anglo=menutime*0.02-i*0.1
- title[i].z=(title[i].cntrz-abs(menutween)*3)+sin(anglo)*2
- title[i].y=(title[i].cntry+abs(menutween)*4) +cos(anglo)*5
- title[i].x+=cos(menutime*0.0039+i*0.01)*0.25
- end
- end
- function drawtitle(i)
- for k=1,5 do
- drawspr(i.sp,i.x,i.y,i.z+k*6,1,2,true,true)
- end
- drawspr(i.sp,i.x,i.y,i.z,1,2,true,false)
- end
- function addgmovr()
- local xgutter=36
- local gap =(128-xgutter*2)/3
- local letterz={64,72,80,88,96,104,88,112}
- for i=0,7 do
- letter={}
- letter.x=xgutter+gap*(i%4)
- letter.y=45+gap*flr(i/4)
- letter.age=0-i*10
- letter.sprx=letterz[i+1]
- letter.spry=96
- add(gmovr,letter)
- end
- end
- function startgmovr()
- for i=1,#gmovr do
- gmovr[i].age=0-(i-1)*10
- end
- end
- function dogmovr(i)
- i.age+=1
- if i.age==35 then
- sfx(21,1)
- end
- end
- function drawgmovrcirc(i)
- if i.age>=35 and i.age<50 then
- if i.age>37 then
- mcirc(i.x,i.y ,3*sqrt(i.age-30) ,color(rnd(3)) )
- else
- mcircfill(i.x,i.y ,16 ,8 )
- end
- end
- end
- function drawgmovr(i)
- if (i.age<0) return
- local scale
- if i.age<35 then
- scale=1+(35-i.age)*0.1
- else
- scale=1
- end
- if menutween>0 then
- scale*=(30-menutween)*0.033
- end
- local myx=i.x-scale*4
- local myy=i.y-scale*4
- local myw=scale*8
- sspr( i.sprx, i.spry, 8, 8, myx, myy, myw, myw)
- end
- function namebar (t, yloc,c1,c2,reverse,double)
- rectfill(0, yloc+1, 128, yloc+3, c2)
- local length=#t*4
- if double then length*=2 end
- local ok=fnum
- if reverse then ok*=-1 end
- ok=ok*0.5%length
- print(t, ok, yloc, c1)
- print(t,ok-length, yloc, c1)
- end
- function printcenter(txt,xoffset,y,col)
- print(txt,xoffset+64-2*#txt,y,col)
- end
- -- draw in 3d
- function drawcirc(x, y, z, r, c, fill)
- if (z<0) return
- local ok=ztoscalar(z)
- local cue={xcoord(x,ok), ycoord(y,ok), getscale(r,ok), c}
- cue.z=z
- cue.type=1
- if fill then
- cue.type=2
- end
- add(todraw,cue)
- end
- --cue scaled sprite
- function drawsspr(i,shadow, flash)--i must have parameters: sprx, spry, x, y, z, w, h, scl
- if (i.z<0) return
- local ok=ztoscalar(i.z)
- local scaleo=getscale(i.scl,ok)
- local scalw=ceil(scaleo*i.w)
- local scalh=ceil(scaleo*i.h)
- local xcrd=xcoord(i.x,ok)
- local ycrd=ycoord(i.y,ok)
- local cue={i.sprx, i.spry, i.w, i.h, xcrd-0.5*scalw, ycrd-0.5*scalh, scalw, scalh, i.flip, flash}
- cue.type=0
- cue.z=i.z
- add(todraw,cue)
- if shadow and i.z<80 then
- local shadowy=ycoord(0,ok)
- mcircfill(xcrd,shadowy,scalw*0.2,3)
- end
- end
- --cue unscaled sprite (don't use for colliders)
- function drawspr(sp,x,y,z,w,h,shadow, flash)--w and h are in sprites
- if (z<0) return
- local ok=ztoscalar(z)
- local xcrd=xcoord(x,ok)
- local ycrd=ycoord(y,ok)
- local cue={sp, xcrd-w*4, ycrd-h*4, w, h, flash}
- cue.type=4
- cue.z=z
- add(todraw,cue)
- if shadow and z<80 then
- local shadowy=ycoord(0,ok)
- mcircfill(xcrd,shadowy,w*3,3)
- end
- end
- function drawcross(x,y,z,r,ang,c)
- if (z<0) return
- local ok=ztoscalar(z)
- local ctrx=xcoord(x,ok)
- local ctry=ycoord(y,ok)
- cue={ctrx,ctry,r,ang,c}
- cue.z=z
- cue.type=3
- add(todraw,cue)
- end
- function dcross(x,y,r,a,c)
- pset(x,y,11)
- local cosa=cos(a)
- local sina=sin(a)
- line( x-cosa*r, y-sina*r, x+cosa*r, y+sina*r, c)
- line( x-sina*r, y+cosa*r, x+sina*r, y-cosa*r, c)
- end
- function drawtodraw(i)
- if i.type==0 then
- if i[10] then pal(3,0) pal(8,3) end
- sspr(i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8],i[9])
- if i[10] then pal(3,3) pal(8,8) end
- elseif i.type==1 then
- mcirc(i[1],i[2],i[3],i[4])
- elseif i.type==2 then
- mcircfill(i[1],i[2],i[3],i[4])
- elseif i.type==3 then
- dcross(i[1],i[2],i[3],i[4],i[5])
- elseif i.type==4 then
- if(i[6]) then pal(8,3) end
- spr(i[1], i[2], i[3], i[4], i[5])
- if(i[6]) then pal(8,8) end
- end
- end
- function zsort(data)
- local n=#data
- if (n<2)return
- for i=flr(n/2)+1,1,-1 do
- local parent,value,m=i,data[i],i+i
- local key=-value.z
- while m<=n do
- --find the max child
- if ((m<n) and (-data[m+1].z > -data[m].z)) m+=1
- local mval=data[m]
- if (key > -mval.z) break
- data[parent] = mval
- parent=m
- m+=m
- end
- data[parent] = value
- end
- --read out values
- for i=n, 2, -1 do
- --swap root w last
- local value = data[i]
- data[i], data[1] = data[1], value
- --restore the heap
- local parent,term,m= 1,i-1,2
- local key=-value.z
- while m <= term do
- local mval=data[m]
- local mkey=-mval.z
- if m<term and -data[m+1].z>mkey then
- m+=1
- mval=data[m]
- mkey=-mval.z
- end
- if(key>mkey) break
- data[parent]=mval
- parent=m
- m+=m
- end
- data[parent]=value
- end
- end
- --------helpers--------------------------------
- function checkcol(a,b)--a and b are tables with x,y,z,w,h,scl values
- local w=(a.w*a.scl+b.w*b.scl)*0.5
- local h=(a.h*a.scl+b.h*b.scl)*0.5
- if abs(a.x-b.x)<w and abs(a.y-b.y)<h and abs(a.z-b.z)<1 then
- return true
- end
- return false
- end
- function xcoord(x,z)
- return lerp(x*1.886,0,z)+64
- end
- function ycoord(y,z)
- return lerp((96-y)*1.886,20,z)
- end
- function getscale(r,z)
- return max(0,(1-z)*r*1.886)
- end
- function ztoscalar(z)
- return sqrt(sqrt(z*0.01))
- end
- function color(i)
- if i<1 then return 0 end
- if i<2 then return 3 end
- return 8
- end
- function lerp(la,lb,li)
- return la+li*(lb-la)
- end
- function ceil(num)
- return flr(num+0x0.ffff)
- end
- function round(num)
- return flr(num+0.5)
- end
- function tostring(n)
- return ""..n
- end
- function xpressed()
- if btn(5) and xdown==false then
- return true
- end
- return false
- end
- function zpressed()
- if btn(4) and zdown==false then
- return true
- end
- return false
- end
- --minskycricle by@musurca, @felice, and @ultrabrite
- function mcirc(x,y,r,c)
- x,y=x+0.5,y+0.5
- local j,k,rat=r,0,1/r
- poke(0x5f25,c) --set color
- for i=1,0.785*r do
- k-=rat*j
- j+=rat*k
- pset(x+j,y+k)
- pset(x+j,y-k)
- pset(x-j,y+k)
- pset(x-j,y-k)
- pset(x+k,y+j)
- pset(x+k,y-j)
- pset(x-k,y+j)
- pset(x-k,y-j)
- end
- pset(x,y-r)
- pset(x,y+r)
- pset(x-r,y)
- pset(x+r,y)
- end
- function mcircfill(x,y,r,c)
- x,y=x+0.5,y+0.5
- local j,k,rat=r,0,1/r
- poke(0x5f25,c) --set color
- for i=1,r*0.786 do
- k-=rat*j
- j+=rat*k
- rectfill(x+k,y+k,x+j,y-k)
- rectfill(x-k,y+k,x-j,y-k)
- rectfill(x-k,y-j,x-k,y+j)
- rectfill(x+k,y-j,x+k,y+j)
- --rectfill(x+j,y+k,x+j,y-k)
- --rectfill(x-j,y+k,x-j,y-k)
- --rectfill(x-k,y-j,x-k,y+j)
- --rectfill(x+k,y-j,x+k,y+j)
- end
- rectfill(x,y-flr(r),x,y+flr(r))--flooring these values reduces ugly 3-vertical-pixel "circles", but causes uneven edges
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement