public void Update(TimeSpan deltaTime) { foreach (var entity in Screen.MainConsole.Entities) { if (CollisionBox.CheckCollision(this.Transform, entity.Transform)) { var character = entity as Character; if (character != null) { character.TakeDamage(Damage); } IsDead = true; } } Move(); }
private void Move() { if (IsMoving == false) { return; } var entity = Screen.MainConsole.Entities.FirstOrDefault(e => e.Transform.Position == Transform.Position + Transform.Direction.AsPoint()); Point lastPosition = Transform.Position; switch (Transform.Direction) { case Direction.Right: Transform.Position = new Point(Transform.Position.X + Velocity, Transform.Position.Y); break; case Direction.Left: Transform.Position = new Point(Transform.Position.X - Velocity, Transform.Position.Y); break; case Direction.Up: Transform.Position = new Point(Transform.Position.X, Transform.Position.Y - Velocity); break; case Direction.Down: Transform.Position = new Point(Transform.Position.X, Transform.Position.Y + Velocity); break; } if (entity != null && CollisionBox.CheckCollision(Transform, entity.Transform)) { Transform.Position = lastPosition; } }