From 8e3117d5bc4e9e99b3c2e5d1469d438cea86df67 Mon Sep 17 00:00:00 2001 From: JailGamer Date: Thu, 30 Apr 2026 23:42:49 +0200 Subject: [PATCH] =?UTF-8?q?[NEW]=20Escena=20habitaci=C3=B3=20de=20Batman?= =?UTF-8?q?=20funcionant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/batman.lua | 254 +++++++++++++++++++++++++++++++++++++++++++++++ data/game.lua | 2 + data/stage1.lua | 4 +- data/trigger.lua | 2 +- 4 files changed, 259 insertions(+), 3 deletions(-) create mode 100644 data/batman.lua diff --git a/data/batman.lua b/data/batman.lua new file mode 100644 index 0000000..aaec2bd --- /dev/null +++ b/data/batman.lua @@ -0,0 +1,254 @@ +local arcade_config = require("arcade_config") +o2aX = arcade_config.org2arc_escala +cxr = arcade_config.character_per_row-1 +cxr2 = arcade_config.character_per_row_base2 +cw = arcade_config.character_width +ch = arcade_config.character_height + +batman={hab=5,x=24,y=24,flip=true,goup=true,frame=8,stairscooldown=0,stepscooldown=0,stepsremember=0,wait=0,step=0,anim={24,25,24,26},bb={x=4,y=0,w=8,h=16},scene_intro=false,scene_object=false} + +function batman.init() + batman.hit=batman.hit + batman.update=batman.update_normal + batman.draw=batman.draw + local habs={5,9,46,36,18} + batman.hab=habs[1+math.random(0,#habs-1)] + batman.x=24 + batman.y=24 +end + +function batman.draw() + local flip=batman.flip + if batman.update==batman.update_stairs then + flip=(((batman.x>>1)+(batman.y>>1))%2)==0 + end + -- draw.surf((batman.frame&7)*16,(batman.frame>>3)*16,16,16,batman.x,batman.y,16,16,flip) + draw.surf((batman.frame&7)*cw,(batman.frame>>cxr2)*ch,cw,ch,batman.x*o2aX,batman.y*o2aX,cw,ch,flip) +end + +function batman.hit() + if abad.objects.bol~=nil then + batman.endgame=true + -- Start end of the game + start_scene(scenes.final) + end +end + +function batman.update_normal() + batman.wait=batman.wait+1 + + if batman.wait>=6 then + batman.wait=0 + if batman.stairscooldown>0 then batman.stairscooldown=batman.stairscooldown-1 end + batman.step=(batman.step+1)%4 + if batman.stepscooldown>0 then batman.stepscooldown=batman.stepscooldown-1 end + batman.frame=batman.anim[batman.step+1] + + local inc=12 if batman.flip then inc=2 end + if not batman.flip and batman.x==84 then + batman.hab=batman.hab+1 + batman.x=-4 + elseif check_tile(batman.hab,batman.x+inc,batman.y+14)==tiletype.nonpc then + --if rnd(10)<8 then + batman.update=batman.update_jumping + batman.step=0 + --else + -- batman.flip=not batman.flip + --end + elseif check_tile(batman.hab,batman.x+inc,batman.y+14)0 and check_tile(batman.hab,batman.x+inc,batman.y+14)==tiletype.half then r=batman.stepsremember end + if r==0 then + batman.update=batman.update_jumping + batman.step=0 + else + if batman.flip then + batman.x=batman.x-2 + else + batman.x=batman.x+2 + end + if batman.x<-4 then + batman.hab=batman.hab-1 + batman.x=84 + end + end + if batman.stepscooldown==0 then + batman.stepscooldown=30 + batman.stepsremember=r + end + else + --if check_tile(batman.hab,batman.x+4,batman.y+16)==tiletype.void and ((batman.x+4)&7==0 or check_tile(batman.hab,batman.x+12,batman.y+16)==tiletype.void) then + --batman.update=batman.update_falling + --else + batman.flip=not batman.flip + --end + end + + if batman.stairscooldown==0 and + check_tile(batman.hab,batman.x+6,batman.y+8)==tiletype.stair and + check_tile(batman.hab,batman.x+14,batman.y+8)==tiletype.stair then + if math.random(0,9)<8 then + batman.update=batman.update_stairs + if check_tile(batman.hab,batman.x+4,batman.y+16)==tiletype.block then + batman.goup=true + else + batman.goup=false + end + --batman.goup=rnd(2)==0 and true or false + else + batman.stairscooldown=50 + end + elseif batman.update==batman.update_stairs then + batman.stairscooldown=50 + batman.update=batman.update_normal + batman.frame=24 + end + + if check_tile(batman.hab,batman.x+4,batman.y+16)==tiletype.void and ((batman.x+4)&7==0 or check_tile(batman.hab,batman.x+12,batman.y+16)==tiletype.void) then + local option=math.random(0,1) + if batman.stairscooldown>0 then option=0 end + if option==0 then + batman.update=batman.update_falling + else + batman.update=batman.update_jumping + batman.step=0 + batman.wait=0 + --else + -- batman.flip=not batman.flip + end + end + + if batman.hab==abad.hab then + if aabb(abad,batman) then + abad_hurt(40) + end + end + + end +end + +function batman.update_jumping() + batman.frame=25 + batman.wait=batman.wait+1 + + if batman.wait>=6 then + batman.wait=0 + + local inc=12 if batman.flip then inc=2 end + if not batman.flip and batman.x==84 then + batman.hab=batman.hab+1 + batman.x=-4 + elseif check_tile(batman.hab,batman.x+inc,batman.y+14)0 then + if check_tile(batman.hab,batman.x+4,batman.y-2)~=tiletype.block then + if (batman.x+4)&7==0 or check_tile(batman.hab,batman.x+12,batman.y-2)~=tiletype.block then + batman.y=batman.y-2 + end + end + else + batman.hab=batman.hab-10 + batman.y=32 + end + elseif batman.step>6 then + batman.update=batman.update_falling + end + batman.step=batman.step+1 + end + +end + +function batman.update_falling() + batman.frame=25 + batman.wait=batman.wait+1 + + if batman.wait>=6 then + batman.wait=0 + + local inc=12 if batman.flip then inc=2 end + if not batman.flip and batman.x==84 then + batman.hab=batman.hab+1 + batman.x=-4 + elseif check_tile(batman.hab,batman.x+inc,batman.y+14)=tiletype.half or ((batman.x+4)&7~=0 and check_tile(batman.hab,batman.x+12,batman.y+16)>=tiletype.half)) then + batman.update=batman.update_normal + return + end + batman.y=batman.y+2 + else + batman.hab=batman.hab+10 + batman.y=0 + end + end +end + +function batman.update_stairs() + batman.frame=27 + batman.wait=batman.wait+1 + + if batman.wait>=6 then + batman.wait=0 + + if batman.goup then + if batman.y>0 then + if check_tile(batman.hab,batman.x+4,batman.y+8)==tiletype.stair or (batman.x+4)&7~=0 and check_tile(batman.hab,batman.x+12,batman.y+8)==tiletype.stair then + batman.y=batman.y-2 + else + batman.update=batman.update_normal + if math.random(0,2)>0 then batman.flip=not batman.flip end + batman.stairscooldown=50 + end + else + batman.hab=batman.hab-10 + batman.y=32 + end + else + if batman.y<32 then + if check_tile(batman.hab,batman.x+4,batman.y+16)==tiletype.stair or (batman.x+4)&7~=0 and check_tile(batman.hab,batman.x+12,batman.y+16)==tiletype.stair then + batman.y=batman.y+2 + else + batman.update=batman.update_normal + if math.random(0,2)>0 then batman.flip=not batman.flip end + batman.stairscooldown=50 + end + else + batman.hab=batman.hab+10 + batman.y=0 + end + end + end +end \ No newline at end of file diff --git a/data/game.lua b/data/game.lua index c81d3bf..69bdec4 100644 --- a/data/game.lua +++ b/data/game.lua @@ -23,6 +23,8 @@ require "remote_view" require "dialeg" require "trigger_event" +require "batman" + local DEBUG = false local tile_w = arcade_config.tiles_width diff --git a/data/stage1.lua b/data/stage1.lua index 681f5fc..86dace4 100644 --- a/data/stage1.lua +++ b/data/stage1.lua @@ -103,7 +103,7 @@ function stages.stage1_init() table.insert( actors, trigger.new(53,5,3,triggers.escena_abad_porta_casa,"porta casa","TR06")) table.insert( actors, trigger.new(56,4,3,triggers.escena_abad_porta_batman,"porta batman","TR07")) - table.insert( actors, trigger.new(19,32,32,triggers.escena_habitacio_batman,"habitacio batman")) + table.insert( actors, trigger.new(19,4,3,triggers.escena_habitacio_batman,"habitacio batman")) -- table.insert( actors, trigger.new(55,1,3,triggers.escena_lluita_imp,"lluita imp")) @@ -140,7 +140,7 @@ function stages.stage1_init() zombie2, abad, 150, "Aaaaaargh... per ell!", 250) local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 ) - -- local abad_x, abad_y = coords.room_to_world ( 56, 7, 3 ) + local abad_x, abad_y = coords.room_to_world ( 9, 4, 3 ) abad:move(abad_x, abad_y) abad_make_safe( true ) diff --git a/data/trigger.lua b/data/trigger.lua index 910ae15..ba03aa7 100644 --- a/data/trigger.lua +++ b/data/trigger.lua @@ -57,7 +57,7 @@ function trigger:draw() end -- debug rect - -- draw.rect(scr_x,scr_y,self.bb.w,self.bb.h,3) + draw.rect(scr_x,scr_y,self.bb.w,self.bb.h,3) end --function trigger:do_touched()