Windfield and Tiled. Dynamically change tiles
Posted: Tue Nov 14, 2023 5:22 pm
I am working on a copy of Hotline Miami and can't solve the problem with breakable windows tiles.
So, idea is simple: draw usual windows on load of level and change them to broken ones once bullet destroys them.
I have solved the collisions part of the problem and it works as expected: player can't go through the collider unless bullet passes it and destroys the collider.
But here is a problem: drawing windows in Tiled on tilemap (tileMap.lua) makes them permanent so windows must be drawn dynamically taking obj.x and obj.y from their colliders. tileMap has windowsObjects layer with drawn objects to make colliders with windfield help.
Simply drawing windows on locations of windowsObjects (game_map.layers["windowsObjects"].objects) does not work, because I cant remove those later. (screenshot1)
for j, obj in ipairs(game_map.layers["windowsObjects"].objects) do
love.graphics.draw(windowV, obj.x, obj.y)
end
So I want to draw windows on positions of objects in the world, however I can't access specific objects with specific CollisionClass ('window'). The class gets assigned properly and logic of interactions with other objects works as expected, but drawing...
So I am trying to do something like this. If I remove 'obj.collision_classes == 'window' and' condition then I get (screenshot2). And if it is back, then (screenshot3)
local colliders = world:getBodies()
for i, obj in ipairs(colliders) do
if obj.collision_classes == 'window' and not obj.destroyed then
love.graphics.draw(windowV, obj:getX(), obj:getY())
end
end
If you need the rest of the code then let me know and I will provide it.
Also, if there is a better way than the one I am trying to describe then I would be really happy to learn it.
Thank you in advance!
So, idea is simple: draw usual windows on load of level and change them to broken ones once bullet destroys them.
I have solved the collisions part of the problem and it works as expected: player can't go through the collider unless bullet passes it and destroys the collider.
But here is a problem: drawing windows in Tiled on tilemap (tileMap.lua) makes them permanent so windows must be drawn dynamically taking obj.x and obj.y from their colliders. tileMap has windowsObjects layer with drawn objects to make colliders with windfield help.
Simply drawing windows on locations of windowsObjects (game_map.layers["windowsObjects"].objects) does not work, because I cant remove those later. (screenshot1)
for j, obj in ipairs(game_map.layers["windowsObjects"].objects) do
love.graphics.draw(windowV, obj.x, obj.y)
end
So I want to draw windows on positions of objects in the world, however I can't access specific objects with specific CollisionClass ('window'). The class gets assigned properly and logic of interactions with other objects works as expected, but drawing...
So I am trying to do something like this. If I remove 'obj.collision_classes == 'window' and' condition then I get (screenshot2). And if it is back, then (screenshot3)
local colliders = world:getBodies()
for i, obj in ipairs(colliders) do
if obj.collision_classes == 'window' and not obj.destroyed then
love.graphics.draw(windowV, obj:getX(), obj:getY())
end
end
If you need the rest of the code then let me know and I will provide it.
Also, if there is a better way than the one I am trying to describe then I would be really happy to learn it.
Thank you in advance!