public override void Update(float delta) { if (Alive) { Alerted = SeesMonster(); if (Alerted && Map.World.Monster.Alive) { Vector2 diff = Map.World.Monster.Position - Position; Move(diff.NormalizedSafe() * SPEED * delta); } else { if (walkTime < 0) { walkTime = (float)(random.NextDouble()) * 3; walkAngle = (float)(random.NextDouble() * 360); } walkTime -= delta; Move(walkAngle.DegreesToNormalVector() * SPEED * delta); } if (Moving) { walkAnimation.Update(delta); alertedAnimation.Update(delta); } else { walkAnimation.Reset(); alertedAnimation.Reset(); } } }
public override void Update(float delta) { if (Alive) { KeyboardState keyboardState = Keyboard.GetState(); bool left = keyboardState.IsKeyDown(Key.Left); bool right = keyboardState.IsKeyDown(Key.Right); bool up = keyboardState.IsKeyDown(Key.Up); bool down = keyboardState.IsKeyDown(Key.Down); bool shift = keyboardState.IsKeyDown(Key.LShift); Vector2 movement = new Vector2(); if (left ^ right) { movement.X += left ? -1 : 1; } if (up ^ down) { movement.Y += up ? -1 : 1; } bool running = false; if (shift && !regeneratingStamina) { if (running = (Stamina > 0)) { Stamina -= delta; } } else { Stamina += delta * (Moving ? 0.5f : 1); } Move(movement.NormalizedSafe() * delta * SPEED * (running ? 2 : 1)); if (Moving) { animation.Update(delta); if (running) { animation.Update(delta); } } else { animation.Reset(); } foreach (var entity in Map.Entities) { NPC npc = entity as NPC; if (npc != null && npc.Alive && npc.CollisionBox.IntersectsWith(CollisionBox)) { npc.HP = 0; bloodEmitter.Position = npc.Position; bloodEmitter.Emit(25); } } } }