- [NEW] Ja lleva o fica els items segons l'habitació que entra

This commit is contained in:
2025-11-14 20:08:26 +01:00
parent 6db92c3df6
commit 8dc76e1382
4 changed files with 17 additions and 12 deletions

View File

@@ -31,7 +31,7 @@ game = {
game.chg_step = 8
sprites.pause_ia = true
-- [TODO] Crear els sprites per als items de l'habitació a la que entrem
sprites.add_from_room()
sprites.add_from_room(rooms.pos.x+x*20, rooms.pos.y+y*12)
app.push(game.update_change_room)
end,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 995 B

After

Width:  |  Height:  |  Size: 999 B

View File

@@ -17,23 +17,27 @@ sprites = {
end,
remove_out_of_room = function()
print("Current room: "..rooms.current())
for i,v in ipairs(sprites.list) do
if v.room ~= rooms.current() then
table.remove(sprites.list, i)
print("Sprite removed: "..v.type)
local room = v.room or 0
print("Sprite at room "..room.." removed: "..v.type)
end
end
end,
add_from_room = function()
add_from_room = function(rx,ry)
map.surf(rooms.surf_items)
for y = rooms.pos.y, rooms.pos.y+19 do
for x = rooms.pos.x, rooms.pos.x+11 do
--if surf.pixel(x,y) ~= 0 then
io.write(map.tile(x,y)..",")
--end
for y = ry, ry+11 do
for x = rx, rx+19 do
if map.tile(x,y) ~= 0 then
local room = (rx//20) + (ry//12) * 8
io.write("crear "..items[map.tile(x,y)].name.." en hab "..room.." ("..x..","..y..")...\n")
table.insert(sprites.list, templates.create(items[map.tile(x,y)].name, {pos={x=x*8, y=y*8},flipped=true, room=room}))
end
io.write("\n")
end
--io.write("\n")
end
end,
@@ -113,14 +117,14 @@ sprites = {
update_mummy = function(spr)
if spr.state == templates.ALIVE then
if spr.flipped then
local tx, ty = (spr.pos.x+3)>>3, (spr.pos.y+16)>>3
local tx, ty = (spr.pos.x+3)>>3, (spr.pos.y+15)>>3
if map.tile(tx,ty) < 16 and map.tile(tx,ty-1) < 16 and map.tile(tx,ty+1) > 0 then
spr.pos.x = spr.pos.x - 1
else
spr.flipped = not spr.flipped
end
else
local tx, ty = (spr.pos.x+12)>>3, (spr.pos.y+16)>>3
local tx, ty = (spr.pos.x+12)>>3, (spr.pos.y+15)>>3
if map.tile(tx,ty) < 16 and map.tile(tx,ty-1) < 16 and map.tile(tx,ty+1) > 0 then
spr.pos.x = spr.pos.x + 1
else

View File

@@ -18,6 +18,7 @@ templates = {
animation = "mummy_walk",
state = templates.ALIVE,
enemy = true,
room = options.room,
ia = sprites.update_mummy
}
elseif type == "bullet" then
@@ -35,7 +36,7 @@ templates = {
else
error("Template not recognized")
end
sprite.room = rooms.current()
--sprite.room = rooms.current()
print("creat sprite de tipus "..type)
return sprite
end,