Added one way platforms.
Since I'm using box2d all I have to do is disable the collision response (contact:setEnabled(false)) on the pre-solve callback, which means that when a collision between a one way platform and the player happens, no collision response should happen. BUT that should happen only when the player is coming from below the platform, so either only when the y velocity of the player is lower than 0 or when the lowermost part of the player is below the topmost part of the platform.
Using y velocity as the parameter is faulty because if the player goes up but doesn't quite make it and starts to descend, the collision kicks back in and the player is either pushed down or up by box2d, which looks and feels wrong.
function MetalPlatform:collisionPlayerPre(player, nx, ny, contact)
local vx, vy = player.body:getLinearVelocity()
if vy < 0 then contact:setEnabled(false) end
end
So the way that works the best (and it's the one I'm using) is taking positions into consideration, which also makes a lot of sense.
function MetalPlatform:collisionPlayerPre(player, nx, ny, contact)
local px, py = player.body:getPosition()
if py + player.h/2 >= self.y - self.h/2 then contact:setEnabled(false) end
end
Also, Matt also sent me an initial pretty good idea for how to add randomness to the creation of room templates (check first page for how we generate dungeons, now we need to figure out how to generate each room randomly so that the game doesn't get repetitive too fast).
The red blocks in that image are the games main layout, those blocks don't change. The orange blocks are split into sections (where they've been numbered) and then randomly set to 3 different states.
- That section doesn't appear on the layout
- That section becomes breakable blocks
- That section becomes part of the solid layout
With that set up we can still have a selection of pre-designed maps, but each of these maps then also has a selection of randomly created alternatives...
So if we do the basic layout of the maps in this way (or something similar to this) we can design templates (with puzzles, enemies and item placement) with those "probabilistic tiles" in mind and we pretty much get 1-5 extra different templates/rooms for free. Add to that the possibility of combining templates together to create a single room and we could probably get a huuuuuge number of different rooms with just a few templates... !