public override void Update(Engine engine) { if (AnimationStep == 0) { if (Cube.IsMoveSafe(engine, GridPosition - Vector3.UnitZ)) { if (Move(engine, GridPosition - Vector3.UnitZ)) { Falling(); } } } base.Update(engine); }
public override void NewStep(Engine engine) { base.NewStep(engine); if (AnimationStep == 0) { // Checks to see if the player needs to grab onto a ladder. if (Cube.IsMoveSafe(engine, GridPosition - Vector3.UnitZ)) { if (LadderVector != Vector3.Zero) { if (Block.VectorToSide[LadderVector] < 4) { animation.SetAnimation(Block.VectorToSide[LadderVector] + 4); } else { Vector3 _dir = Vector3.Normalize(Direction); if (Block.VectorToSide[-_dir] < 4) { animation.SetAnimation(Block.VectorToSide[-_dir] + 13); } } } } // The player must be falling. else { Vector3 _dir = Vector3.Normalize(Direction); if (Block.VectorToSide[-_dir] < 4) { animation.SetAnimation(Block.VectorToSide[-_dir]); } else if (Block.VectorToSide[-_dir] == 4) { animation.SetAnimation(0); } } } }
/// <summary> /// The script this class runs every new step that is taken. /// </summary> public virtual void NewStep(Engine engine) { // Checks to see if any moves are enquened. if (MovementChain.Count > 0) { if (AnimationChain.Count > 0) { SetAnimation(AnimationChain.Dequeue()); } if (!Move(engine, GridPosition + MovementChain.Dequeue())) { // If the move fails, it moves right on to the next move. NewStep(engine); } } // Otherwise, checks if the player needs to fall. else { LadderVector = Vector3.Zero; // Allows the block to use ladders or fall if it uses gravity. if (UsesGravity) { // Only bothers to check if the fall will be sucessful. if (Cube.IsMoveSafe(engine, GridPosition - Vector3.UnitZ)) { // Checks to see if the cube can grab a ladder. if (UsesLadders) { Block _b = engine.room.GetGridBlockSafe(GridPosition + Vector3.UnitZ); if (_b != null) { if (_b.SideProperty[4] == 1) { LadderVector = -Vector3.UnitZ; } } _b = engine.room.GetGridBlockSafe(GridPosition + Vector3.UnitY); if (_b != null) { if (_b.SideProperty[0] == 1) { LadderVector = -Vector3.UnitY; } } _b = engine.room.GetGridBlockSafe(GridPosition - Vector3.UnitY); if (_b != null) { if (_b.SideProperty[2] == 1) { LadderVector = Vector3.UnitY; } } _b = engine.room.GetGridBlockSafe(GridPosition + Vector3.UnitX); if (_b != null) { if (_b.SideProperty[3] == 1) { LadderVector = -Vector3.UnitX; } } _b = engine.room.GetGridBlockSafe(GridPosition - Vector3.UnitX); if (_b != null) { if (_b.SideProperty[1] == 1) { LadderVector = Vector3.UnitX; } } } // Lets the cube fall. if (LadderVector == Vector3.Zero) { Move(engine, GridPosition - Vector3.UnitZ); // We know this will be successful, so we use the falling animation. Falling(); } } } // Checks to see if the cube will slip on ice. if (UsesIce && LadderVector == Vector3.Zero && AnimationStep == 0) { Block _bl = engine.room.GetGridBlockSafe(GridPosition - Vector3.UnitZ); if (_bl != null) { if (_bl.SideProperty[5] == 2) { Vector3 _dir = Vector3.Normalize(Direction); if (Move(engine, GridPosition + _dir)) { // If the move is successful, use the falling animation. Sliding(); } } } } } }