Page 2 of 2
Re: Crushing monsters by closing door
Posted: Thu Sep 20, 2012 8:02 pm
by JKos
There was a bug which is fixed now: I automatically assumed that y coordinates increase upwards on map so the door_y was "calculated" wrong.
Added monsters.directions table-cleaning to monster.onDie() as Petri suggested.
And I also made a loop for monster-assets initialization, so I don't have to repeat that same cloneObject codeblock for every monster.
Btw: I's there a reason why ipairs and pairs-iterators aren't working in init.lua?
I edited these changes to my previous post and updated the sample-dungeon.
Re: Crushing monsters by closing door
Posted: Thu Sep 20, 2012 10:40 pm
by JKos
Monsters can now open doors
but you can control which monsters (by name in script-entity monsters.canOpenDoors) and which individual doors(by id in script-entity doors.canBeOpenendByMonsters). I also polished the code and made some general purpose functions, which i will post here:
Code: Select all
-- returns x and y coordinates of tile at ahead (+ distance) of an entity based on it's facing
function getCoordsOfTileAhead(entity,distance)
distance = distance or 1
local x = entity.x
local y = entity.y
if (entity.facing == 0) then
y = y - distance
elseif (entity.facing == 2) then
y = y + distance
elseif (entity.facing == 1) then
x = x + distance
else
x = x - distance
end
return {["x"]=x,["y"]=y}
end
-- returns all entities at ahead of entity based on it's facing
function entitiesAtAhead(entity)
local coords = self.getCoordsOfTileAhead(entity)
return entitiesAt(entity.level,coords.x ,coords.y)
end
-- returs opposite facing direction of entity. For example if entity is facing 0 (north) returns 2 (south)
function getOppositeFacing(entity)
return (entity.facing + 2)%4
end
-- checks if entity is a door
function isDoor(entity)
return type(entity.addPullChain) == "function"
end
you can get full code with demo-dungeon from here:
https://docs.google.com/open?id=0B7cR7s ... FFtWWJQcWs