//============================================================ /*-------------------------------------- * * Evalute vertical movement logic * for a given actor * * -----------------------------------*/ internal void EvaluateVerticalMovement(Actor moving_actor) { Sprite sprite = moving_actor.Sprite; Character actor = moving_actor.Character; //-- translate the sprite vertically if (actor.Falling) { Gravitate(actor); // changes acceleration rate actor.Accelerate_Y(); // adjust speed by acceleration rate int X = sprite.GL_Position.X; int Y = sprite.GL_Position.Y; //-- if speed is negative we are on the downwards part of the jump arc if (actor.ySpeed < 0) { bool Landing = level.Blocks[X][Y - 1].IsSolid; /*------------------------------- * * Are We About to Land? * YES? * * Then stop falling. * * ---------------------------*/ if (Landing) { actor.ySpeed = 0; actor.yAccelerationRate = 0; actor.Falling = false; actor.Standing = true; sprite._Status = Status.standing; deviceScreen_.MoveSprite(sprite, new Block(X, Y)); } /*--------------------------- * * NO? then keep falling * * ------------------------*/ else { sprite.Translate(0, (0 - actor.ySpeed) / 2); } } //==================================================================== //-- speed is positive, so we are still on the upwards part of the jump arc else if (actor.ySpeed > 0) { //-- is there a block overhead? //-- I don't know why, but this will ONLY work at Y + 3. if (level.Blocks[actor.BlockPosition.X][actor.BlockPosition.Y + 3].IsSolid) { actor.yAccelerationRate = 0; actor.ySpeed = 0; } else { sprite.Translate(0, 0 - actor.ySpeed); } } //-- speed is 0, so do nothing } }