protected void lookThisWay(Vector2 direction) { SpriteState spriteDirection; float angle = XnaHelper.RadiansFromVector(direction); if (angle > -Math.PI / 4 && angle < Math.PI / 4) { spriteDirection = SpriteState.FaceUp; } else if (angle >= Math.PI / 4 && angle < 3 * Math.PI / 4) { spriteDirection = SpriteState.FaceRight; } else if (angle > 3 * Math.PI / 4 || angle < -3 * Math.PI / 4) { spriteDirection = SpriteState.FaceDown; } else { spriteDirection = SpriteState.FaceLeft; } _sprite.AnimationState = (int)spriteDirection; }
protected override void UpdateWeapon(GameTime gameTime) { switch (_hookState) { case (HookState.Idle): { if (_firing) { _hookState = HookState.Fired; _hookPosition = _owner.Position; _hookAngle = XnaHelper.RadiansFromVector(_fireDirection); _hookVelocity = _fireDirection * HOOK_SPEED; } break; } case (HookState.Fired): { if (!(_firing) && Vector2.Distance(_hookPosition, _owner.Position) < MAX_RANGE) { _hookPosition += _hookVelocity; _hookHitRect.X = (int)_hookPosition.X; _hookHitRect.Y = (int)_hookPosition.Y; } else { _hookState = HookState.Retracting; } break; } case (HookState.Retracting): { _hookPosition -= HOOK_SPEED * Vector2.Normalize(_hookPosition - _owner.Center); if (XnaHelper.PointInRect(_hookPosition, _owner.HitRect)) { _hookState = HookState.Idle; } break; } case (HookState.Attached): { _hookPosition = _hookedUnit.Center; Vector2 pullForce = HOOK_FORCE * XnaHelper.DirectionBetween(_owner.Position, _hookedUnit.Position); _owner.ApplyForce(pullForce); _hookedUnit.ApplyForce(Vector2.Negate(pullForce)); if (_firing) { _hookState = HookState.Idle; } break; } } }
public override void CheckAndApplyCollision(PhysicalUnit unit, TimeSpan time) { if (!_firing || !unit.Collides) { return; //don't check collisions if not firing } float fireAngle = XnaHelper.RadiansFromVector(_fireDirection); if (XnaHelper.RectangleIntersectsArc(unit.HitRect, _owner.Center, _range, fireAngle, _hitArc)) { _tempVector = unit.Center - _owner.Center; _tempVector.Normalize(); unit.ApplyImpact(_force * _tempVector, 1); unit.ApplyDamage(_damage); } }