- La càmara segueix al "heroi"

This commit is contained in:
2023-01-30 18:16:03 +01:00
parent 09bea06850
commit 3e608882c9
2 changed files with 10 additions and 4 deletions

View File

@@ -65,9 +65,9 @@ actors={
elseif step=='a' then elseif step=='a' then
v.o='d' v.o='d'
elseif step=='o' then elseif step=='o' then
v.o='r'
elseif step=='p' then
v.o='l' v.o='l'
elseif step=='p' then
v.o='r'
end end
end end
end end

View File

@@ -3,12 +3,19 @@ game={
init=function() init=function()
mapa.load("test.map") mapa.load("test.map")
actors.add({name="usufondo",x=11,y=9,o="r",gfx={x=0,y=0},path={pos=0,route='rrrrura'}}) actors.add({name="usufondo",x=11,y=9,o="r",gfx={x=0,y=0},path={pos=0,route='rrrruro'}})
actors.add({name="jailer",x=6,y=9,o="r",gfx={x=32,y=0}}) actors.add({name="jailer",x=6,y=9,o="r",gfx={x=32,y=0}})
update=game.update update=game.update
end, end,
update=function() update=function()
local hero = actors.search("jailer")
if hero then
game.cam.x = hero.x*8 + hero.dx*2 - 80
if game.cam.x < 0 then game.cam.x=0 end
game.cam.y = hero.y*8 + hero.dy*2 - 72
if game.cam.y < 0 then game.cam.y=0 end
end
camera(game.cam.x, game.cam.y) camera(game.cam.x, game.cam.y)
setsource(tiles) setsource(tiles)
map(0,0,0,0,mapa.w, mapa.h) map(0,0,0,0,mapa.w, mapa.h)
@@ -16,7 +23,6 @@ game={
actors.draw() actors.draw()
camera(0,0) camera(0,0)
local hero = actors.search("jailer")
if hero and not hero.path and hero.dx+hero.dy==0 then if hero and not hero.path and hero.dx+hero.dy==0 then
if btn(KEY_DOWN) then if btn(KEY_DOWN) then
hero.path={pos=0,route='d'} hero.path={pos=0,route='d'}