public override void Update(GameTime gameTime)
{
if (!view.Freezed)
{
if (model.resetTimeLeft > 0)
{
model.resetTimeLeft -= gameTime.ElapsedGameTime.Milliseconds;
if (model.resetTimeLeft <= 0)
{
model.resetTimeLeft = -1;
view.Rotation = 0;
view.BoundBox.Rotation = 0;
view.Scale = 0.6f;
}
else if (model.resetTimeLeft <= 4000 && model.resetTimeLeft >= 2000)
{
model.setState(CharacterState.falling);
AddView(view);
view.BoundBox.IsStatic = false;
view.Scale = 0.6f - (model.resetTimeLeft - 2000) / 2000 * 0.6f;
view.Rotation += (float)Math.PI * 2 * gameTime.ElapsedGameTime.Milliseconds / 1000;
}
}
else
{
if (model.invounerable)
{
model.invounerableTimeLeft -= gameTime.ElapsedGameTime.Milliseconds;
if (model.invounerableTimeLeft <= 0)
{
model.invounerable = false;
view.Opacity = 1;
}
}
if (model.state == CharacterState.attacking && currentMove.Stats.Type != MoveType.Range && currentMove.Started)
{
Vector2 moveVelocity = ConvertUnits.ToSimUnits((currentMove.Stats.SqTo - currentMove.Stats.SqFrom) / (currentMove.Stats.End - currentMove.Stats.Start) * 1000);
if (!model.faceRight) moveVelocity *= new Vector2(-1, 1);
currentMove.Img.BoundBox.LinearVelocity = moveVelocity + view.Velocity;
}
Vector2 velocityPlus = new Vector2(0, 0);
if (!model.attackMode && (Math.Abs(view.VelocityX) < Math.Abs(model.maxSpeed * navigation.X) || view.VelocityX * navigation.X < 0))
velocityPlus.X += navigation.X * model.acceleration * gameTime.ElapsedGameTime.Milliseconds / 1000f;
if (!model.attackMode || model.state == CharacterState.takingHit || currentMove.Stats.Type != MoveType.Body
|| Math.Abs(currentMove.Stats.BodyEnd - currentMove.Stats.Duration) > currentMove.attackTimeLeft || Math.Abs(currentMove.Stats.BodyStart - currentMove.Stats.Duration) < currentMove.attackTimeLeft)
{
if (model.inAir)
velocityPlus.Y += stats.gravity * gameTime.ElapsedGameTime.Milliseconds / 1000f;
else if (view.VelocityX * navigation.X < 0 || navigation.X == 0 || model.attackMode)
velocityPlus.X += -(view.VelocityX / model.maxSpeed) * 3 * model.acceleration * gameTime.ElapsedGameTime.Milliseconds / 1000;
}
view.Velocity += velocityPlus;
model.position = view.Position;
NaturalState();
switch (model.state)
{
case CharacterState.running:
view.fps = (int)MathHelper.Clamp(Math.Abs(view.VelocityX) * 4, 5, 100);
break;
case CharacterState.charging:
currentMove.chargeTime += gameTime.ElapsedGameTime.Milliseconds;
if (startAfterMinCharge && currentMove.chargeTime > currentMove.Stats.MinWait)
model.setState(CharacterState.attacking, currentMove.Stats);
break;
case CharacterState.attacking:
if (currentMove.Ended)
{
view.Rotation = 0;
view.BoundBox.Rotation = 0;
model.attackMode = false;
NaturalState();
break;
}
currentMove.attackTimeLeft -= gameTime.ElapsedGameTime.Milliseconds;
if (currentMove.attackTimeLeft <= 0)
{
if (currentMove.Stats.Type != MoveType.Range)
{
moves.EndMove(currentMove);
moves.RemoveMove(currentMove);
view.Rotation = 0;
view.BoundBox.Rotation = 0;
}
if (currentMove.Stats.Type != MoveType.Range || !currentMove.Stats.Adjustable)
{
model.attackMode = false;
NaturalState();
}
}
else if (currentMove.Stats.Type != MoveType.Range && currentMove.attackTimeLeft <= Math.Abs(currentMove.Stats.End - currentMove.Stats.Duration))
{
moves.EndMove(currentMove);
}
else if (currentMove.attackTimeLeft <= Math.Abs(currentMove.Stats.Start - currentMove.Stats.Duration))
{
moves.StartMove(view.Position, view.Velocity, currentMove);
}
if (!currentMove.Stats.Adjustable && currentMove.Stats.Type == MoveType.Body && currentMove.attackTimeLeft <= Math.Abs(currentMove.Stats.BodyStart - currentMove.Stats.Duration)
&& currentMove.attackTimeLeft >= Math.Abs(currentMove.Stats.BodyEnd - currentMove.Stats.Duration))
{
view.Velocity = currentMove.Stats.BodySpeed * currentMove.Xdirection;
}
else if (currentMove.Stats.Adjustable)
{
if (currentMove.attackTimeLeft <= currentMove.Stats.Duration - 100)
adjustAngle += model.faceRight ?
navigation.Y * currentMove.Stats.AdjustAcc * gameTime.ElapsedGameTime.Milliseconds / 1000f :
-navigation.Y * currentMove.Stats.AdjustAcc* 1f * gameTime.ElapsedGameTime.Milliseconds / 1000f;
if (currentMove.Stats.Type == MoveType.Range && currentMove.attackTimeLeft <= currentMove.Stats.Duration - currentMove.Stats.Start)
{
float velocity = currentMove.Img.BoundBox.LinearVelocity.Length();
Vector2 newVelocity = new Vector2(velocity * (float)Math.Cos(adjustAngle), velocity * (float)Math.Sin(adjustAngle));
currentMove.Img.BoundBox.LinearVelocity = newVelocity;
try { currentMove.Img.BoundBox.Rotation = (float)adjustAngle; }
catch { }
}
else if (currentMove.Stats.Type == MoveType.Body
&& currentMove.attackTimeLeft <= currentMove.Stats.Duration - currentMove.Stats.BodyStart
&& currentMove.attackTimeLeft >= currentMove.Stats.Duration - currentMove.Stats.BodyEnd)
{
float velocity = currentMove.Stats.BodySpeed.Length();
float newAngle = (float)(adjustAngle - currentMove.Stats.StartAngle);
Vector2 newVelocity = new Vector2(velocity * (float)Math.Cos(adjustAngle), velocity * (float)Math.Sin(adjustAngle));
view.Velocity = newVelocity;
view.BoundBox.Rotation = newAngle;
view.Rotation = newAngle;
if(currentMove.attackTimeLeft <= currentMove.Stats.Duration - currentMove.Stats.Start
&& currentMove.attackTimeLeft <= currentMove.Stats.Duration - currentMove.Stats.Start)
{
currentMove.Img.BoundBox.Rotation = newAngle;
float posLength = ConvertUnits.ToSimUnits(currentMove.Stats.SqFrom.Length());
currentMove.Img.BoundBox.Position = view.BoundBox.Position + new Vector2(posLength * (float)Math.Cos(adjustAngle), posLength * (float)Math.Sin(adjustAngle));
}
}
}
break;
case CharacterState.takingHit:
if (view.VelocityY >= 0)
{
if (currentMove.Stats.Type != MoveType.Range)
{
moves.EndMove(currentMove);
moves.RemoveMove(currentMove);
}
model.attackMode = false;
NaturalState();
}
break;
}
string p = "Player " + model.playerIndex + " ";
DebugWrite(p + "Jumps: ", model.jumpsLeft);
DebugWrite(p + "State: ", model.state);
DebugWrite(p + "inAir: ", model.inAir);
}
}
}