diff --git a/batman.lua b/batman.lua index 4976187..125fca0 100644 --- a/batman.lua +++ b/batman.lua @@ -18,6 +18,7 @@ end function batman.hit() if abad.objects.bol~=nil then + batman.endgame=true -- Start end of the game start_scene(scenes.final) end diff --git a/fade.lua b/fade.lua new file mode 100644 index 0000000..5d4e5c5 --- /dev/null +++ b/fade.lua @@ -0,0 +1,99 @@ +fade = { + table={13,15,5,3,12,5,6,7,12,9,10,16,9,13,14}, + pal={}, + old_update=nil, + wait=0, + step=0, + outin=false, + + init = function() + for i=1,15 do + local r,g,b=getcolor(i) + fade.pal[i]={r,g,b} + end + end, + + getstep=function(num,steps) + if steps==0 or num==16 then return num end + for i=1,steps do + num=fade.table[num] + if num==16 then return num end + end + return num + end, + + fadeout = function() + --print("fading out") + fade.old_update=_update + _update=fade.update_fadeout + fade.wait=0 + fade.step=0 + end, + + fadeoutin = function() + --print("fading outin") + fade.old_update=_update + _update=fade.update_fadeout + fade.wait=0 + fade.step=0 + fade.outin=true + end, + + update_fadeout=function() + --print("out") + fade.wait=fade.wait+1 + if fade.wait==6 then + fade.wait=0 + for i=1,15 do + local v=fade.getstep(i,fade.step) + --print(v) + if v==16 then + setcolor(i,0,0,0) + else + setcolor(i,fade.pal[v][1],fade.pal[v][2],fade.pal[v][3]) + end + end + fade.step=fade.step+1 + if fade.step==7 then + _update = fade.old_update + if fade.outin then + fade.outin=false; + fade.fadein() + end + end + end + end, + + fadein = function() + --print("fading in") + fade.old_update=_update + _update=fade.update_fadein + fade.wait=0 + fade.step=6 + for i=1,15 do setcolor(i,0,0,0) end + end, + + update_fadein=function() + --print("in") + fade.old_update() + + fade.wait=fade.wait+1 + if fade.wait==6 then + fade.wait=0 + for i=1,15 do + local v=fade.getstep(i,fade.step) + --print(v) + if v==16 then + setcolor(i,0,0,0) + else + setcolor(i,fade.pal[v][1],fade.pal[v][2],fade.pal[v][3]) + end + end + fade.step=fade.step-1 + if fade.step<0 then + _update = fade.old_update + end + end + end + +} diff --git a/final.lua b/final.lua index 2245136..55e2728 100644 --- a/final.lua +++ b/final.lua @@ -5,14 +5,17 @@ function final_init() cameras={} current_actor=1 - --table.insert(actors,zombie.new(2,24,24,false)) - abad.update = abad_nop _update=update_final next_actor() play(audio_final) + local r,g,b=getcolor(15) + setcolor(17,r,g,b) + --fade.fadein() end +go_next_actor=false + function update_final() cls(16) @@ -25,7 +28,7 @@ function update_final() rectfill(114,0,191,96,16) rect(15,40,113,89,2) - text("C A C A U S", 42, 12, 15) + text("C A C A U S", 42, 12, 17) text(actor.name, 64-(#actor.name*2), 28, 11) mapa_update(abad.hab,final_room) @@ -38,6 +41,8 @@ function update_final() play(audio_final) end end + + if go_next_actor then next_actor() end end function init_actor(name,flipped,w,h,anim) @@ -80,7 +85,9 @@ function draw_actor() end if actor.x>96 or actor.x<-actor.w or (#actor.anim==1 and actor.center_count==0) then - next_actor() + go_next_actor=true + fade.fadeoutin() + return true end end end @@ -89,6 +96,8 @@ function draw_actor() end function next_actor() + go_next_actor=false + faded = true if current_actor==1 then init_actor("ZOMBIE",false,16,16,{16,17,16,18}) elseif current_actor==2 then @@ -117,11 +126,32 @@ function next_actor() init_actor("BATMAN",false,16,16,{24,25,24,26}) elseif current_actor==13 then init_actor("EL ABAD",true,16,16,{0,1,0,2}) + elseif current_actor==14 then + final_count=0 + _update=update_final2 + fade.fadeoutin() end final_room=final_rooms[current_actor] current_actor=current_actor+1 end ----bol de cacaus ---batman ---abad +function update_final2() + cls(16) + + text("C A C A U S", 42, 12, 17) + text("GRACIES PER JUGAR", 30, 48, 10) + + if btnp(KEY_M) then + mute = not mute + if mute then + stopchirp() + else + play(audio_final) + end + end + final_count=final_count+1 + if final_count==200 or btnp(KEY_SPACE) or btnp(KEY_RETURN) then + game_init(true) + fade.fadeoutin() + end +end diff --git a/game.ini b/game.ini index 68e9a87..09005f2 100644 --- a/game.ini +++ b/game.ini @@ -2,4 +2,4 @@ title=Cacaus width=128 height=96 zoom=5 -files=final.lua,audio.lua,dead.lua,scenes.lua,trigger.lua,score.lua,switches.lua,map.lua,mapa.lua,bol.lua,invisible.lua,gota.lua,fireball.lua,cacau.lua,bambolla.lua,imp.lua,gps.lua,peu.lua,gorro.lua,batman.lua,elalien.lua,premiere.lua,caco.lua,zombie.lua,abad.lua,intro.lua,game.lua,main.lua +files=final.lua,fade.lua,audio.lua,dead.lua,scenes.lua,trigger.lua,score.lua,switches.lua,map.lua,mapa.lua,bol.lua,invisible.lua,gota.lua,fireball.lua,cacau.lua,bambolla.lua,imp.lua,gps.lua,peu.lua,gorro.lua,batman.lua,elalien.lua,premiere.lua,caco.lua,zombie.lua,abad.lua,intro.lua,game.lua,main.lua diff --git a/game.lua b/game.lua index 5265487..cb46ee4 100644 --- a/game.lua +++ b/game.lua @@ -97,7 +97,7 @@ function game_init(menu) table.insert(actors,caco.new(17,24,16,false)) -- TRIGGERS - if not menu then table.insert(actors,trigger.new(10,44,32,triggers.escena_abad_inici)) end + if not menu then table.insert(actors,trigger.new(10,57,32,triggers.escena_abad_inici)) end table.insert(actors,trigger.new(11,16,32,triggers.escena_abad_corfes)) table.insert(actors,trigger.new(31,12,32,triggers.escena_abad_portes)) @@ -128,7 +128,9 @@ function game_init(menu) play(audio_main_song) else _update=update_game + stopchirp() end + --fade.fadein() end function text(str,x,y,col) @@ -348,6 +350,7 @@ function update_menu() if btnp(KEY_SPACE) then game_exit() game_init() + fade.fadeoutin() elseif btnp(KEY_M) then mute = not mute if mute then diff --git a/intro.lua b/intro.lua index 9ebb4f5..a2ce5b0 100644 --- a/intro.lua +++ b/intro.lua @@ -12,6 +12,7 @@ function intro_init() setsource(logo) sspr(0,0,36,5,28,35,72,10) setsource(tiles) + fade.fadein() end function intro_intro() @@ -19,15 +20,9 @@ function intro_intro() text("presenta",48,50,14) intro_wait=intro_wait-1 if intro_wait==0 or btnp(KEY_ESCAPE) or btnp(KEY_SPACE) then - cls(16) - rect(15,3,113,53,2) - camera(-16,-4) - mapa_draw(10) - rectfill(73,24,79,39,16) - sspr(0,0,16,16,44,24,16,16,true) - camera(0,0) - intro_wait=40 + intro_wait=1 _update = intro_update + fade.fadeoutin() end if btnp(KEY_M) then mute = not mute @@ -35,10 +30,13 @@ function intro_intro() end function intro_update() + --print("intro_update") --play(audio_main_song) --game_init(true) if btnp(KEY_ESCAPE) then game_init(true) + elseif btnp(KEY_SPACE) then + intro_wait=1 elseif btnp(KEY_M) then mute = not mute end @@ -46,9 +44,18 @@ function intro_update() intro_wait=intro_wait-1 if intro_wait==0 then if intro_step==0 then - start_scene(scenes.intro_01,58) - intro_step=1 + cls(16) + rect(15,3,113,53,2) + camera(-16,-4) + mapa_draw(10) + rectfill(73,24,79,39,16) + sspr(0,0,16,16,44,24,16,16,true) + camera(0,0) + intro_step=intro_step+1 elseif intro_step==1 then + start_scene(scenes.intro_01,58) + intro_step=intro_step+1 + elseif intro_step==2 then cls(16) rect(15,3,113,53,2) camera(-16,-4) @@ -56,11 +63,11 @@ function intro_update() rectfill(73,24,79,39,16) sspr(0,0,16,16,44,24,16,16,false) camera(0,0) - intro_step=2 - elseif intro_step==2 then - start_scene(scenes.intro_02,58) - intro_step=3 + intro_step=intro_step+1 elseif intro_step==3 then + start_scene(scenes.intro_02,58) + intro_step=intro_step+1 + elseif intro_step==4 then cls(16) rect(15,3,113,53,2) camera(-16,-4) @@ -70,11 +77,11 @@ function intro_update() sspr(112,88,16,8,76,32,16,8,true) sspr(0,48,16,16,82,24,16,16,true) camera(0,0) - intro_step=4 - elseif intro_step==4 then - start_scene(scenes.intro_03,58) - intro_step=5 + intro_step=intro_step+1 elseif intro_step==5 then + start_scene(scenes.intro_03,58) + intro_step=intro_step+1 + elseif intro_step==6 then cls(16) rect(15,3,113,53,2) camera(-16,-4) @@ -82,14 +89,15 @@ function intro_update() rectfill(73,24,79,39,16) sspr(0,0,16,16,44,24,16,16,false) camera(0,0) - intro_step=6 - elseif intro_step==6 then - start_scene(scenes.intro_04,58) - intro_step=7 + intro_step=intro_step+1 elseif intro_step==7 then + start_scene(scenes.intro_04,58) + intro_step=intro_step+1 + elseif intro_step==8 then play(audio_main_song) game_init(true) + fade.fadeoutin() end - intro_wait=40 + intro_wait=50 end end \ No newline at end of file diff --git a/main.lua b/main.lua index f6df7ce..3bc79ff 100644 --- a/main.lua +++ b/main.lua @@ -6,10 +6,11 @@ function _init() logo=newsurf(36,5) back=newsurf(128,96) + fade.init() --game_init() - --intro_init() - final_init() + intro_init() + --final_init() end function _update() end diff --git a/scenes.lua b/scenes.lua index 34e737c..acde26d 100644 --- a/scenes.lua +++ b/scenes.lua @@ -231,7 +231,12 @@ function update_scene() scenes.die=scenes.die-1 if scenes.die==0 then if scenes.dnum==#scenes.current_scene then - _update=old_update + if batman.endgame then + final_init() + fade.fadeoutin() + else + _update=old_update + end else scenes.dnum=scenes.dnum+1 scenes.die=scenes.current_scene[scenes.dnum].die or 0 @@ -250,8 +255,12 @@ function update_scene() elseif btnp(KEY_SPACE) then if scenes.step>8 then if scenes.dnum==#scenes.current_scene then - --freesurf(bkg) - _update=old_update + if batman.endgame then + final_init() + fade.fadeoutin() + else + _update=old_update + end else scenes.dnum=scenes.dnum+1 scenes.step=2 diff --git a/tiles.gif b/tiles.gif index d249565..1584876 100644 Binary files a/tiles.gif and b/tiles.gif differ