forked from drludos/meteorain-gba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainMINIFIED.lua
1 lines (1 loc) · 4.98 KB
/
mainMINIFIED.lua
1
playerX=0;playerY=-16;playerAnim=0;playerFlipX=nil;foes={}foesMax=14;foesTimer=0;for a=0,foesMax,1 do table.insert(foes,{active=0,x=math.random(224),y=-16,speedX=0,speedY=0})end;STATE=0;ticks=0;score=0;highscore=-1;ticks_anim=0;screenshake=0;fade(1)txtr(0,"overlay.bmp")txtr(1,"tiles.bmp")txtr(2,"tiles.bmp")txtr(4,"sprites.bmp")for a=0,19,1 do for j=0,29,1 do tile(3,j,a,62)end end;for a=0,40,1 do tile(3,math.random(29),math.random(16),62+math.random(9))end;for a=0,29,1 do tile(2,a,17,a+2)tile(2,a,18,a+32)tile(2,a,19,1)tile(2,a,20,1)end;priority(0,2,3,3)function init()ticks=0;score=0;foesTimer=60;screenshake=0;scroll(2,0,0)playerX=112;playerY=140;playerFlipX=nil;playerAnim=1;foes={}for a=0,foesMax,1 do table.insert(foes,{active=0,x=math.random(224),y=-16,speedX=0,speedY=0})end;for a=0,19,1 do for j=0,30,1 do tile(0,j,a,1)end end;music("music.raw",0)end;function update()ticks=ticks+1;if ticks>3601 then ticks=1 end;local ticks=ticks;if STATE==1 then local playerX=playerX;local playerY=playerY;local playerAnim=playerAnim;local playerFlipX=playerFlipX;local screenshake=screenshake;local foesTimer=foesTimer;local score=score;local b=ticks%5==0;if btn(5)then playerX=playerX+3;if playerX>225 then playerX=225 end;playerFlipX=nil;if b then playerAnim=playerAnim+1;if playerAnim>4 then playerAnim=1 end end elseif btn(4)then playerX=playerX-3;if playerX<-1 then playerX=-1 end;playerFlipX=1;if b then playerAnim=playerAnim+1;if playerAnim>4 then playerAnim=1 end end else playerAnim=1 end;local c=ticks%8;local d=playerX+16;local e=playerY+16;for a=1,14,1 do local f=foes[a]if f.active==1 then f.y=f.y+f.speedY;if c==0 and f.y<145 then f.speedY=f.speedY+1 end;if playerX<f.x+16 and d>f.x and playerY<f.y+16 and e>f.y then f.active=0;f.x=math.random(224)f.y=-16;f.speedY=0;sound("sfx_gameover.raw",0)music()playerAnim=5;fade(1,0xFFFFFF,nil,1)ticks_anim=180;STATE=2 end;if f.y>=145 then score=score+1;f.active=0;f.x=math.random(224)f.y=-16;f.speedY=0;screenshake=3;if score<27 then sound("sfx_crash.raw",0)end end end end;if foesTimer>1 then foesTimer=foesTimer-1 else spawnFoe()if score<2 then foesTimer=60 elseif score<8 then foesTimer=40 elseif score<12 then foesTimer=30 elseif score<15 then foesTimer=20 elseif score<30 then foesTimer=10 elseif score<40 then foesTimer=9 elseif score<60 then foesTimer=8 elseif score<80 then foesTimer=7 else foesTimer=6 end end;if screenshake>0 then screenshake=screenshake-1;if screenshake>0 then scroll(2,0,2)else scroll(2,0,0)end end;_G.playerX=playerX;_G.playerY=playerY;_G.playerAnim=playerAnim;_G.playerFlipX=playerFlipX;_G.screenshake=screenshake;_G.foesTimer=foesTimer;_G.score=score elseif STATE==2 then if ticks_anim>0 then ticks_anim=ticks_anim-1;if ticks_anim==179 then for a,f in ipairs(foes)do f.active=1;f.x=playerX+5-math.random(9)f.y=playerY-5+math.random(7)f.speedX=3-math.random(7)f.speedY=-(2+math.random(4))end;screenshake=0;scroll(2,0,0)end;if ticks_anim==130 then for a=0,30,1 do tile(0,a,0,1)end;print("GAME OVER",10,4)if score<100 then print("score:"..tostring(score),11,8)else print("score:"..tostring(score),10,8)end;if score>highscore then print("NEW RECORD!",9,10)highscore=score else if score<100 then print("best:"..tostring(highscore),12,10)else print("best:"..tostring(highscore),11,10)end end end;if ticks_anim<120 and ticks_anim>=20 then fade((ticks_anim-20)/100,0xFFFFFF,nil,1)end;if ticks_anim==0 then ticks=29 end else j=ticks%60;if j==30 then print("press button to restart",4,15)elseif j==0 then for a=4,26,1 do tile(0,a,15,1)end end;if btnp(0)or btnp(1)then STATE=3;ticks_anim=60 end end;local c=ticks%7;for a,f in ipairs(foes)do if f.active==1 then f.x=f.x+f.speedX;f.y=f.y+f.speedY;if c==0 then f.speedY=f.speedY+1 end;if f.y>240 then f.active=0;f.x=math.random(224)f.y=-16;f.speedY=0;f.speedX=0 end end end elseif STATE==3 then if ticks_anim>0 then ticks_anim=ticks_anim-1;if ticks_anim>30 then fade(1-(ticks_anim-30)/30,0x000000,1,1)elseif ticks_anim==30 then init()elseif ticks_anim>0 then fade(ticks_anim/30,0x000000,1,1)else STATE=1 end end elseif STATE==0 then if ticks_anim>0 then ticks_anim=ticks_anim-1;if ticks_anim==59 then print("METEORAIN",10,4)print("a game by",21,15)print("Dr.LUDOS",22,16)print("music by",0,15)print("WARLORD",0,16)end;if ticks_anim>=0 then fade(ticks_anim/60,0x000000,1,1)end else j=ticks%60;if j==30 then print("press button to start",5,10)elseif j==0 then for a=5,25,1 do tile(0,a,10,1)end end;if btnp(0)or btnp(1)then STATE=3;ticks_anim=60 end end end end;function draw()local playerX=playerX;local playerY=playerY;local playerAnim=playerAnim;local playerFlipX=playerFlipX;if STATE==1 then spr(playerAnim,playerX,playerY,playerFlipX)for a=1,14,1 do local f=foes[a]if f.active==1 then spr(0,f.x,f.y)end end else if ticks_anim~=180 then for a=1,14,1 do local f=foes[a]if f.active==1 then spr(6+a%4,f.x,f.y)end end end;spr(playerAnim,playerX,playerY,playerFlipX)end;spr(playerAnim,playerX,playerY,playerFlipX)end;function spawnFoe()for a=1,14,1 do local f=foes[a]if f.active==0 then f.active=1;return end end end;STATE=0;ticks_anim=60;while true do update()clear()draw()display()end