0 P2TvͫgE#2Tv2TvW^^=u2!ASgev3EwwwwfUUfUffUfUUfwwwwUUfwfUUUUfUUfUfUwfUUfffUfUfUffUffUU"""3D""""""""""D""3"D"3""݈̻̻̻̻̻̻̻̻̪̙̙̈""D3D3DDDDDDDD3D33""DDDDDD3D"DDDDD3D"D"3D"""D3"D3D̈fffUUUwUUwwwwffffUUUUUUUU"33""D"""fffUUUUUwwwww""f"Uf"Uf"Uf"fff"f""Uf"f"UfUfff"f"3UUfUUfUfUUfD3D""3"""D"3"33"D" ffffUUUUUUUU"33""D"""""""UUfUUfUfDUDfUff̪̻wwwwwwwwww̻wwwwwwwwwwwwwwwwwwwwwwwwwwwwww 33D333"D3"33333D3D33"33"33333D"3"333D33333""""""""D33D"3"""3D"3DD"3DD"DDDD33D"3DD"3DD"3DD"DDDDD3D"3DD"3DD"3DD"DDDD33D"3DD"3DD"3DD"DD333""3"D3"D""D3"3̻"̈DDDDD3"D"3D""DD"3DDDDDDDDD"3D3"DD""D3"DDDDDDDD3DD"3D""DD3DDDD"DDDDDDDD3333""DDD"3DD"3DDDD33"3"D"D"33D3333""33D3333333D3333̪""̪""3D3DD"""D33"D3333""3DD3DD33D3DD33D333333"̈̈̈̈̈ "̈̈̈̈̈ffUfUfUDfUUfUfUfUUUffUUfUfUfDUfDUfDUUfUDUfUDUfffffUfUUffUfUUfUUfUffffUfDUfDUfDUfUDfUDfffUfUfUDffffU"fUffffUUfUfUfDUfDUfDUUfUDUfUDUfffUffUfUDff"fffUffUfUfDUfDDfUUDffUDfUDf"""3"""""""""""3"3"3"""3""3"""""""""""3"3"3""3"3"""3"D"""""3"3"3"""3""3""""3D"""3"33""3"3"3fUfUffUUfffUfUfffUfffUfUDUfUUUfUUUfUUffUfUffffffUfUfffUfUfffUffffffDfUUfUffUUffUfUfffffUfUfffffffffUffDUffUffUffUffUfUfffffffUfDUffUffUffUffUfUffff"""""""""3""""""""""""""""3""""""""""3"""""""3""""""wwwwwwwww"www"DDwwD"""3""""""""""D"D3"3"3"""3""3"DD"""""""""DD"D3"3"3""3"3D"""3"D"""D""D3"3"3"""3""3"D"""3D"DDD""D3"33""3"3"3wwwwwwwwwDDDDwwDDww"""""""DD""3"""""""""""D"""""DDD3"""""""DDD""DDDD"3""""""DDDD"3""""""DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"DDDDDDDDDDDDDDDD"DDDDDDDD"""3"""""""""""3"3"3"""3""3"""""""""""3"3"3""3"3"""3"D"""""3"3"3"""3""3""""3D"""3"33""3"3"3DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"""""""""3""""""""""""""""3""""""""""3"""""""3""""""~################ ########0### ### ## # ##  # 0  @   0  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$              0    @  0             @                                   $$$$$$$$$$$$$$$$$$$$$$$ @ @ 00  0  0 0 0 0      @  @     $$$$$$$$ $$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$ $$$$$$$$$$ $$ $$$ $$$$$$$$$$$$$$ $$$$$$$$ $$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$                                     5                                         OONN M0LK0K0J0HPGPFPE@D`B`Ap@ BDEFGIIJKLMNO ) @ @ ` @ @ @ ` @ @ ` @ @ ` @ @ @ ` @ @ @ ` @ @ ` @ @ ` @ `@@`@@@`@@`@@@`@@@@`@@@`@@`@ @ ` @ ` ` ` ` ` ` ` `` ` ` `` ` aa a a aa aBBBB B B  @  @  @   @   @  @        @ @ @ @ @ @ @ @ @ ` ` ` `aaaa ```````` ` ` @ ` ` ` ` @ @ ` @ @ ` @ @ ` @ @ @ ` @ @ @ ` @ @ ` @ ` ` ` ` @ @ ` @ @ ` @@@`@ @ ` @ ` @ @ ` @ @ ` @ @ ` @ @ @ ` @  ! ! ! !  ! ! ! ! @ @ @ @@@@@ @ @ @ @ @ @ @ @     @ @ @ @@@@@ @ @ @ @ @ @ @ @`````````` `` ``````````` `` `           ` ` `` ` ` ```@``````**J***J****J*J*JJJJ   `````````` `````````````` ``````````````````````` `` `` `` `` `` `` `` `aaaa ```` ` ` ` ` ` 00DaL<P$MT ?DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD!"!"!"!"!"!"!""!!"!""ABDBDBDBDBDBDBDD"!!"AB!D$ADDADBDBDBDBDBDBDBD!D$AA!D$ADA$D!DADDDDDDDDA$DA$BA$DAAADA!A$AD"D"D"D"D"D"D"D"ADDADA$B$A$BA"DAADADADADADADADADDADDDDDDANwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUffUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUffUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUffUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwffffffffffUUUUUUUUUUwUUUUUUUUww"33"ww"D"ww""www<<D!B!B43!B!B 3!! "<!B!B4!B!! !B1<!!B4<!B4!B !B! ! !B1!B4!! !B41<! !B41!B A !2313 ! @00 fffUffUfUfUfUfUffUffUfffUUUUff"""fffUff""f"fUffUfUfUUUfUf"f"fUfU"UfUffUffUUf"fUffUffffUf"ffUU"fffUUUUUU""""f"ff fffwff"f"f""fUffUfʬ fUffUfUUUUUUUfUf UfUUfUfff"f" UfU""UUfUfUfUffUf"Uf"fUfUffUffUffUUwUf"Uf"fffff fffUUfffff"fUUUU UUUUff"""""""ff ff"""f"UUfUff""f"f"f"fUffUfʬfUff""f"f""fwfUfUUUUUfUf UfUUUUUUf"f"fff f"f"ff"f"UfUUfU"""UfUfUfU"UUfUfUffUUf"Uf"Uf"fUffUffUffUUf"fUfffffUf"Uf"Uf"ff ffffUf"fffUwUU"fffffffUUUU UU"fff"ffUUfUUUUUUUUUUUUUUUUUUUUUUUUUU3"3"3"3"3"3"3"3"3"3"3"3"3"3"3"3"3fwffwffwffwffwffwffwffwffwffwffwffwffwf"UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUfUUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfUUfffffffffffffffffffffffffffffffUUUUUUUUUUUUUUUUUwUwUwUwUwUwUwUwUwUwUwUwUwUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUfUffUUffUUffUUffUUffUUffUUffUUffUUffUUffUUffUUffUUffUUfUx-- title: Dragoon -- author: DjPoke -- desc: shoot'em up -- site: https://cpclike.com -- license: MIT License -- version: 0.9.6 -- script: lua -- ===================================== -- Faking the Amstrad CPC : -- 1) Doubling horizontal pixels -- 2) 16 colors from the 27 CPC palette -- (each RGB value can be &00,&80 -- or &ff) -- 3) Square waveform for sounds -- ===================================== -- constants DEBUG_MODE=false -- activate debug mode MAX_DFIRE=6 -- max. dragon's fireballs MAX_DEGG=4 -- max. dragon's eggs MAX_SAUCER=4 -- max. flying saucers in the screen DEGG_SPEED=1.0 -- fall speed for dragon's eggs EXPLOSION_SP_MIN=260 -- sprites for explosion EXPLOSION_SP_MAX=264 MAX_STARS = 64 -- max stars in the starfield SPACE_BASE=18 -- space base sprites OPENED_SPACE_BASE=34 SAUCER_SP=259 ROACH_SP={291,292,293} SHIP1_SP=309 SHIP2_SP=307 DFIRE_SP=273 -- dragon's fire sprite image DEGG_SP=289 -- dragon's egg sprite image SFIRE_SP=275 -- saucer's fire sprite image RFIRE_SP=294 -- roach's fire sprite image BOSS_SP={336,338} -- boss sprite images (top left) BOSSHEAD_SP=340 -- boss head sprite image BOSSFIREHEAD_SP=342 -- boss fire head sprite image BFIRE_SP=276 BOSS_PAIN_TIMER=60 BOSS_FIRE_SPEED=1 DRAGON_DIST=6 -- max. distance from dragon's bodyparts DIAMOND={128,129,130} -- bonus sprites images HEART={131,132} SHIELD={133,134,135,136} MIN_BONUS=128 -- sprites values for bonus MAX_BONUS=136 VOID_ROACH=240 -- used for reset level purpose VOID_SHIP1=241 VOID_SHIP2=242 VOID_DIAMOND=243 VOID_HEART=244 VOID_SHIELD=245 VOID_BOSS=246 SLEEPING_ROACH=16 FIRST_LEVEL=1 -- first level of the game LAST_LEVEL=5 -- last level of the game BOSS_SCREEN_LIMIT=210 INTRO=0 -- game state : intro PLAYING=1 -- playing GAMEOVER=2 -- game over INTERLEVELS=3 -- between two levels -- tables dragon={ sp={ head={256}, headFire={256,272,288,304}, body={257} }, pos={ head={ x=16, y=26 }, body={ {x=12,y=26}, {x=8,y=30}, {x=4,y=34}, {x=4,y=38}, {x=4,y=42}, {x=8,y=46} } }, fire=false, frame=1 } -- dfire={} for i=1,MAX_DFIRE do dfire[i]={x=0,y=0,on=false} end -- degg={} for i=1,MAX_DEGG do degg[i]={x=0,y=0,fs=0,on=false} end -- saucer={} sfire={} for i=1,MAX_SAUCER do saucer[i]={x=0,y=0,ym=0,r=0,a=0,stp=0,on=false} end -- roach={} rfire={} -- ship1={} -- ship2={} -- boss={} bfire={} -- boss fire -- explosion={} -- star={} for i=1,MAX_STARS do star[i]={ x=math.floor(math.random(0,119))*2, y=math.floor(math.random(8,135)), s=math.floor(math.random(1,4)) } end -- vars cpt=0 -- timer cpt2=0 -- long timer cptmem=0 -- to memorize cpt2 timer score=0 lives=0 -- life count invincible=0 -- invincible ? level=0 -- current level dragonAlive=false -- is dragon alive ? xscroll=0 -- tiles scrolling tscroll=0 -- pixel scrolling -- start the game with INTRO gameState=INTRO music(1) -- functions ------------------------ function TIC() -- select game state if gameState==INTRO then drawIntro() checkButton() elseif gameState==PLAYING then animateWater() updateAllBonus() updateGame() drawGame() drawPanel() elseif gameState==GAMEOVER then drawGameOver() checkButton() elseif gameState==INTERLEVELS then drawInterLevels() checkButton() end end -- move the dragon function moveUL() dragon.pos.head.x=dragon.pos.head.x-1 dragon.pos.head.y=dragon.pos.head.y-1 -- move the tail tailUp(DRAGON_DIST) tailLeft(DRAGON_DIST) end function moveUR() dragon.pos.head.x=dragon.pos.head.x+1 dragon.pos.head.y=dragon.pos.head.y-1 -- move the tail tailUp(DRAGON_DIST) tailRight(DRAGON_DIST) end function moveDL() dragon.pos.head.x=dragon.pos.head.x-1 dragon.pos.head.y=dragon.pos.head.y+1 -- move the tail tailDown(DRAGON_DIST) tailLeft(DRAGON_DIST) end function moveDR() dragon.pos.head.x=dragon.pos.head.x+1 dragon.pos.head.y=dragon.pos.head.y+1 -- move the tail tailDown(DRAGON_DIST) tailRight(DRAGON_DIST) end function moveUp() dragon.pos.head.y=dragon.pos.head.y-1 -- move the tail tailUp(DRAGON_DIST) tailHor() end function moveDown() dragon.pos.head.y=dragon.pos.head.y+1 -- move the tail tailDown(DRAGON_DIST) tailHor() end function moveLeft() dragon.pos.head.x=dragon.pos.head.x-1 -- move the tail tailLeft(DRAGON_DIST) tailVert() end function moveRight() dragon.pos.head.x=dragon.pos.head.x+1 -- move the tail tailRight(DRAGON_DIST) tailVert() end -- move the tail function tailUp(dd) if dragon.pos.body[1].y-(dd/2)>dragon.pos.head.y then dragon.pos.body[1].y=dragon.pos.body[1].y-1 end for i=2,6 do if dragon.pos.body[i].y-dd>dragon.pos.body[i-1].y then dragon.pos.body[i].y=dragon.pos.body[i].y-1 end end end function tailDown(dd) if dragon.pos.body[1].y+(dd/2)dragon.pos.head.x then dragon.pos.body[1].x=dragon.pos.body[1].x-1 end for i=2,6 do if dragon.pos.body[i].x-dd>dragon.pos.body[i-1].x then dragon.pos.body[i].x=dragon.pos.body[i].x-1 end end end function tailRight(dd) if dragon.pos.body[1].x+(dd/2)232 then x=232 end if y<0 then y=0 end if y>128 then y=128 end return x,y end -- makes flying saucer appear function createSaucer() s=0 -- check for an unused saucer for i=1,MAX_SAUCER do if saucer[i].on==false then s=i break end end -- exit if not found if s==0 then return end -- check for a saucer space base for y=0,16 do for x=xscroll+12,xscroll+29,4 do if mget(x,y+((level-1)*17))==SPACE_BASE then mset(x,y+((level-1)*17),OPENED_SPACE_BASE) saucer[s].on=true saucer[s].x=((x-xscroll-1)*8) saucer[s].y=(y+2)*8 saucer[s].ym=saucer[s].y saucer[s].r=math.random(16,32)/2.0 saucer[s].a=270 saucer[s].stp=math.floor(math.random(1,4)) return end end end end -- wake up a roach in visible screen function wakeUpRoaches() for y=0,16 do for x=xscroll,xscroll+29 do if mget(x,y+((level-1)*17))==SLEEPING_ROACH then mset(x,y+((level-1)*17),VOID_ROACH) createRoach(((x-xscroll)*8)+tscroll,y*8) return end end end end -- create a roach sprite at coords function createRoach(xr,yr) table.insert(roach,{x=xr,y=yr,dir=-1,sp=291,on=true}) end -- create a ship1 sprite at coords function createShip1(xr,yr,as) table.insert(ship1,{sx=xr,sy=yr,x=xr,y=yr,a=as,sp=309,on=true}) end -- create a ship2 sprite at coords function createShip2(xr,yr,as,ls) table.insert(ship2,{sx=xr,sy=yr,x=xr,y=yr,a=as,sp=307,l=ls,on=true}) end function createBoss(xr,yr,ls) if ls==1 then table.insert(boss,{x=xr,y=yr,a2=0,a={0,0,0,0,0,0,0},ray={0,0,0,0,0,0,0},stp={0,0,0,0,0,0,0},sp={0,0,0,0,0,0,0},l=80,pain={0,0,0,0,0,0,0},on=true,explode=10}) elseif ls==2 then table.insert(boss,{x=xr,y=yr,a2=0,a={0,0,0,0,0,0,0},ray={0,0,0,0,0,0,0},stp={0,0,0,0,0,0,0},sp={0,0,0,0,0,0,0},l=60,pain={0,0,0,0,0,0,0},on=true,explode=10}) elseif ls==3 then table.insert(boss,{x=xr,y=yr,a2=0,a={0,0,0,0,0,0,0},ray={0,0,0,0,0,0,0},stp={0,0,0,0,0,0,0},sp={0,0,0,0,0,0,0},l=40,pain={0,0,0,0,0,0,0},on=true,explode=10}) elseif ls==4 then elseif ls==5 then elseif ls==6 then elseif ls==7 then end -- randomize boss rotations for i=1,#boss do local r=8 for j=1,#boss[i].a do boss[i].a[j]=math.floor(math.random(0,359)) boss[i].stp[j]=math.floor(math.random(2,5)) boss[i].ray[j]=r r=r+2 boss[i].sp[j]=math.floor(math.random(1,2)) end end end -- check for solid tile function isSolid(x,y) xt1=math.floor((x-tscroll)/8)+xscroll yt1=math.floor(y/8)+((level-1)*17) xt2=math.floor((x+7-tscroll)/8)+xscroll yt2=math.floor((y+7)/8)+((level-1)*17) if fget(mget(xt1,yt1),1) then return true end if fget(mget(xt2,yt1),1) then return true end if fget(mget(xt1,yt2),1) then return true end if fget(mget(xt2,yt2),1) then return true end return false end -- check for bonus tile function isBonus(x,y) xt1=math.floor((x-tscroll)/8)+xscroll yt1=math.floor(y/8)+((level-1)*17) xt2=math.floor((x+7-tscroll)/8)+xscroll yt2=math.floor((y+7)/8)+((level-1)*17) if fget(mget(xt1,yt1),3) or fget(mget(xt1,yt1),4) or fget(mget(xt1,yt1),5) then return true,xt1,yt1 end if fget(mget(xt2,yt1),3) or fget(mget(xt2,yt1),4) or fget(mget(xt2,yt1),5) then return true,xt2,yt1 end if fget(mget(xt1,yt2),3) or fget(mget(xt1,yt2),4) or fget(mget(xt1,yt2),5) then return true,xt1,yt2 end if fget(mget(xt2,yt2),3) or fget(mget(xt2,yt2),4) or fget(mget(xt2,yt2),5) then return true,xt2,yt2 end return false end function takeBonus(x,y) -- take diamond for i=1,#DIAMOND do if mget(x,y)==DIAMOND[i] then mset(x,y,VOID_DIAMOND) score=score+50 sfx(8,77,20,3) return end end -- take heart for i=1,#HEART do if mget(x,y)==HEART[i] then mset(x,y,VOID_HEART) score=score+100 lives=lives+1 sfx(9,40,40,3) return end end -- take shield for i=1,#SHIELD do if mget(x,y)==SHIELD[i] then mset(x,y,VOID_SHIELD) score=score+50 invincible=600 sfx(8,77,20,3) return end end end -- check collisions within two sprites function getCol(x1,y1,w1,h1,x3,y3,w3,h3) x2=x1+w1-1 y2=y1+h1-1 x4=x3+w3-1 y4=y3+h3-1 -- out of the screen ? exit if x1<-w1 or x3<-w3 then return false end if x1>320 or x3>320 then return false end if x1>x4 or x2y4 or y2EXPLOSION_SP_MAX then table.remove(explosion,i) end end end function freeAllExplosions() for i=#explosion,1,-1 do table.remove(explosion,i) end end function freeAllEnemies() for i=1,MAX_SAUCER do saucer[i].on=false end for i=#roach,1,-1 do table.remove(roach) end for i=#ship1,1,-1 do table.remove(ship1) end for i=#ship2,1,-1 do table.remove(ship2) end for i=#boss,1,-1 do table.remove(boss) end end function freeAllBullets() -- clear player's bullets for i=1,MAX_DFIRE do dfire[i].on=false end for i=1,MAX_DEGG do degg[i].on=false end -- clear enemies bullets for i=#sfire,1,-1 do table.remove(sfire) end for i=#rfire,1,-1 do table.remove(rfire) end for i=#bfire,1,-1 do table.remove(bfire) end end ------------------------------------- ------------------------------------- function drawIntro() -- count time cpt=(cpt+1)%60 if cpt==0 then cpt2=cpt2+1 end -- clear the screen in black cls(0) -- hide mouse cursor poke(0x3FFB,0) -- draw the intro's map map(0,119,30,17,0,0,0) -- print texts print("Dragoon",100,32,12) print("Throw Fire (A)",88,80,12) print("Drop Eggs (B)",88,88,12) if cpt<30 then print("Press (A)",99,112,5) end -- play ambiant sounds if cpt2%3==0 and cpt==0 then sfx(6,math.floor(math.random(20,50)),40,2) end if cpt2%5==0 and cpt==0 then sfx(5,math.floor(math.random(30,70)),70,3) end end function drawGameOver() -- count time cpt=(cpt+1)%60 if cpt==0 then cpt2=cpt2+1 end -- clear the screen in dark red cls(1) -- hide mouse cursor poke(0x3FFB,0) -- draw the intro's map map(30,119,30,17,0,0,0) -- print texts print("You failed !",88,56,2) print("Try again...",88,72,2) sc=tostring(score) for i=1,7-#sc do sc="0"..sc end print("Your score : "..sc,64,88,2) if cpt<30 then print("Press (A)",96,112,5) end end function drawInterLevels() -- count time cpt=(cpt+1)%60 if cpt==0 then cpt2=cpt2+1 end -- clear the screen in dark red cls(1) -- hide mouse cursor poke(0x3FFB,0) -- draw the intro's map map(30,119,30,17,0,0,0) -- print texts print("Prepare for next level...",32,56,2) if cpt<30 then print("Press (A)",96,112,5) end end -- check for button press -- before switching to -- another game state function checkButton() if gameState==INTRO then if btnp(4) then gameState=PLAYING resetLevel() score=0 lives=3 invincible=0 level=FIRST_LEVEL dragonAlive=true activateShips(level) cpt=0 cpt2=0 cptmem=0 music(0) end elseif gameState==INTERLEVELS then if btnp(4) then gameState=PLAYING resetLevel() -- force explosions to end for i=#explosion,1,-1 do table.remove(explosion,i) end invincible=0 level=level+1 activateShips(level) cpt=0 cpt2=0 cptmem=0 music(0) end elseif gameState==GAMEOVER then if btnp(4) then gameState=INTRO music(1) end end end -- update the game function updateGame() -- count time cpt=(cpt+1)%60 if cpt==0 then cpt2=cpt2+1 end -- store cpt2 value if cptmem==0 and not dragonAlive then cptmem=cpt2 end -- decrement invincibility if invincible>0 then invincible=invincible-1 end -- use a new life for the dragon if cptmem>0 and cpt2-cptmem>=3 then cptmem=0 if lives>0 then lives=lives-1 invincible=0 end if lives>0 then dragonAlive=true resetLevel() activateShips(level) music(0) else gameState=GAMEOVER music(2,nil,nil,false) end end -- scroll starfield for i=1,MAX_STARS do if cpt%(star[i].s*3.0)==0 then star[i].x=star[i].x-2 if star[i].x<0 then star[i].x=star[i].x+240 end end end -- if the dragon is alive... if dragonAlive then -- scroll the map if xscroll0 then dragon.fire=true dfire[df].x=dragon.pos.head.x dfire[df].y=dragon.pos.head.y dfire[df].on=true sfx(6,57,5,3) end end -- dragon's throw eggs if btnp(5) and not dragon.fire then dragon.fire=true throwEgg(dragon.pos.head.x,dragon.pos.head.y) end end -- move dragon's fireball for i=1,MAX_DFIRE do if dfire[i].on then dfire[i].x=dfire[i].x+2 if dfire[i].x>240 then dfire[i].on=false end end end -- move dragon's eggs for i=1,MAX_DEGG do if degg[i].on then degg[i].y=degg[i].y+degg[i].fs if degg[i].fs<2.0 then degg[i].fs=degg[i].fs*1.1 end -- an egg it out of the screen ? if degg[i].y>=136 then degg[i].on=false end -- an egg hit a tile ? if degg[i].on then if isSolid(degg[i].x,degg[i].y) then degg[i].on=false end end -- an egg hit a saucer ? if degg[i].on then for j=1,MAX_SAUCER do if saucer[j].on then if getCol(saucer[j].x,saucer[j].y,8,8,degg[i].x,degg[i].y,8,8) then newExplosion(saucer[j].x,saucer[j].y,1) degg[i].on=false saucer[j].on=false score=score+10 sfx(3,67,20,3) end end end end -- an egg hit a roach ? if degg[i].on then for j=1,#roach do if roach[j].on then if getCol(roach[j].x,roach[j].y,8,8,degg[i].x,degg[i].y,8,8) then newExplosion(roach[j].x,roach[j].y,1) degg[i].on=false roach[j].on=false score=score+10 sfx(3,67,20,3) end end end end -- an egg hit a ship1 ? if degg[i].on then for j=1,#ship1 do if ship1[j].on then if getCol(ship1[j].x,ship1[j].y,8,8,degg[i].x,degg[i].y,8,8) then newExplosion(ship1[j].x,ship1[j].y,1) degg[i].on=false ship1[j].on=false score=score+10 sfx(3,67,20,3) end end end end -- an egg hit a ship2 ? if degg[i].on then for j=1,#ship2 do if ship2[j].on then if getCol(ship2[j].x,ship2[j].y,16,16,degg[i].x,degg[i].y,8,8) then ship2[j].l=ship2[j].l-1 degg[i].on=false if ship2[j].l>0 then sfx(4,77,5,3) else sfx(3,67,20,3) newExplosion(ship2[j].x,ship2[j].y,2) ship2[j].on=false score=score+100 end end end end end -- an egg hit a boss bodypart ? if degg[i].on then for j=1,#boss do if boss[j].on then local xc=boss[j].x local yc=boss[j].y -- a bodypart of the boss collides ? for k=1,#boss[j].a do if getCol(xc,yc,16,16,degg[i].x,degg[i].y,8,8) then boss[j].l=boss[j].l-1 degg[i].on=false if boss[j].l>0 then boss[j].pain[k]=BOSS_PAIN_TIMER sfx(4,77,5,3) else boss[j].on=false score=score+5000 sfx(3,67,20,3) end break end if k<#boss[j].a then if xscroll==BOSS_SCREEN_LIMIT then xc=xc+(boss[j].ray[k+1]*math.cos(math.rad(boss[j].a[k+1]))*math.cos(math.rad(boss[j].a2))) yc=yc+(boss[j].ray[k+1]*math.sin(math.rad(boss[j].a[k+1]))*math.sin(math.rad(boss[j].a2))) end end end end end end end end -- restore boss bodypart after a hit for i=1,#boss do if boss[i].on then if boss[i].l>0 then for k=1,#boss[i].a do if boss[i].pain[k]>0 then boss[i].pain[k]=boss[i].pain[k]-1 end end end end end -- dragon's fireball collisions for i=1,MAX_DFIRE do if dfire[i].on then -- check collisions with solid tiles if isSolid(dfire[i].x,dfire[i].y) then dfire[i].on=false sfx(4,77,5,3) end end end -- check collisions between flying -- saucers and dragon's fireballs for i=1,MAX_SAUCER do if saucer[i].on then for j=1,MAX_DFIRE do if dfire[j].on then if getCol(saucer[i].x,saucer[i].y,8,8,dfire[j].x,dfire[j].y,8,8) then newExplosion(saucer[i].x,saucer[i].y,1) saucer[i].on=false dfire[j].on=false score=score+10 sfx(3,67,20,3) end end end end end -- check collisions between roaches -- and dragon's fireballs for i=1,#roach do if roach[i].on then for j=1,MAX_DFIRE do if dfire[j].on then if getCol(roach[i].x,roach[i].y,8,8,dfire[j].x,dfire[j].y,8,8) then newExplosion(roach[i].x,roach[i].y,1) roach[i].on=false dfire[j].on=false score=score+10 sfx(3,67,20,3) end end end end end -- check collisions between ship1 -- and dragon's fireballs for i=1,#ship1 do if ship1[i].on then for j=1,MAX_DFIRE do if dfire[j].on then if getCol(ship1[i].x,ship1[i].y,8,8,dfire[j].x,dfire[j].y,8,8) then newExplosion(ship1[i].x,ship1[i].y,1) ship1[i].on=false dfire[j].on=false score=score+10 sfx(3,67,20,3) end end end end end -- check collisions between ship2 -- and dragon's fireballs for i=1,#ship2 do if ship2[i].on then for j=1,MAX_DFIRE do if dfire[j].on then if getCol(ship2[i].x,ship2[i].y,16,16,dfire[j].x,dfire[j].y,8,8) then ship2[i].l=ship2[i].l-1 dfire[j].on=false if ship2[i].l>0 then sfx(4,77,5,3) else sfx(3,67,20,3) newExplosion(ship2[i].x,ship2[i].y,2) ship2[i].on=false score=score+100 end end end end end end -- check collisions between boss -- bodypart and dragon's fireballs for i=1,#boss do if boss[i].on then for j=1,MAX_DFIRE do if dfire[j].on then local xc=boss[i].x local yc=boss[i].y -- a bodypart of the boss collides ? for k=1,#boss[i].a do if getCol(xc,yc,16,16,dfire[j].x,dfire[j].y,8,8) then boss[i].l=boss[i].l-1 dfire[j].on=false if boss[i].l>0 then boss[i].pain[k]=BOSS_PAIN_TIMER sfx(4,77,5,3) else boss[i].on=false score=score+5000 sfx(3,67,20,3) end break end if k<#boss[i].a then if xscroll==BOSS_SCREEN_LIMIT then xc=xc+(boss[i].ray[k+1]*math.cos(math.rad(boss[i].a[k+1]))*math.cos(math.rad(boss[i].a2))) yc=yc+(boss[i].ray[k+1]*math.sin(math.rad(boss[i].a[k+1]))*math.sin(math.rad(boss[i].a2))) end end end end end end end -- check collisions between dragon's -- fire and boss fire for i=1,#bfire do if bfire[i].on then for j=1,MAX_DFIRE do if dfire[j].on then if getCol(bfire[i].x,bfire[i].y,8,8,dfire[j].x,dfire[j].y,8,8) then bfire[i].on=false dfire[j].on=false sfx(3,67,20,3) newExplosion(bfire[i].x,bfire[i].y,1) score=score+20 end end end end end -- a boss die boss_die=false for i=#boss,1,-1 do if not boss[i].on then if boss[i].explode>0 then if cpt%15==0 then boss[i].explode=boss[i].explode-1 newExplosion(boss[i].x+math.random(-8,8),boss[i].y+math.random(-8,8),math.random(1,2)) if boss[i].explode==0 then table.remove(boss,i) if #boss==0 then boss_die=true end end end end end end -- all the boss die if boss_die then music(4,-1,-1,false) cpt=0 cpt2=0 gameState=INTERLEVELS end -- randomly create saucers if cpt2%4==3 and cpt%30==0 then createSaucer() end -- move saucers for i=1,MAX_SAUCER do if saucer[i].on then saucer[i].x=saucer[i].x-1 -- stop saucers if they are -- out of the screen if saucer[i].x<=-8 then saucer[i].on=false else saucer[i].y=saucer[i].ym -- remember last y saucer[i].y=saucer[i].y+(saucer[i].r*math.sin(math.rad(saucer[i].a))) saucer[i].a=(saucer[i].a+saucer[i].stp)%360 if cpt%20==0 then if math.floor(math.random(1,10))==1 then saucerFire(saucer[i].x,saucer[i].y) end end end end end -- move saucer's bullets for i=1,#sfire do if sfire[i].on then sfire[i].x=sfire[i].x-1.5 -- if the dragon is alive... if dragonAlive then -- check collisions with dragon's tail for j=1,6 do if sfire[i].on then if getCol(sfire[i].x,sfire[i].y,8,8,dragon.pos.body[j].x,dragon.pos.body[j].y,8,8) then sfire[i].on=false sfx(4,77,5,3) end end end -- check collisions with dragon's head if sfire[i].on then if getCol(sfire[i].x,sfire[i].y,8,8,dragon.pos.head.x,dragon.pos.head.y,8,8) then if invincible==0 then killDragon() end end end end end end -- randomly wake up roaches if cpt2%3==0 then wakeUpRoaches() end -- move roaches if cpt%8==0 then for i=1,#roach do if roach[i].on then if roach[i].sp==ROACH_SP[1] then if math.floor(math.random(1,15))==1 then roach[i].sp=ROACH_SP[3] roachFire(roach[i].x,roach[i].y) else roach[i].sp=ROACH_SP[2] xr=roach[i].x roach[i].x=roach[i].x+roach[i].dir if isSolid(roach[i].x,roach[i].y) then roach[i].x=xr roach[i].dir=-roach[i].dir end end elseif roach[i].sp==ROACH_SP[2] then roach[i].sp=ROACH_SP[1] xr=roach[i].x roach[i].x=roach[i].x+roach[i].dir if isSolid(roach[i].x,roach[i].y) then roach[i].x=xr roach[i].dir=-roach[i].dir end elseif roach[i].sp==ROACH_SP[3] then roach[i].sp=ROACH_SP[1] end -- roach out of the screen ? if roach[i].x<=-8 then roach[i].on=false end end end end -- move roaches bullets for i=1,#rfire do if rfire[i].on then rfire[i].y=rfire[i].y-1.5 if rfire[i].y<=-8 then rfire[i].on=false end if rfire[i].on then if isSolid(rfire[i].x,rfire[i].y) then rfire[i].on=false end end -- if the dragon is alive... if dragonAlive then -- check collisions with dragon's tail for j=1,6 do if rfire[i].on then if getCol(rfire[i].x,rfire[i].y,8,8,dragon.pos.body[j].x,dragon.pos.body[j].y,8,8) then rfire[i].on=false sfx(4,77,5,3) end end end -- check collisions with dragon's head if rfire[i].on then if getCol(rfire[i].x,rfire[i].y,8,8,dragon.pos.head.x,dragon.pos.head.y,8,8) then if invincible==0 then killDragon() end end end end end end -- move ship1 for i=1,#ship1 do if ship1[i].on and ship1[i].x<-8 then ship1[i].on = false elseif ship1[i].x<320 then ship1[i].x=ship1[i].x-1 ship1[i].y=ship1[i].y+(2.0*math.sin(math.rad(ship1[i].a))) ship1[i].a=(ship1[i].a+5) % 360 end end -- move ship2 for i=1,#ship2 do if ship2[i].on and ship2[i].x<-16 then ship2[i].on = false elseif ship2[i].x<320 then ship2[i].x=ship2[i].x-0.25 ship2[i].y=ship2[i].y+(0.2*math.sin(math.rad(ship2[i].a))) ship2[i].a=(ship2[i].a+2) % 360 end end -- move boss for i=1,#boss do for j=1,#boss[i].a do boss[i].a[j]=(boss[i].a[j]+boss[i].stp[j])%360 boss[i].a2=(boss[i].a2+1)%360 if cpt%16==0 then boss[i].sp[j]=boss[i].sp[j]+1 if boss[i].sp[j]==3 then boss[i].sp[j]=1 end end end end -- move boss bullets for i=1,#bfire do if bfire[i].on then bfire[i].x=bfire[i].x+bfire[i].xdir bfire[i].y=bfire[i].y+bfire[i].ydir+(2*math.sin(math.rad((bfire[i].x%360)*4))) -- if the dragon is alive... if dragonAlive then if bfire[i].on then -- check collisions with dragon's tail for j=1,6 do if getCol(bfire[i].x,bfire[i].y,16,16,dragon.pos.body[j].x,dragon.pos.body[j].y,8,8) then bfire[i].on=false killDragon() end end -- check collisions with dragon's head if getCol(bfire[i].x,bfire[i].y,16,16,dragon.pos.head.x,dragon.pos.head.y,8,8) then if invincible==0 then bfire[i].on=false killDragon() end end end end end end -- delete unused saucer's bullets for i=#sfire,1,-1 do if not sfire[i].on then table.remove(sfire,i) end end -- delete unused roaches for i=#roach,1,-1 do if not roach[i].on then table.remove(roach,i) end end -- delete unused roach's bullets for i=#rfire,1,-1 do if not rfire[i].on then table.remove(rfire,i) end end -- delete unused ship1 for i=#ship1,1,-1 do if not ship1[i].on then table.remove(ship1,i) end end -- delete unused ship2 for i=#ship2,1,-1 do if not ship2[i].on then table.remove(ship2,i) end end -- delete unused boss tentacles for i=#boss,1,-1 do if not boss[i].on and boss[i].explode==0 then table.remove(boss,i) end end -- delete unused boss bullets for i=#bfire,1,-1 do if not bfire[i].on then table.remove(bfire,i) end end -- if the dragon is alive... if dragonAlive then -- check collisions between flying -- saucers and dragon's tail for i=1,MAX_SAUCER do if saucer[i].on then for j=1,6 do if getCol(saucer[i].x,saucer[i].y,8,8,dragon.pos.body[j].x,dragon.pos.body[j].y,8,8) then newExplosion(saucer[i].x,saucer[i].y,1) saucer[i].on=false score=score+10 sfx(3,67,20,3) end end end end -- check collisions between flying -- saucers and dragon's head for i=1,MAX_SAUCER do if saucer[i].on then if getCol(saucer[i].x,saucer[i].y,8,8,dragon.pos.head.x,dragon.pos.head.y,8,8) then newExplosion(saucer[i].x,saucer[i].y,1) saucer[i].on=false if invincible==0 then killDragon() else score=score+10 sfx(3,67,20,3) end end end end end -- if the dragon is alive... if dragonAlive then -- check collisions between roaches -- and dragon's tail for i=1,#roach do if roach[i].on then for j=1,6 do if getCol(roach[i].x,roach[i].y,8,8,dragon.pos.body[j].x,dragon.pos.body[j].y,8,8) then newExplosion(roach[i].x,roach[i].y,1) roach[i].on=false score=score+10 sfx(3,67,20,3) end end end end -- check collisions between roaches -- and dragon's head for i=1,#roach do if roach[i].on then if getCol(roach[i].x,roach[i].y,8,8,dragon.pos.head.x,dragon.pos.head.y,8,8) then newExplosion(roach[i].x,roach[i].y,1) roach[i].on=false if invincible==0 then killDragon() else score=score+10 sfx(3,67,20,3) end end end end end -- if the dragon is alive... if dragonAlive then -- check collisions between ship1 -- and dragon's tail for i=1,#ship1 do if ship1[i].on then for j=1,6 do if getCol(ship1[i].x,ship1[i].y,8,8,dragon.pos.body[j].x,dragon.pos.body[j].y,8,8) then newExplosion(ship1[i].x,ship1[i].y,1) ship1[i].on=false score=score+10 sfx(3,67,20,3) end end end end -- check collisions between ship1 -- and dragon's head for i=1,#ship1 do if ship1[i].on then if getCol(ship1[i].x,ship1[i].y,8,8,dragon.pos.head.x,dragon.pos.head.y,8,8) then newExplosion(ship1[i].x,ship1[i].y,1) ship1[i].on=false if invincible==0 then killDragon() else score=score+10 sfx(3,67,20,3) end end end end end -- if the dragon is alive... if dragonAlive then -- check collisions between ship2 -- and dragon's tail for i=1,#ship2 do if ship2[i].on then for j=1,6 do if getCol(ship2[i].x,ship2[i].y,16,16,dragon.pos.body[j].x,dragon.pos.body[j].y,8,8) then newExplosion(ship2[i].x,ship2[i].y,2) ship2[i].on=false killDragon() end end end end -- check collisions between ship2 -- and dragon's head for i=1,#ship2 do if ship2[i].on then if getCol(ship2[i].x,ship2[i].y,16,16,dragon.pos.head.x,dragon.pos.head.y,8,8) then newExplosion(ship2[i].x,ship2[i].y,2) ship2[i].on=false killDragon() end end end end -- if the dragon is alive... if dragonAlive then -- check collisions between boss -- bodyparts and dragon's tail for i=1,#boss do if boss[i].on then local xc=boss[i].x local yc=boss[i].y -- a bodypart of the boss collides ? for k=1,#boss[i].a do -- ...with the dragon's tail ? for j=1,6 do if getCol(xc,yc,16,16,dragon.pos.body[j].x,dragon.pos.body[j].y,8,8) then killDragon() end end -- ...or with the dragon's head ? if getCol(xc,yc,16,16,dragon.pos.head.x,dragon.pos.head.y,8,8) then killDragon() end -- next boss bodypart collides ? if k<#boss[i].a then if xscroll==BOSS_SCREEN_LIMIT then xc=xc+(boss[i].ray[k+1]*math.cos(math.rad(boss[i].a[k+1]))*math.cos(math.rad(boss[i].a2))) yc=yc+(boss[i].ray[k+1]*math.sin(math.rad(boss[i].a[k+1]))*math.sin(math.rad(boss[i].a2))) end end end end end end -- if the dragon is alive... if dragonAlive then -- check collisions between the -- dragon's head and solid tiles if isSolid(dragon.pos.head.x,dragon.pos.head.y) then killDragon() else r,xr,yr=isBonus(dragon.pos.head.x,dragon.pos.head.y) if r then takeBonus(xr,yr) end end end -- check collisions between the -- dragon's tail and solid tiles for i=1,6 do -- if the dragon is alive... if dragonAlive then if isSolid(dragon.pos.body[i].x,dragon.pos.body[i].y) then killDragon() else r,xr,yr=isBonus(dragon.pos.body[i].x,dragon.pos.body[i].y) if r then takeBonus(xr,yr) end end end end end -- draw the game function drawGame() -- clear the screen in black cls(0) -- hide mouse cursor poke(0x3FFB,0) -- draw the starfield for i=1,MAX_STARS do if star[i].s==1 then rect(star[i].x,star[i].y,2,1,12) elseif star[i].s==2 then rect(star[i].x,star[i].y,2,1,10) elseif star[i].s==3 then rect(star[i].x,star[i].y,2,1,9) elseif star[i].s==4 then rect(star[i].x,star[i].y,2,1,8) end end -- draw the map map(xscroll,(level-1)*17,31,17,tscroll,0,0) -- if the dragon is alive... if dragonAlive then -- draw the dragon's body for i=6,1,-1 do local sprite=dragon.sp.body[1] -- make the dragon's tail blink if invincible%4==3 then sprite=305 end spr(sprite,dragon.pos.body[i].x,dragon.pos.body[i].y,0) end -- draw the dragon's head if not dragon.fire then spr(dragon.sp.head[1],dragon.pos.head.x,dragon.pos.head.y,0) else spr(dragon.sp.headFire[dragon.frame],dragon.pos.head.x,dragon.pos.head.y,0) if cpt%3==0 then dragon.frame=dragon.frame+1 if dragon.frame>4 then dragon.fire=false dragon.frame=1 end end end end -- draw the dragon's fire bullets for i=1,MAX_DFIRE do if dfire[i].on then spr(DFIRE_SP,dfire[i].x,dfire[i].y,0) end end -- draw the dragon's eggs for i=1,MAX_DEGG do if degg[i].on then spr(DEGG_SP,degg[i].x,degg[i].y,0) end end -- draw saucers for i=1,MAX_SAUCER do if saucer[i].on then spr(SAUCER_SP,saucer[i].x,saucer[i].y,0) end end -- draw saucer's bullets for i=1,#sfire do if sfire[i].on then spr(SFIRE_SP,sfire[i].x,sfire[i].y,0) end end -- draw roaches for i=1,#roach do if roach[i].on then spr(roach[i].sp,roach[i].x,roach[i].y,0) end end -- draw roaches bullets for i=1,#rfire do if rfire[i].on then spr(RFIRE_SP,rfire[i].x,rfire[i].y,0) end end -- draw ship1 for i=1,#ship1 do if ship1[i].on then spr(SHIP1_SP,ship1[i].x,ship1[i].y,0) end end -- draw ship2 for i=1,#ship2 do if ship2[i].on then spr(SHIP2_SP,ship2[i].x,ship2[i].y,0,1,0,0,2,2) end end -- draw boss for i=1,#boss do if boss[i].on then local xc=boss[i].x local yc=boss[i].y for k=1,#boss[i].a-1 do local offset=0 if boss[i].pain[k]>0 then offset=8 end spr(BOSS_SP[boss[i].sp[k]]+offset+(32*(level-1)),xc,yc,0,1,0,0,2,2) if xscroll==BOSS_SCREEN_LIMIT then xc=xc+(boss[i].ray[k+1]*math.cos(math.rad(boss[i].a[k+1]))*math.cos(math.rad(boss[i].a2))) yc=yc+(boss[i].ray[k+1]*math.sin(math.rad(boss[i].a[k+1]))*math.sin(math.rad(boss[i].a2))) end end local k=#boss[i].a local offset=0 local firing=0 if boss[i].pain[k]>0 then offset=8 end if xscroll==BOSS_SCREEN_LIMIT then if cpt==0 and cpt2%4==0 then firing=2 sfx(11,24,60) for f=1,firing do if boss[i].x>dragon.pos.head.x then xdir=-BOSS_FIRE_SPEED else xdir=BOSS_FIRE_SPEED end ydir=math.random(-4,4)/10.0 bossFire(xc,yc,xdir,ydir) end end end spr(BOSSHEAD_SP+(32*(level-1))+offset+firing,xc,yc,0,1,0,0,2,2) end end -- draw boss bullets for i=1,#bfire do if bfire[i].on then spr(BFIRE_SP,bfire[i].x,bfire[i].y,0) end end -- draw explosions for i=1,#explosion do if cpt%5==0 then explosion[i].frm=explosion[i].frm+1 end if explosion[i].frm<=EXPLOSION_SP_MAX then spr(explosion[i].frm,explosion[i].x,explosion[i].y,0,explosion[i].zoom) end end -- delete finished explosions endExplosions() end -- draw the panel function drawPanel() rect(0,0,240,8,14) rect(1,1,238,6,1) line(0,0,239,0,4) line(239,0,239,7,4) -- add zeros at beginning -- of the score sc=tostring(score) for i=1,7-#sc do sc="0"..sc end -- add zeros at beginning -- of the life count l=tostring(lives) for i=1,2-#l do l="0"..l end -- draw text's shadows print(sc,2,1,2) print(l,227,1,2) print("level "..level,108,1,2) -- draw the text print(sc,2,2,4) print(l,227,2,4) print("level "..level,108,2,4) end -- destroy the player function killDragon() -- debug mode on ? exit if DEBUG_MODE==true then return end if dragonAlive==false then return end newExplosion(dragon.pos.head.x,dragon.pos.head.y,1) for j=1,6 do newExplosion(dragon.pos.body[j].x,dragon.pos.body[j].y,1) end dragonAlive=false sfx(5,67,40,3) end -- reset level function resetLevel() tscroll=0 xscroll=0 dragon.pos.head.x=16 dragon.pos.head.y=26 dragon.pos.body[1].x=12 dragon.pos.body[1].y=26 dragon.pos.body[2].x=8 dragon.pos.body[2].y=30 dragon.pos.body[3].x=4 dragon.pos.body[3].y=34 dragon.pos.body[4].x=4 dragon.pos.body[4].y=38 dragon.pos.body[5].x=4 dragon.pos.body[5].y=42 dragon.pos.body[6].x=8 dragon.pos.body[6].y=46 for y=0,16 do for x=0,239 do if mget(x,y+((level-1)*17))==OPENED_SPACE_BASE then mset(x,y+((level-1)*17),SPACE_BASE) end if mget(x,y+((level-1)*17))==VOID_ROACH then mset(x,y+((level-1)*17),16) end if mget(x,y+((level-1)*17))==VOID_SHIP1 then mset(x,y+((level-1)*17),32) end if mget(x,y+((level-1)*17))==VOID_SHIP2 then mset(x,y+((level-1)*17),48) end if mget(x,y+((level-1)*17))==VOID_BOSS then mset(x,y+((level-1)*17),64) end if mget(x,y+((level-1)*17))==VOID_DIAMOND then mset(x,y+((level-1)*17),128) end if mget(x,y+((level-1)*17))==VOID_HEART then mset(x,y+((level-1)*17),131) end if mget(x,y+((level-1)*17))==VOID_SHIELD then mset(x,y+((level-1)*17),133) end end end freeAllEnemies() freeAllBullets() freeAllExplosions() end -- animate water on the current level function animateWater() if cpt%8>0 then return end for y=0,16 do for x=xscroll,xscroll+29 do y2=y+(17*(level-1)) if mget(x,y2)>=36 and mget(x,y2)<=39 then mset(x,y2,math.floor(math.random(36,39))) end end end end -- the player throw an egg function throwEgg(xe,ye) for i=1,MAX_DEGG do if not degg[i].on then degg[i].on = true degg[i].x=xe degg[i].y=ye+6 degg[i].fs=DEGG_SPEED sfx(7,40,40,3) return end end end -- a saucer fire on the player's directionfunction saucerFire(xf,yf) function saucerFire(xf,yf) table.insert(sfire,{x=xf,y=yf,on=true}) end -- a roach fire on the player's direction function roachFire(xf,yf) table.insert(rfire,{x=xf,y=yf,on=true}) end -- a boss fire on the player's directionfunction saucerFire(xf,yf) function bossFire(xf,yf,xdir,ydir) table.insert(bfire,{x=xf,y=yf,xdir=xdir,ydir=ydir,on=true}) end -- update bonus animations function updateAllBonus() for y=0,16 do for x=xscroll,xscroll+29 do t=mget(x,y+((level-1)*17)) -- diamond if cpt%4==0 then if t>=DIAMOND[1] and t<=DIAMOND[3] then t=t+1 if t>DIAMOND[3] then t=DIAMOND[1] end end end -- heart if cpt%10==0 then if t==HEART[1] then t=HEART[2] elseif t==HEART[2] then t=HEART[1] end end -- shield if cpt%4==0 then if t>=SHIELD[1] and t<=SHIELD[4] then t=t+1 if t>SHIELD[4] then t=SHIELD[1] end end end -- change tile value mset(x,y+((level-1)*17),t) end end end -- activate level's ships (and bosses) function activateShips(l) for y=0,16 do for x=0,239 do -- search for special tiles local t=mget(x,y+((l-1)*17)) if t==32 then mset(x,y+((l-1)*17),VOID_SHIP1) createShip1(x*8,y*8,270) elseif t==48 then mset(x,y+((l-1)*17),VOID_SHIP2) createShip2(x*8,y*8,270,8) elseif t==64 then mset(x,y+((l-1)*17),VOID_BOSS) createBoss(x*8,y*8,l) end end end end