public override void OnRelease(int key) { if (this.game.Mario.SheetState != SpriteStates.Sheets.FIRE) { StateMario current = this.game.Mario.StateMachineAction.CurrentState; if (current is StateMarioWalking) { (current as StateMarioWalking).ToWalk((current as StateMarioWalking).Direction); } //else, we aren't moving anyway } }
public static void HandleStop(Direction direction, SpriteCollection sprite, SpriteCollection other) { Rectangle bounds1 = new Rectangle((int)sprite.Info.position.X, (int)sprite.Info.position.Y, sprite.Info.spriteWidth, sprite.Info.spriteHeight); Rectangle bounds2 = new Rectangle((int)other.Info.position.X, (int)other.Info.position.Y, other.Info.spriteWidth, other.Info.spriteHeight); Rectangle intersection = Rectangle.Intersect(bounds1, bounds2); if (direction == Direction.LEFT || direction == Direction.RIGHT) { if (sprite.Info.bounce) { sprite.Info.acceleration.X = -sprite.Info.acceleration.X; sprite.Info.velocity.X = -sprite.Info.velocity.X; } else { if (direction == Direction.LEFT) { sprite.Info.position.X -= intersection.Width; } else { sprite.Info.position.X += intersection.Width; } sprite.Info.acceleration.X = 0; sprite.Info.velocity.X = 0; } } else if (direction == Direction.TOP || direction == Direction.BOTTOM) { if (direction == Direction.TOP) { sprite.Info.position.Y -= intersection.Height; } else { sprite.Info.position.Y += intersection.Height; } sprite.Info.acceleration.Y = 0; sprite.Info.velocity.Y = 0; if (sprite is SpriteMario) { SpriteMario m = sprite as SpriteMario; StateMario currentState = m.StateMachineAction.CurrentState; //Mario is landing if (direction == Direction.TOP) { if (!(currentState is StateMarioWalking)) { currentState.ToIdle(); } } //Mario is bumping his head else { currentState.ToFall(); } } } }