public void Damage(int amount) { OnTargetHit.Invoke(gameObject); if (gameObject.tag == "Target") { TurnRed(); Destroy(gameObject, 0.5f); } }
public void OnBodyEntered(Node body) { TargetHit?.Invoke(new BulletHitInfo { WorldCoords = _worldCoords, Building = body as IBuilding }); _worldCoords = Vector3.Zero; QueueFree(); }
protected override void Update(GameTime time) { base.Update(time); if (!_initialized) { _initialized = true; _startTime = time.TotalGameTime; } float percent = (float)(_elapsedTime.TotalMilliseconds / _duration.TotalMilliseconds); if (percent > 0.99f) { Active = false; _tcs.SetResult(true); TargetHit?.Invoke(); } var offset = new Vector2(16, 16); _sourceWorld = Camera2D.Instance.HexToPixel(_source) + offset; _dstWorld = Camera2D.Instance.HexToPixel(_destination) + offset; _directionWorld = _dstWorld - _sourceWorld; Vector2 normDir = _directionWorld; normDir.Normalize(); var acos = Vector2.Dot(new Vector2(1, 0), normDir); double flip = 1; if (normDir.Y < 0) { flip = -1; } Rotation = (float)(flip * Math.Acos(acos)); Position = _sourceWorld + _directionWorld * percent + offset; _elapsedTime = time.TotalGameTime - _startTime; }