//Execute entity's action public void Update(GameTime gameTime) { lastAttackTime += gameTime.ElapsedGameTime.Milliseconds; timeSinceAstar += gameTime.ElapsedGameTime.Milliseconds; #region Animations if (animState == AnimationState.Idle) { animationPlayer = animationPlayerwalk; animationPlayer.ResetClip(); } else if (animState == AnimationState.Walking) { animationPlayer = animationPlayerwalk; } else if(animState == AnimationState.Attacking)//animation for attacking { animationPlayer = animationPlayerattack; } else if (animState == AnimationState.Hurt)//animation when hurt { animationPlayer = animationPlayerhurt; ElapsedDamagedTime += gameTime.ElapsedGameTime.Milliseconds; if (ElapsedDamagedTime < DAMAGE_ANIM_LENGTH) { if (animationPlayer.currentKeyframe < animationPlayer.CurrentClip.Keyframes.Count() - 1) { animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity); } else animationPlayer.ResetClip(); return; } ElapsedDamagedTime = 0; animState = AnimationState.Idle; } else if (animState == AnimationState.Dying)//animation for dying { animationPlayer = animationPlayerdie; ElapsedDeathTime += gameTime.ElapsedGameTime.Milliseconds; if (ElapsedDeathTime < DEATH_ANIM_LENGTH) { if (animationPlayer.currentKeyframe < animationPlayer.CurrentClip.Keyframes.Count() - 1) { animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity); } return; } else { Dead = true; return; } } else//if just standing { animationPlayer = animationPlayerwalk; animationPlayer.ResetClip(); } animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity); #endregion PosState = EvaluateBehaviour(); switch (PosState) { case EntityPositionState.KineticArrive: { KinematicArrive(); animState = AnimationState.Walking; Position += Velocity; break; } case EntityPositionState.KineticFlee: { if ((Target.Position - this.Position).Length() < FleeRadius) { KinematicFlee(); animState = AnimationState.Walking; Position += Velocity; } break; } case EntityPositionState.SteeringArrive: { //if (onPath) //{ // // see if we can get to second node in path // if (path.Count > 1 && astarGetter(Position, path[1].position).Equals(Vector3.Zero)) // { // GroundTarget = path[1].position; // path.RemoveAt(0); // } // else if (path.Count > 0) // { // if (!astarGetter(Position, GroundTarget).Equals(Vector3.Zero)) // GroundTarget = path[0].position; // else // onPath = false; // } //} //else if (!onPath) // try to get path //{ // if (timeSinceAstar > MIN_PATHFINDING_IDLE) // { // path = GetAStarPath(GroundTarget); // if (path != null) // onPath = true; // timeSinceAstar = 0; // } //} SteeringArrive(creep); animState = AnimationState.Walking; Position += Velocity; break; } case EntityPositionState.SteeringFlee: { if ((Target.Position - this.Position).Length() < FleeRadius) { SteeringFlee(creep); animState = AnimationState.Walking; Position += Velocity; onPath = false; } break; } case EntityPositionState.SteeringWander: { SteeringWander(); animState = AnimationState.Walking; Position += Velocity; onPath = false; break; } case EntityPositionState.Attack: { animState = AnimationState.Attacking; if (lastAttackTime > MeleeAttack.Speed) { Attack(MeleeAttack); lastAttackTime = 0; } onPath = false; break; } case EntityPositionState.RangedAttack: { animState = AnimationState.Attacking; if (lastAttackTime > RangedAttack.Speed) { Attack(RangedAttack); lastAttackTime = 0; } onPath = false; break; } default: { animState = AnimationState.Idle; break; } } }
public void Update(GameTime gameTime) { TimeSinceLastFire += gameTime.ElapsedGameTime.Milliseconds; TimeSinceLastUse += gameTime.ElapsedGameTime.Milliseconds; if (animState == AnimationState.Idle) { animationPlayer = animationPlayerwalk; animationPlayer.ResetClip(); } else if (animState == AnimationState.Walking) { animationPlayer = animationPlayerwalk; } else if (animState == AnimationState.Hurt)//animation when hurt { animationPlayer = animationPlayerhurt; ElapsedDamagedTime += gameTime.ElapsedGameTime.Milliseconds; if (ElapsedDamagedTime < DAMAGE_ANIM_LENGTH) { if (animationPlayer.currentKeyframe < animationPlayer.CurrentClip.Keyframes.Count() - 1) { animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity); } else animationPlayer.ResetClip(); return; } ElapsedDamagedTime = 0; animState = AnimationState.Idle; } else if (animState == AnimationState.Dying)//animation for dying { animationPlayer = animationPlayerdie; ElapsedDeathTime += gameTime.ElapsedGameTime.Milliseconds; if (ElapsedDeathTime < DEATH_ANIM_LENGTH) { if (animationPlayer.currentKeyframe < animationPlayer.CurrentClip.Keyframes.Count() - 1) { animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity); } return; } else { Dead = true; return; } } else//if just standing { animationPlayer = animationPlayerwalk; animationPlayer.ResetClip(); } animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity); //update ray positions ray[0] = new VertexPositionColor(Position + rayHeight, Color.GreenYellow); ray[1] = new VertexPositionColor(Position + rayHeight + raydist * new Vector3((float)Math.Sin(Rotation), 0, (float)Math.Cos(Rotation)) * 2f, Color.GreenYellow); }