diff --git a/data/abad.lua b/data/abad.lua index cf9f79e..b9ee80c 100644 --- a/data/abad.lua +++ b/data/abad.lua @@ -144,6 +144,10 @@ function abad_make_safe( force ) end end +function abad_lifes_up(howmuch) + abad.vides = abad.vides + howmuch +end + function abad_heal(howmuch) abad.energia = abad.energia + howmuch if abad.energia>abad.max_energia then diff --git a/data/game.lua b/data/game.lua index 31d82a2..f1f92b3 100644 --- a/data/game.lua +++ b/data/game.lua @@ -26,6 +26,7 @@ require "trigger_event" require "batman" require "health_potion" +require "one_up" require "tiles_layer2" require "batvio" -- require "live_scene" diff --git a/data/one_up.lua b/data/one_up.lua new file mode 100644 index 0000000..fbaa6d5 --- /dev/null +++ b/data/one_up.lua @@ -0,0 +1,70 @@ +one_up_gif_x = 208 +one_up_gif_y = 128 + +one_up={} + +function one_up.new(_hab, _x, _y, _y_speed, _max_height, _flip) + _raising = false + if _max_height>0 then _raising=true end + return { + name="one_up", + hab = _hab, + x = _x, y = _y, + w = 16, h = 16, + flip = _flip, + vx=0, vy=0, + y_speed = _y_speed, + max_height = _max_height, + raising = _raising, + enabled=true, + wait = 0, + bb={x=4,y=0,w=9,h=16}, + update=one_up.update, + draw=one_up.draw, + } +end + +function one_up:draw() + if not self.enabled then return end + local x = one_up_gif_x + local y = one_up_gif_y + local scr_x, scr_y = viewp:screen_coords( self.x, self.y ) + draw.surf(x,y,self.w,self.h,scr_x,scr_y,self.w,self.h,self.flip) + + -- draw.rect(scr_x+one_up.bb.x,scr_y+one_up.bb.y,one_up.bb.w,one_up.bb.h,3) +end + +function one_up:update() + if not self.enabled then return end + if self.raising and self.y_speed>0 then + self.y_speed = -self.y_speed + elseif not self.raising and self.y_speed<0 then + self.y_speed = -self.y_speed + end + + local x2_check = self.x+self.bb.x+self.bb.w + local x1_check = self.x+self.bb.x + local y_check = self.y+self.bb.h+self.y_speed + + if true then + self.wait=0 + self.max_height = self.max_height+self.y_speed + self.y = self.y+self.y_speed + if self.max_height==0 then self.raising=false end + end + self.wait=self.wait+1 + + local tile1_hit_type= arc_check_tile(x1_check, y_check ) + local tile2_hit_type= arc_check_tile(x2_check, y_check) + local block_tile = tile1_hit_type == tiletype.block or tile2_hit_type == tiletype.block + + if block_tile then self.y_speed=0 end + self.hab = coords.world_to_tile(self.x, self.y) + if self.hab==abad.hab then + if collision(abad,self) then + abad_lifes_up(1) + self.enabled = false + remove_actor(self) + end + end +end \ No newline at end of file diff --git a/data/stage1.lua b/data/stage1.lua index b088137..00a27f1 100644 --- a/data/stage1.lua +++ b/data/stage1.lua @@ -128,7 +128,8 @@ function stages.stage1_init() table.insert( actors, trigger.new(75,6,1,triggers.open_door,"","pasillo inf","switch",{77, 50,38,26}) ) table.insert( actors, trigger.new(75,9,1,triggers.open_door,"","acces inf casa batman","switch",{57, 53,41},{"TR07"}) ) table.insert( actors, trigger.new(79,5,1,triggers.open_door,"","sotan casa batman","switch",{36, 56,44}) ) - table.insert( actors, trigger.new(38,2,2,triggers.open_door,"","","switch",{39, 62,63}) ) + -- table.insert( actors, trigger.new(38,2,2,triggers.open_door,"","","switch",{39, 62,63}) ) + table.insert( actors, trigger.new(38,2,2,triggers.add_1up,"","","switch",{39, 62,63}) ) table.insert( actors, trigger.new(35,1,3,triggers.open_door,"","batman a casa abad (1/2)","invisible",{36, 12,24 }) ) table.insert( actors, trigger.new(35,1,3,triggers.open_door,"","batman a casa abad (2/2)","invisible",{35, 23,35 }) ) diff --git a/data/trigger.lua b/data/trigger.lua index 4264c4e..543a8a5 100644 --- a/data/trigger.lua +++ b/data/trigger.lua @@ -87,6 +87,12 @@ function triggers:open_door() end end +function triggers:add_1up() + local x, y = coords.room_to_world(38, 8, 1) + table.insert( actors, one_up.new(38, x, y, 1, 0, true) ) + triggers.open_door(self) +end + function triggers:escena_abad_inici() start_scene(scenes.abad_inici) remove_actor(self)