From 526eb88fd7a9253a488b8a826cb24422ffdf26f1 Mon Sep 17 00:00:00 2001 From: JailGamer Date: Sat, 2 May 2026 22:52:56 +0200 Subject: [PATCH] [NEW] Tile de la aranya animat --- data/stage1.lua | 2 +- data/tiles_layer2.lua | 80 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 72 insertions(+), 10 deletions(-) diff --git a/data/stage1.lua b/data/stage1.lua index 49bb740..3ddd4f5 100644 --- a/data/stage1.lua +++ b/data/stage1.lua @@ -154,7 +154,7 @@ function stages.stage1_init() tiles_layer2.new(13,11,3,144,144,16,16) tiles_layer2.new(13,11,4,144,144,16,16) - tiles_layer2.new(11,10,2,128,208,16,16) + tiles_layer2.new(11,10,2,128,208,16,16, tiles_layer2.update_aranya, tiles_layer2.draw_aranya) local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 ) -- local abad_x, abad_y = coords.room_to_world ( 54, 8, 3 ) diff --git a/data/tiles_layer2.lua b/data/tiles_layer2.lua index b5dab03..9168969 100644 --- a/data/tiles_layer2.lua +++ b/data/tiles_layer2.lua @@ -3,9 +3,9 @@ tiles_layer2={ tiles = {}, } -function tiles_layer2.new(_hab, _x, _y, _tx, _ty, _tw, _th) +function tiles_layer2.new(_hab, _x, _y, _tx, _ty, _tw, _th, _anim, _draw) local world_x, world_y = coords.room_to_world(_hab,_x,_y) - print(world_x.." "..world_y) + table.insert( tiles_layer2.tiles, { hab = _hab, @@ -17,25 +17,87 @@ function tiles_layer2.new(_hab, _x, _y, _tx, _ty, _tw, _th) ty = _ty, tw = _tw, th = _th, + off_x = 0, + off_y = 0, + draw = _draw, + anim = _anim, + anim_started = false, } ) end +function tiles_layer2.draw_tile( tile ) + local curr_surf = surf.source() + if tiles_layer2.surf ~= nil then + surf.source(tiles_layer2.surf) + end + local scr_x, scr_y = viewp:screen_coords( tile.x, tile.y ) + draw.surf(tile.tx, tile.ty, tile.tw, tile.th, + scr_x, scr_y, tile.tw, tile.th) + surf.source(curr_surf) +end + function tiles_layer2.draw() for i, tile in ipairs(tiles_layer2.tiles) do if viewp:inside(tile.x, tile.y, tile.w, tile.h) then - local curr_surf = surf.source() - if tiles_layer2.surf ~= nil then - surf.source(tiles_layer2.surf) + if tile.draw == nil then + tiles_layer2.draw_tile(tile) + else + tile.draw(tile) end - local scr_x, scr_y = viewp:screen_coords( tile.x, tile.y ) - draw.surf(tile.tx, tile.ty, tile.tw, tile.th, - scr_x, scr_y, tile.tw, tile.th) - surf.source(curr_surf) end end end function tiles_layer2.update() + for i, tile in ipairs(tiles_layer2.tiles) do + if viewp:inside(tile.x, tile.y, tile.w, tile.h) then + if tile.anim ~= nil then + tile.anim(tile) + end + end + end +end +function tiles_layer2.draw_aranya(tile) + local curr_surf = surf.source() + if tiles_layer2.surf ~= nil then + surf.source(tiles_layer2.surf) + end + local scr_x, scr_y = viewp:screen_coords( tile.x, tile.y ) + draw.line(scr_x+11, scr_y, scr_x+11+tile.off_x, scr_y+tile.off_y, 2) + draw.surf(tile.tx, tile.ty, tile.tw, tile.th, + scr_x+tile.off_x, scr_y+tile.off_y, tile.tw, tile.th) + surf.source(curr_surf) +end + +function tiles_layer2.update_aranya(tile) + if not tile.anim_started then + tile.wait = 6 + tile.step = 0 + tile.off_x= 0 + tile.off_y= 0 + tile.next_move = 16 + tile.vy = 1 + tile.anim_started = true + end + + tile.wait = tile.wait + 1 + if tile.wait>=6 then + tile.wait = 0 + if tile.off_y==0 or tile.off_y==8 then + tile.next_move = tile.next_move - 1 + if tile.next_move<=0 then + tile.next_move = 16+math.random(64) + if tile.off_y==0 then + tile.vy = 1 + else + tile.vy = -1 + end + tile.off_y = tile.off_y + tile.vy + end + else + tile.off_y = tile.off_y + tile.vy + end + end end \ No newline at end of file