In this tutorial we address some of the limitations with the moving blocks by allowing the player to get squished.
There were two limitations with the moving blocks in the last tutorial. The first was that the blocks would slide underneath the player. This can be easily fixed with one line of code in the MovingBlock collision function.
override public function collide(Core:FlxCore):void
{
// ..
if (contactFromTop)
{
if (Core.hitCeiling(this))
{
Core.y = this.y - Core.height;
Core.last.y = Core.y;
Core.x += this.x - this.last.x;
}
}
}
Here we move the player horizontally by the same amount as the block when the player has collided with the block from above (i.e. it is standing on it).
The second limitation was that the player would be transported through the blocks in situations where it should have been squished. To fix that up we need to perform collision detection on the static and moving blocks individually.
First we define a new FlxArray in the GameState class to hold the moving blocks.
protected var movingBlocks:FlxArray = new FlxArray();
All the instances of the MovingBlock class are then placed into the new array
this.movingBlocks.add( this.add ( new MovingBlock( 32, 64, 0, 0, LEVEL_DIMENSIONS>>1, LEVEL_DIMENSIONS - BLOCK_DIMENSIONS * 3, BLOCK_DIMENSIONS * 2, BLOCK_DIMENSIONS * 2, TechTilesImage ) ) );
In the update function we do collisions on the moving blocks, and then the static ones. Note that the order of the calls to the FlxG collideArray function are important: the moving blocks have to be processed before the static blocks. We then check to see if the player is embedded in any of the blocks. If it is it has been squashed, and we call the playerSquash function.
public override function update():void
{
super.update();
FlxG.collideArray(movingBlocks, player);
FlxG.collideArray(levelBlocks, player);
FlxG.collideArrays(playerBullets, levelBlocks);
FlxG.collideArrays(enemies, levelBlocks);
FlxG.overlapArrays(playerBullets,enemies,bulletHitEnemy);
FlxG.overlapArray(movingBlocks, player, playerSquash);
FlxG.overlapArray(levelBlocks, player, playerSquash);
}
In the playerSquash function we simply kill the player. For an actual game you would probably remove a players life and restart the state in this function.
private function playerSquash(Collide1:FlxCore, Collide2:FlxCore):void
{
player.kill();
}

In this article I introduce you to the series, Specifiers in C++....
In this article I introduce you to a tutorial series titled, Some Features of C++ Entities....
C++ is a computer language I want to teach in these tutorials. C++ is a very developed language...
In C++ an array is a set of consecutive objects of the same type, in memory. We see how to crea...
A database is a set of related tables. This is part 1, division 1 of a series I have on databas...
In this tutorial we add mouse interactivity to the scene....
In this tutorial we allow the view of the isometric scene to be moved with the mouse....
In this tutorial we show the height of an isometric object by adding a shadow....
In this tutorial we modify the appearance of the isometric cube at runtime....
In this tutorial we add some animated isometric boxes to the scene....