diff --git a/data/abad.lua b/data/abad.lua index 40fd393..2eb3a91 100644 --- a/data/abad.lua +++ b/data/abad.lua @@ -44,6 +44,7 @@ function abad_init() step=0, mustep=1, stairs_flip=false, + stairs_moves=0, --contador de moviments dins de les escales draw=abad.draw, hurting=0, update=nil, @@ -99,13 +100,22 @@ function abad:draw() local flip = abad.flip local x, y = viewp:screen_coords(self.x, self.y) if abad.update==abad_state_stairs then - flip=abad.stairs_flip - -- flip=(((abad.x>>1)+(abad.y>>1))%2)==0 - if ((abad.x+abad.y)%12)==0 then abad.stairs_flip=not abad.stairs_flip end - local msg = "-- "..abad.x.." "..abad.y - if flip then msg = "FLIP"..abad.x.." "..abad.y end - -- msg_print(0,35,msg,true) + -- flip=abad.stairs_flip + -- -- flip=(((abad.x>>1)+(abad.y>>1))%2)==0 + if math.abs(abad.stairs_moves-(abad.x+abad.y))>12 then + abad.stairs_moves = abad.x+abad.y + abad.flip = not abad.flip + end + flip = abad.flip + -- if ((abad.x+abad.y)%12)==0 then + -- abad.stairs_flip=not abad.stairs_flip + -- end + + -- local msg = "-- "..abad.x.." "..abad.y + -- if flip then msg = "FLIP"..abad.x.." "..abad.y end + -- -- msg_print(0,35,msg,true) end + if (abad.respawning==0) or (math.floor(abad.respawning/15)%2==0) then draw.surf(abad.frame*abad.w,0,abad.w,abad.h,x,y,abad.w,abad.h,flip) -- caminant, parat, disparant o saltant @@ -139,7 +149,7 @@ function abad_heal(howmuch) end function abad_hurt(howmuch) - -- howmuch = 0 + howmuch = 0 if abad.hurting == 0 and abad.respawning==0 then sound.play(audio_abad_hit) abad.energia=abad.energia-howmuch @@ -298,6 +308,38 @@ function abad_land () return can_land end +function abad_in_stairs(next_x, next_y) + next_x = next_x or 0 + next_y = next_y or 0 + local x1_check = abad.x+abad.bb.x+next_x + local x2_check = abad.x+abad.bb.x+abad.bb.w+next_x + local y1_check = abad.y+next_y + local y2_check = abad.y+abad.bb.h+next_y + + if arc_check_tile(x1_check, y1_check)==tiletype.stair or + arc_check_tile(x2_check, y1_check)==tiletype.stair or + arc_check_tile(x1_check, y2_check)==tiletype.stair or + arc_check_tile(x2_check, y2_check)==tiletype.stair + then + return true + end + + return false +end + +function abad_in_floor(next_x, next_y) + local x1_check = abad.x+abad.bb.x+next_x + local x2_check = abad.x+abad.bb.x+abad.bb.w+next_x + local y2_check = abad.y+abad.bb.h+next_y + if arc_check_tile(x1_check, y2_check)==tiletype.block or + arc_check_tile(x2_check, y2_check)==tiletype.block + then + return true + end + + return false +end + function abad_advance() local step_length=abad.step_length; --lo que avança l'abad cada pas local limit=tiletype.block @@ -315,12 +357,25 @@ function abad_advance() abad.x=abad.x+step_length end - if arc_check_tile(x_check,y_check)==tiletype.stair then - abad.update=abad_state_stairs - elseif abad.update==abad_state_stairs then + -- if arc_check_tile(x_check,y_check)==tiletype.stair then + -- print("STAIRS "..math.random(50)) + -- if abad.update~=abad_state_stairs and controller:check("up") + -- then + -- print("UPDATE STAIRS") + -- abad.update=abad_state_stairs + -- end + -- elseif abad.update==abad_state_stairs then + -- abad.update=abad_state_normal + -- abad.frame=0 + -- end + + if not abad_in_stairs() and + abad.update==abad_state_stairs + then abad.update=abad_state_normal abad.frame=0 end + local hab,xx, yy = coords.world_to_tile(abad.x, abad.y) abad.hab = hab end @@ -354,13 +409,19 @@ function abad_state_normal() if controller:check("right") then abad.update=abad_state_walking abad.flip=false + elseif controller:check("up") and abad_in_stairs() then + abad.update=abad_state_stairs elseif controller:check("left") then abad.update=abad_state_walking abad.flip=true elseif controller:check("jump") then abad_do_jump() elseif controller:check("down") then - abad.update=abad_state_crouch + if abad_in_stairs() then + abad.update=abad_state_stairs + else + abad.update=abad_state_crouch + end --elseif btn(KEY_Z) then -- abad.respawning=240 elseif controller:check("shoot") then @@ -520,32 +581,46 @@ end function abad_state_stairs() abad.frame=4 abad.wait=abad.wait+1 + local moved = false - local x1_check = abad.x+abad.bb.x - local x2_check = abad.x+abad.bb.x+abad.bb.w-1 - local y_check = abad.y+abad.bb.h-1 + --local x1_check = abad.x+abad.bb.x + --local x2_check = abad.x+abad.bb.x+abad.bb.w-1 + --local y_check = abad.y+abad.bb.h if controller:check("right") then abad.flip=false abad_advance() - if abad.wait==6 then sound.play(audio_low) end + moved = true elseif controller:check("left") then abad.flip=true abad_advance() - if abad.wait==6 then sound.play(audio_low) end + moved = true elseif controller:check("up") then - if arc_check_tile(x1_check,y_check)==tiletype.stair and - arc_check_tile(x2_check,y_check)==tiletype.stair then + --y_check = y_check - 1 + --if arc_check_tile(x1_check,y_check)==tiletype.stair and + -- arc_check_tile(x2_check,y_check)==tiletype.stair then + -- abad.y=abad.y-1 + -- if abad.wait==6 then sound.play(audio_low) end + --end + if abad_in_stairs(0,-1) then abad.y=abad.y-1 - if abad.wait==6 then sound.play(audio_low) end + moved = true end elseif controller:check("down") then - if arc_check_tile(x1_check,y_check)==tiletype.stair and - arc_check_tile(x2_check,y_check)==tiletype.stair then + -- y_check = y_check + 1 + -- if arc_check_tile(x1_check,y_check)==tiletype.stair and + -- arc_check_tile(x2_check,y_check)==tiletype.stair then + -- abad.y=abad.y+1 + -- if abad.wait==6 then sound.play(audio_low) end + -- end + if abad_in_stairs(0,1) and not abad_in_floor(0,0) then abad.y=abad.y+1 - if abad.wait==6 then sound.play(audio_low) end + moved = true + else + --abad.update=abad_state_normal end end + if moved and abad.wait==6 then sound.play(audio_low) end if abad.wait==6 then abad.wait=0 end end \ No newline at end of file diff --git a/data/game.lua b/data/game.lua index 18fcbc4..7fefcef 100644 --- a/data/game.lua +++ b/data/game.lua @@ -27,7 +27,7 @@ require "batman" require "health_potion" require "tiles_layer2" -local DEBUG = true +local DEBUG = false local tile_w = arcade_config.tiles_width local tile_h = arcade_config.tiles_height diff --git a/data/trigger.lua b/data/trigger.lua index 36284b8..54f6b43 100644 --- a/data/trigger.lua +++ b/data/trigger.lua @@ -64,7 +64,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()