-- alphawar by lyoy -- created for gamejam gamecodeur 11 -- game={} game.scene="" game.statut="" game.btnxrelease=false game.score=0 grpenemies={} grpprojectiles={} grpparticules={} grpbackground={} grpgfx={} player={} timer=0 timer1s=0 lasttime=0 levelbg={ {"<","","","","","","","<",">"}, {"<","","","","","","","<",">"}, {"<","","","","","","","<",">"}, {"<","","","","","","","p",">"}, {"<","","","","","","","p",">"}, {"<","","","","","","","p",">"} } function _draw() cls() if(game.scene=="game")then game_draw() elseif(game.scene=="start_screen")then stscreen_draw() end end function game_init() game.statut="game" player=mkship(50,80) mkbackground() for i=1,5 do local enemy=mkenemy(rnd(100),(rnd(20)+40)*-1,flr(rnd(3)+1) ) end for i=1,10 do local enemy=mkenemy(rnd(100),(rnd(20)+120)*-1,flr(rnd(3)+1) ) end for i=1,15 do local enemy=mkenemy(rnd(100),(rnd(20)+200)*-1,flr(rnd(3)+1) ) end for i=1,20 do local enemy=mkenemy(rnd(100),(rnd(20)+350)*-1,flr(rnd(3)+1) ) end for i=1,10 do local enemy=mkenemy(rnd(100),(rnd(20)+500)*-1,flr(rnd(3)+1) ) end end function _init() game.scene="start_screen" end function game_over() game.statut="gameover" --restart() end function restart() game.scene="start_screen" grpenemies={} grpprojectiles={} grpparticules={} grpbackground={} grpgfx={} player={} end function _update() timer=timer+1 timer1s=flr(timer/30) if(game.scene=="game") then if(btnp(5) and game.statut=="gameover")then restart() else game_update() end elseif(game.scene=="start_screen")then stscreen_update() end end ---- functions make ----- -------------------------- function mkenemy(px,py,ptype) local enemy={} enemy.x=px enemy.y=py enemy.dx=0 enemy.speed=0.15 enemy.ecartx=4 enemy.ecarty=5 enemy.shootrate=10 if (ptype==1) then enemy.sprite= { {"<",0,"e",0,">"}, {"<","e","a","a",">"}, {"<",0,"h",0,">"} } enemy.col=1 enemy.dx=0 enemy.dy=1 elseif (ptype==2) then enemy.sprite= { {"<",0,"e",0,">"}, {"<","e","a","a",">"}, {"<","y","y","y",">"} } enemy.col=2 enemy.dy=3 elseif (ptype==3) then enemy.sprite= { {"<","u","e","u",">"}, {"<","e","a","a",">"}, {"<","y","y","y",">"}, {"<",0,"y",0,">"} } enemy.col=2 enemy.dy=3 elseif (ptype==4) then enemy.sprite= { {0,0,"r",0,0}, {"<","e","a","a",">"}, {"<","y","y","y",">"}, {"<","t","0","t",">"}, {0,"<","\142",">",0} } enemy.col=1 enemy.dy=4 end enemy.w=#(enemy.sprite[1])*6 enemy.h=#enemy.sprite*6 enemy.life=flr(rnd(60)) enemy.damagetimer=0 printh("enemy.h: "..enemy.h) function enemy:update() enemy:collisions() enemy:move() enemy.shootrate-=1 if(enemy.shootrate<=0 and enemy.y>0)then enemy.shoot() enemy.shootrate=rnd(150)+5 end end function enemy:move() enemy.x=enemy.x+enemy.dx*enemy.speed enemy.y=enemy.y+enemy.dy*enemy.speed --enemy.x=enemy.x+cos(time()/3)*20+50 end--end fn enemu move function enemy:shoot() mkbullet("benemy",enemy.x+enemy.ecartx,enemy.y+20,1,11,"!!") end function enemy:die() local px=enemy.x+enemy.w/2 local py=enemy.y+enemy.h/2 sfx(2) if(game.score>=0)then game.score+=2 end for i=1,10 do mkparticule(px+rnd(10),py+rnd(4)) end del(grpgfx,enemy) del(grpenemies,enemy) end--end fn enemy die function enemy:damage(pamount) enemy.life=enemy.life-pamount enemy.damagetimer=20 if(enemy.life<=0)then enemy.die() end end-- end fn enemy damage function enemy:collisions() for i=1,#grpprojectiles do local proj=grpprojectiles[i] if(proj~=nil)then if proj.x+proj.w/2>enemy.x and proj.x+proj.w/2enemy.y and proj.y0 then --collision sfx(3) if(proj.tag=="bship")then enemy:damage(proj.damage) proj:die() end end--end check end--end check proj nil end--end loop proj end--end functin collision add(grpgfx,enemy) add(grpenemies,enemy) return enemy end function mkparticule(px,py) local particule={} particule.x=px particule.y=py particule.life=10 add(grpparticules,particule) function particule:update() particule.life=particule.life-1 if(particule.life<=0)then del(grpparticules,particule) end end return particule end function mkpartbg() local bgpart={} bgpart.x=rnd(150) bgpart.y=rnd(150) bgpart.speed=rnd(5) function bgpart:update() bgpart.y=bgpart.y+1*bgpart.speed if(bgpart.y>150)then bgpart.y=rnd(30)*-1 end end add(grpbackground,bgpart) return bgpart end function mkbackground() for i=1,20 do mkpartbg() end end function mkbullet(ptag,px,py,pdy,pcol,ptext) local bullet={} bullet.x=px bullet.y=py bullet.dy=pdy bullet.col=pcol bullet.tag=ptag bullet.sprite= { {ptext} } bullet.size=1 bullet.w=6 bullet.velocity=3 bullet.damage=10 function bullet:move() bullet.y=bullet.y+bullet.dy*bullet.velocity if (bullet.y<-0) then bullet:die() end -- end if bullet screen out end function bullet:die() del(grpgfx,bullet) del(grpprojectiles,bullet) end add(grpgfx,bullet) add(grpprojectiles,bullet) return bullet end function mkship(px,py) ship={} ship.sprite={ {"i","","","^","","","i"}, {"i","","","i","","","i"}, {"i","","","i","","","i"}, {"<","i","a","m","-","a",">"}, {"<","x","w","i","n","g",">"}, {"<","-","i","i","i","-",">"} } ship.x=px ship.y=py ship.dx=0 ship.dy=0 ship.col=7 ship.ecartx=4 ship.ecarty=5 ship.lifemax=100 ship.life=ship.lifemax ship.speed=2 ship.w=#(ship.sprite[1])*6 ship.h=#ship.sprite*6 ship.firecooldownlimit=5 ship.firecooldown=ship.firecooldownlimit ship.damagetimer=0 --table.insert(grpgfx,ship) function ship:update() ship:collisions() if(ship.firecooldown>0 )then ship.firecooldown=ship.firecooldown-1 else ship.firecooldown=ship.firecooldownlimit end end function ship:damage(pamount) if(ship.life>0)then ship.life=ship.life-pamount end ship.damagetimer=20 if(ship.life<=0)then ship.die() end end-- end fn enemy damage function ship:die() sfx(2) if(game.score>0)then game.score-=1 end game_over() end function ship:collisions() for i=1,#grpprojectiles do local proj=grpprojectiles[i] if(proj~=nil)then print("ship",50,50,7) if proj.x+proj.w/2>ship.x and proj.x+proj.w/2ship.y and proj.y0) then gfx.damagetimer=gfx.damagetimer-1 col = flr((time()*20)%3)+7 elseif(gfx.damagetimer<=0)then --gfx.damagetimer=10 end -- end damage timer end--end check damage timer exist print(pixl[k],posx-1,posy-1,col) elseif (pixl[k]=="") then else if (gfx.damagetimer~=nil)then if (gfx.damagetimer>0) then gfx.damagetimer=gfx.damagetimer-1 col = flr((time()*20)%3)+7 elseif(gfx.damagetimer<=0)then --gfx.damagetimer=10 end -- end damage timer end--end check damage timer exist if(gfx.tag~=nil)then if(gfx.tag=="benemy")then circ(posx,posy,2,gfx.col) elseif(gfx.tag=="bship")then circ(posx,posy,1,col) end else circ(posx,posy,4,col) end end--end if check type end-- end loop sprite col end-- end loop sprite line posx=0 end -- end if gfx not nil end--end loop all gfx end function draw_particules() for i=1,#grpparticules do local part=grpparticules[i] if (part~=nil)then circ(part.x,part.y,flr((time()*20)%20)+7,flr((time()*10)%3)+7) end end end function draw_background() for i=1,#grpbackground do local bgp=grpbackground[i] if(bgp~=nil)then line(bgp.x,bgp.y,bgp.x,bgp.y+bgp.speed,5) end end end function game_draw() draw_background() draw_particules() draw_cgx() draw_ui() if(game.statut=="gameover")then rectfill(9,40,110,80,0) rect(10,40,110,80,1) print("game over",39,50,1) print("game over",40,50,5) print("press \151 to restart",19,65,1) print("press \151 to restart",20,65,5) end end function stscreen_draw() line(62,0,128,128,7) line(62,0,0,128,7) local p=45 local y=50 print("alpha war",p-1,y,7) print("alpha war",p+1,y,7) print("alpha war",p,y+1,7) print("alpha war",p,y-1,7) print("alpha war",p,y,6) print("by lyoy",48,60,6) print("push \151 to start",32,80,1) print("push \151 to start",31,80,8) end ------- updates ------- ----------------------- function stscreen_update() if(btnp(5) and game.scene=="start_screen")then --on lance la partie game.scene="game" game_init() end end function game_update() player:update() for i=1,#grpbackground do local bgpart=grpbackground[i] if(bgpart~=nil)then bgpart:update() end end for i=1,#grpparticules do local part=grpparticules[i] if(part~=nil)then part:update() end end --[[ debug --printh( flr((time()*5)%3)+1 ) --printh("firecooldown : "..player.firecooldown) --printh("firecooldown limit : "..player.firecooldownlimit) --printh(#grpprojectiles) for i=1,#grpenemies do local enemy=grpenemies[i] if (enemy~=nil)then enemy:update() if (lasttime!=timer1s) then --enemy:move() end--end if timer1s end--end check enemy nil end--end loop grpenemies for i=1,#grpprojectiles do local proj=grpprojectiles[i] if (proj~=nil) then proj:move() end--end if proj nil end--end loop projectiles if(game.statut=="game")then if(btn(0) == true and game.scene=="game" and player.x>-10) then player.x=player.x-1*player.speed end if(btn(1) == true and game.scene=="game" and player.x+player.w<130 )then player.x=player.x+1*player.speed --player.ecartx+=0.03 end if(btn(2) == true and game.scene=="game" and player.y>0 )then player.y=player.y-1*player.speed end if(btn(3) == true and game.scene=="game" and player.y+player.h<150 )then player.y=player.y+1*player.speed end if(btn(5) == true and game.scene=="game" and player.firecooldown==player.firecooldownlimit) then player:shoot() elseif(btnp(5) and game.scene=="game" and player.firecooldown>=player.firecooldownlimit-3 )then player:shoot() end lasttime=timer1s elseif(game.statut=="gameover")then if(btnp(5))then --game.statut="" --game_over() end end end