/// <summary> /// Move the enemy /// </summary> /// <param name="gameTime"></param> public void Update(int timeElapsed, Player n) { if (patrol != null) velocity = patrol.getCurrentVector(timeElapsed); Point c = GetCenter(); if(shoots){ if(facingLeft){ if (new Rectangle(c.X - visionrange, c.Y, visionrange, 1).Intersects(n.DrawFrame())){ projectiles.Add(new Projectile(c, new Vector2(-6, new Random().Next(-3, 3)), projectileTexture)); } } else{ if (new Rectangle(c.X, c.Y, visionrange, 1).Intersects(n.DrawFrame())) { projectiles.Add(new Projectile(c, new Vector2(6, new Random().Next(-3, 3)), projectileTexture)); } } List<Projectile> hitlist = new List<Projectile>(); foreach (Projectile p in projectiles) { p.Update(); if (p.lifespan < 0) hitlist.Add(p); else if (p.DrawFrame().Intersects(n.DrawFrame())) n.death(); } foreach (Projectile p in hitlist) projectiles.Remove(p); } if (velocity.X == 0) { actionState = EnemyActionState.Standing; } else { actionState = EnemyActionState.Running; facingLeft = velocity.X < 0; } switch (actionState) { case EnemyActionState.Standing: break; case EnemyActionState.Running: running.Update(timeElapsed); break; case EnemyActionState.Attacking: attacking.Update(timeElapsed); break; case EnemyActionState.Dying: break; } base.Update(timeElapsed); }
/// <summary> /// Return a copy of the existing player. Used to create a ghost player for wall slide. /// </summary> /// <returns></returns> public Player Copy() { Player ret = new Player(Location()); ret.ninjaLifeState = ninjaLifeState; ret.velocity = velocity; ret.hasGravity = hasGravity; return ret; }