Crushing monsters by closing door

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Crushing monsters by closing door

Post 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.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Crushing monsters by closing door

Post 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
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
Post Reply