public void Update(InputState inputState)
        {
            frame = new Rectangle(parent.gfxFrame.Left + (int)offset.X - 16, parent.gfxFrame.Top + (int)offset.Y - 16, 32, 32);

            isMouseOver = (inputState.hoveringElement == this);

            if (isMouseOver &&
                inputState.mouseLeft.justPressed &&
                ability.controller.isActivePlayer &&
                ability.CanActivate(Game1.activePlayer))
            {
                isMousePressing = true;
            }

            if (isMousePressing && ability.hasTarget)
            {
                beamVisible = true;

                Vector2 offset = inputState.MousePos - frame.Center.ToVector2();
                beamRotation  = offset.ToAngle();
                beamRect      = new Rectangle(frame.Center.X, frame.Center.Y, (int)offset.Length(), 16);
                beamArrowRect = new Rectangle((int)inputState.MousePos.X, (int)inputState.MousePos.Y, 16, 16);

                if (inputState.hoveringElement != null && inputState.hoveringElement is ConvergeUIObject)
                {
                    ConvergeObject targetedObject = ((ConvergeUIObject)inputState.hoveringElement).represented;
                    beamBad = !ability.CanTarget(targetedObject, Game1.activePlayer);
                }
                else
                {
                    beamBad = false;
                }
            }
            else
            {
                beamVisible = false;
            }


            if (isMousePressing && !inputState.mouseLeft.isDown)
            {
                isMousePressing = false;

                if (ability.hasTarget)
                {
                    if (inputState.hoveringElement != null)
                    {
                        // used on target
                        if (inputState.hoveringElement is ConvergeUIObject)
                        {
                            ability.ActivateOn(((ConvergeUIObject)inputState.hoveringElement).represented, Game1.activePlayer);
                        }
                    }
                }
                else
                {
                    ability.Activate(Game1.activePlayer);
                }
            }
        }
示例#2
0
        bool SetRotationToPlayerLastKnownPosition()
        {
            Vector2 direction = playerLastKnownPosition - rigidbody.position;

            rigidbody.rotation = direction.ToAngle();
            return(true);
        }
示例#3
0
    private void RotateToMouse()
    {
        // Sets the rotation of this gun to point towards the mouse.
        Vector2 mouseOffset = InputManager.MousePos - (Vector2)transform.position;

        if (!Right)
        {
            mouseOffset.x *= -1f;
        }
        float aimAngle = mouseOffset.ToAngle();
        float change   = Time.deltaTime;

        if (s_Aiming)
        {
            aimTimer += change;
        }
        else
        {
            aimTimer -= change;
        }

        aimTimer = Mathf.Clamp(aimTimer, 0f, Info.AimTime);
        float aimP = aimTimer / Info.AimTime;
        float x    = aimP;

        // Curve...?
        float finalAngle = Mathf.LerpAngle(0f, aimAngle, x);

        var a = transform.localEulerAngles;

        a.z = finalAngle;
        transform.localEulerAngles = a;
    }
示例#4
0
        void UpdateForTargetPos(Vector2 targetPos)
        {
            Vector2 offset = targetPos - sourcePos;

            if (offset != cachedOffset || sourcePos != cachedSource)
            {
                float   length = offset.Length();
                Vector2 dir    = offset / length;
                cachedSource    = sourcePos;
                cachedOffset    = offset;
                cachedLength    = (int)length;
                cachedDirection = cachedOffset;
                cachedDirection.Normalize();
                cachedRotation = offset.ToAngle();
                Vector2 handlePos;
                if (length < 64.0f)
                {
                    handlePos = sourcePos + dir * 32.0f;
                }
                else
                {
                    handlePos = targetPos - dir * 32.0f;
                }
                cachedHandleRect = new Rectangle((int)handlePos.X - 8, (int)handlePos.Y - 18, 16, 16);
                //cachedMouseRect = cachedHandleRect.Bloat(5);

                cachedMouseRect = new Rectangle((int)cachedSource.X, (int)cachedSource.Y, (int)cachedOffset.X, (int)cachedOffset.Y).FixNegatives().Bloat((int)MOUSE_RANGE);

                cachedEffects = offset.X < 0 ? SpriteEffects.FlipVertically : SpriteEffects.None;
            }
        }
示例#5
0
    private float GetAttitudeCorrection()
    {
        Vector2 realGravity         = Input.gyro.gravity.To2D();
        Vector2 gravityFromAttitude = GetGravityFromAttitude(Input.gyro.attitude);

        return(realGravity.ToAngle() - gravityFromAttitude.ToAngle());
    }
示例#6
0
        public void CheckNormalizer()
        {
            for (int x = -10000; x < 10000; x += 100)
            {
                for (int y = -10000; y < 10000; y += 100)
                {
                    Vector2 v    = new Vector2(x, y);
                    Vector2 norm = v.Normalize();

                    Angle a     = v.ToAngle();
                    Angle aNorm = norm.ToAngle();

                    Assert.AreEqual(a.Radian, aNorm.Radian, Vector2.EPS_MIN);

                    // Spezialfall Nullvektor
                    if (x == 0 && y == 0)
                    {
                        Assert.AreEqual(0f, norm.Length(), Vector2.EPS_MIN);
                    }
                    else
                    {
                        Assert.AreEqual(1f, norm.Length(), Vector2.EPS_MIN);
                    }
                }
            }
        }
示例#7
0
 public ProjectileBase(Vector2 position, Vector2 velocity)
 {
     Image    = Art.Bullet;
     Position = position;
     Velocity = velocity;
     Heading  = Velocity.ToAngle();
 }
示例#8
0
        public void Shoot(int muzzle)
        {
            Transform pos = MuzzleSpots[muzzle];

            if (MuzzleFlashPrefab != null)
            {
                var spawned = PoolObject.Spawn(MuzzleFlashPrefab);
                spawned.transform.position = pos.position;
                spawned.transform.rotation = pos.rotation;
            }

            Vector2 direction = pos.right;
            float   angle     = direction.ToAngle();
            bool    right     = Random.value <= 0.5f;

            angle    += Random.Range(AngleOffset.x, AngleOffset.y) * 0.5f * (right ? 1f : -1f);
            direction = angle.ToDirection();

            switch (Type)
            {
            case ProjectileType.HITSCAN:
                HitScan.Shoot(pos.position, direction, HitscanRange, 10f);     // TODO allow custom damage here and in spawned projectiles.
                break;

            case ProjectileType.PROJECTILE:
                if (JNet.IsServer)
                {
                    Projectile.Spawn(pos.position, direction, ProjectileSpeed);
                }
                break;
            }
        }
示例#9
0
        private Vector2 ModVeloc(Vector2 inVel)
        {
            Vector2 vector = inVel;

            if (m_projectile.GetElapsedDistance() > (distanceLastChecked + 1))
            {
                float addition;
                if (recalcDriftPerCheck)
                {
                    addition = UnityEngine.Random.Range(minDriftPerTile, maxDriftPerTile);
                }
                else
                {
                    addition = staticAngle;
                }
                if (randomiseInverseEachCheck && UnityEngine.Random.value <= 0.5f)
                {
                    addition *= -1;
                }
                float targetAngle = inVel.ToAngle() + addition;

                vector = BraveMathCollege.DegreesToVector(targetAngle, inVel.magnitude);
                base.transform.rotation = Quaternion.Euler(0f, 0f, targetAngle);
                distanceLastChecked     = m_projectile.GetElapsedDistance();
            }
            return(vector);
        }
        public void OnTileCollision(CollisionData data)
        {
            if (this.bounces > 0)
            {
                Vector2 vector   = data.Normal;
                Vector2 velocity = data.MyRigidbody.Velocity;
                float   num2     = (-velocity).ToAngle();
                float   num3     = vector.ToAngle();
                float   num4     = BraveMathCollege.ClampAngle360(num2 + 2f * (num3 - num2));
                this.degrees = num4;
                this.bounces--;
            }
            else
            {
                //this.ForceBreak();

                /*CellData cellData2 = GameManager.Instance.Dungeon.data[data.TilePosition];
                 * cellData2.breakable = true;
                 * cellData2.occlusionData.overrideOcclusion = true;
                 * cellData2.occlusionData.cellOcclusionDirty = true;
                 * tk2dTileMap map = GameManager.Instance.Dungeon.DestroyWallAtPosition(data.TilePosition.x, data.TilePosition.y, true);
                 * this.m_owner.CurrentRoom.Cells.Add(cellData2.position);
                 * this.m_owner.CurrentRoom.CellsWithoutExits.Add(cellData2.position);
                 * this.m_owner.CurrentRoom.RawCells.Add(cellData2.position);
                 * if (map)
                 * {
                 *  GameManager.Instance.Dungeon.RebuildTilemap(map);
                 * }*/
                //base.StartCoroutine(this.HandleCombatRoomExpansion(this.Owner.CurrentRoom, this.Owner.CurrentRoom, null));
                this.ForceBreak();
            }
        }
示例#11
0
    public void UpdateAxises(Vector2 axises)
    {
        this.axises = axises;

        float stickAngle = axises.ToAngle();

        if (stickAngle < 0)
        {
            stickAngle += 360;
        }

        if (!float.IsNaN(stickAngle))
        {
            float deltaAngle = stickAngle - lastAngle;
            if (deltaAngle < 0)
            {
                //Clockwise rotation
                cumul += Mathf.Abs(deltaAngle);
            }

            if (cumul > 360)
            {
                cumul = 0;
                ++nbCircle;
                if (OnCircleCompleted != null)
                {
                    OnCircleCompleted();
                }
            }

            lastAngle = stickAngle;
        }
    }
示例#12
0
        bool SetRotationToMovementTarget()
        {
            Vector2 direction = movementTarget - rigidbody.position;

            rigidbody.rotation = direction.ToAngle();
            return(true);
        }
示例#13
0
 public PlayerBullet(Texture2D image, Vector2 position, Vector2 velocity)
 {
     this.image  = image;
     Position    = position;
     Velocity    = velocity;
     Orientation = Velocity.ToAngle();
     Radius      = 8;
 }
示例#14
0
        public static void DrawBeam(this SpriteBatch spriteBatch, Texture2D texture, Vector2 start, Vector2 end, int thickness, Color color)
        {
            Vector2   offset       = end - start;
            float     beamRotation = offset.ToAngle();
            Rectangle beamRect     = new Rectangle((int)start.X, (int)start.Y, (int)offset.Length(), thickness);

            spriteBatch.Draw(texture, beamRect, null, color, beamRotation, new Vector2(0, texture.Height / 2), SpriteEffects.None, 0.0f);
        }
示例#15
0
 public Bullet(Vector2 position, Vector2 velocity)
 {
     image         = Art.Bullet;
     this.position = position;
     this.velocity = velocity;
     orientation   = velocity.ToAngle();
     radius        = 8;
 }
示例#16
0
文件: Bullet.cs 项目: terranjp/Orbit
 public Bullet(Vector2 position, Vector2 velocity)
 {
     image       = Art.Bullet;
     Position    = position;
     Velocity    = velocity;
     Orientation = Velocity.ToAngle();
     Radius      = 8;
 }
示例#17
0
 public Bullet(Vector2 position, Vector2 velocity)
 {
     Image = Art.Bullet;
     Position = position;
     Velocity = velocity;
     Orientation = velocity.ToAngle();
     Radius = 8;
 }
示例#18
0
 public PlayerBullet(Vector2 position, Vector2 velocity)
 {
     image       = GameRoot.PlayerBullet;
     Position    = position;
     Velocity    = velocity;
     Orientation = Velocity.ToAngle();
     Radius      = 8;
     Scale       = 2f;
 }
示例#19
0
 public Bullet(Vector2 position, Vector2 velocity)
 {
     Texture     = ArtManager.Bullet;
     Position    = position;
     Velocity    = velocity;
     Orientation = velocity.ToAngle();
     Radius      = 8;
     Scale       = 0.2f;
 }
示例#20
0
        public void DecomposeMatrix(ref Matrix matrix, out Vector2 position, out float rotation, out Vector2 scale)
        {
            matrix.Decompose(out Vector3 scale3, out Quaternion rotationQ, out Vector3 position3);
            Vector2 direction = Vector2.Transform(Vector2.UnitX, rotationQ);

            rotation = direction.ToAngle();
            position = new Vector2(position3.X, position3.Y);
            scale    = new Vector2(scale3.X, scale3.Y);
        }
示例#21
0
        protected override IEnumerator Top()
        {
            if (this.BulletBank && this.BulletBank.aiActor && this.BulletBank.aiActor.TargetRigidbody)
            {
                base.BulletBank.Bullets.Add(EnemyDatabase.GetOrLoadByGuid("880bbe4ce1014740ba6b4e2ea521e49d").bulletBank.GetBullet("grenade"));
            }
            base.PostWwiseEvent("Play_BOSS_lasthuman_volley_01", null);
            float   airTime    = base.BulletBank.GetBullet("grenade").BulletObject.GetComponent <ArcProjectile>().GetTimeInFlight();
            Vector2 vector     = this.BulletManager.PlayerPosition();
            Bullet  bullet2    = new Bullet("grenade", false, false, false);
            float   direction2 = (vector - base.Position).ToAngle();

            base.Fire(new Direction(direction2, DirectionType.Absolute, -1f), new Speed(1f, SpeedType.Absolute), bullet2);
            (bullet2.Projectile as ArcProjectile).AdjustSpeedToHit(vector);
            bullet2.Projectile.ImmuneToSustainedBlanks = true;
            //yield return base.Wait(150);
            for (int a = 0; a < 2; a++)
            {
                base.PostWwiseEvent("Play_BOSS_lasthuman_volley_01", null);
                for (int i = 0; i < 4; i++)
                {
                    for (int h = 0; h < 2; h++)
                    {
                        base.Fire(new Direction(UnityEngine.Random.Range(-75f, 75f), DirectionType.Aim, -1f), new Speed(7.5f + h, SpeedType.Absolute), new WallBullet());
                        yield return(base.Wait(1));
                    }
                    yield return(base.Wait(12));

                    Vector2 targetVelocity = this.BulletManager.PlayerVelocity();
                    float   startAngle;
                    float   dist;
                    if (targetVelocity != Vector2.zero && targetVelocity.magnitude > 0.5f)
                    {
                        startAngle = targetVelocity.ToAngle();
                        dist       = targetVelocity.magnitude * airTime;
                    }
                    else
                    {
                        startAngle = base.RandomAngle();
                        dist       = (7f * a) * airTime;
                    }
                    float   angle       = base.SubdivideCircle(startAngle, 4, i, 1f, false);
                    Vector2 targetPoint = this.BulletManager.PlayerPosition() + BraveMathCollege.DegreesToVector(angle, dist);
                    float   direction   = (targetPoint - base.Position).ToAngle();
                    if (i > 0)
                    {
                        direction += UnityEngine.Random.Range(-12.5f, 12.5f);
                    }
                    Bullet bullet = new Bullet("grenade", false, false, false);
                    base.Fire(new Direction(direction, DirectionType.Absolute, -1f), new Speed(1f, SpeedType.Absolute), bullet);
                    (bullet.Projectile as ArcProjectile).AdjustSpeedToHit(targetPoint);
                    bullet.Projectile.ImmuneToSustainedBlanks = true;
                }
            }

            yield break;
        }
示例#22
0
 public Bullet(Vector2 position, Vector2 velocity, Texture2D weapon)
 {
     damage      = 10;
     image       = weapon;
     Position    = position;
     Velocity    = velocity;
     Orientation = Velocity.ToAngle();
     Radius      = 8;
 }
示例#23
0
 public Bullet(Vector2 position, Vector2 velocity, Color bulletColor)
 {
     image       = GameRoot.Bullet;
     Position    = position;
     Velocity    = velocity;
     Orientation = Velocity.ToAngle();
     Radius      = 8;
     color       = bulletColor;
 }
示例#24
0
 public Projectile(Viewport viewport, Texture2D texture, Vector2 position, Vector2 velocity)
 {
     entityTexture = texture;
     Position = position;
     Velocity = velocity;
     Orientation = Velocity.ToAngle();
     ColRadius = 0;
     this.entityViewport = viewport;
 }
示例#25
0
        public override void HeavyAttack(Vector2 position, Vector2 aim)
        {
            float   aimAngle          = aim.ToAngle();
            Vector2 HeavyAttackCharge = MathUtil.FromPolar(aimAngle, 75f);
            Vector2 AttackVelocity    = MathUtil.FromPolar(aimAngle, HeavyAttackSpeed);

            EntityManager.Add(new AttackBox(Art.Hitbox, position, AttackVelocity, HeavyAttackFrames, HeavyAttackRadius, HeavyAttackDamage));

            PlayerChar.Instance.Velocity = PlayerChar.Instance.Velocity + HeavyAttackCharge;
        }
示例#26
0
 public Bullet(Vector2 position, Vector2 velocity, int damage)
 {
     image       = Art.Bullet;
     Position    = position;
     Velocity    = velocity;
     Orientation = Velocity.ToAngle();
     Radius      = 4;
     colour      = Color.Ivory;
     _damage     = damage;
 }
示例#27
0
        public static void DrawLine(this SpriteBatch spriteBatch, Texture2D texture, Vector2 start, Vector2 end, float width, Color color, SpriteEffects effects = SpriteEffects.None)
        {
            Vector2 offset   = end - start;
            float   length   = offset.Length();
            Vector2 dir      = offset / length;
            float   rotation = offset.ToAngle();

            spriteBatch.Draw(texture, new Rectangle((int)start.X, (int)start.Y, (int)length, (int)width),
                             null, color, rotation, new Vector2(0, texture.Height / 2), effects, 0.0f);
        }
        public void Vector2_ToAngle_Test()
        {
            var a = new Vector2(0, -10);
            var b = new Vector2(10, 0);
            var c = -Vector2.UnitY.Rotate(MathHelper.ToRadians(45));

            Assert.AreEqual(MathHelper.ToRadians(0), a.ToAngle());
            Assert.AreEqual(MathHelper.ToRadians(90), b.ToAngle());
            Assert.AreEqual(MathHelper.ToRadians(45), c.ToAngle());
        }
示例#29
0
        public Line(int x1, int y1, int x2, int y2, Color color, int width)
        {
            Vector2 startPoint     = new Vector2(x1, y1);
            Vector2 endPoint       = new Vector2(x2, y2);
            Vector2 distanceVector = endPoint - startPoint;

            Rotation = distanceVector.ToAngle();

            line = new Rectangle(x1, y1, distanceVector.Length().ToInt(), width);
        }
示例#30
0
    void SetDir()
    {
        if (movementInput == Vector2.zero)
        {
            return;
        }

        float rot = -movementInput.ToAngle() + 90;

        transform.localEulerAngles = Vector3.up * rot;
    }
示例#31
0
		/// <summary>
		/// Returns the euler angles that would make a Transform look toward the same direction as this vector. Z will always be 0.
		/// </summary>
		public static Vector3 ToEulerAngles(this Vector3 direction){
			Vector3 angles;
			Vector2 hztDir = new Vector2( direction.z,       direction.x );
			Vector2 vtcDir = new Vector2( hztDir.magnitude, -direction.y );

			angles.y = hztDir.ToAngle();
			angles.x = vtcDir.ToAngle();
			angles.z = 0;

			return angles;
		}
示例#32
0
        public override void LightAttack(Vector2 position, Vector2 aim)
        {
            float   aimAngle          = aim.ToAngle();
            float   inverseAimAngle   = (aim * -1).ToAngle();
            Vector2 LightAttackRecoil = MathUtil.FromPolar(inverseAimAngle, 4f);
            Vector2 AttackVelocity    = MathUtil.FromPolar(aimAngle, LightAttackSpeed);

            EntityManager.Add(new AttackBox(Art.Bullet, position, AttackVelocity, LightAttackFrames, LightAttackRadius, LightAttackDamage));

            PlayerChar.Instance.Velocity = PlayerChar.Instance.Velocity + LightAttackRecoil;
        }
 Direction vectorToDirection(Vector2 vector)
 {
     float angle = vector.ToAngle() - 45f;
     if (angle > 90f)
         return Direction.LEFT;
     else if (angle > 0f)
         return Direction.UP;
     else if (angle > -90f)
         return Direction.RIGHT;
     else
         return Direction.DOWN;
 }
示例#34
0
文件: Spout.cs 项目: akbiggs/Trauma
 public Spout(Vector2 position, Color color, Vector2 direction, bool isWater)
     : base(position, direction * SPOUT_SPEED, SPOUT_SPEED * Vector2.One, Vector2.Zero,
     Vector2.Zero, color, true, new Vector2(SIZE_X, SIZE_Y), new List<AnimationSet>() 
     {
         new AnimationSet("Appear", GetTexture(color, isWater), 2, 50, 3, false),
         new AnimationSet("Main", GetTexture(color, isWater), 1, 50, 3, false, 2),
         new AnimationSet("Disappear", GetTexture(color, isWater), 2, 50, 3, false, 3)
     }, "Appear", direction.ToAngle())
 {
     this.direction = direction;
     if (this.direction.Y < 0)
         this.position.Y -= 225;
     if (this.direction.Y > 0)
         this.position.Y += 50;
     if (this.direction.X > 0)
         this.position.X += 1000;
 }
示例#35
0
        public Ship_Sprite(Texture2D texture, Vector2 location, SpriteBatch spriteBatch)
            : base(texture, location, spriteBatch)
        {
            particles[0] = GameContent.Assets.Images.particles[ParticleType.Circle];
            particles[1] = GameContent.Assets.Images.particles[ParticleType.Square];
            gen = new RandomParticleGenerator(SpriteBatch, particles);
            gen.TTLSettings = TimeToLiveSettings.AlphaLess100;
            gen.RandomProperties = new RandomParticleProperties() { ColorFactor = 0.985f, Tint = Color.White };
            gen.ParticlesToGenerate = 1;
            engine = new Glib.XNA.SpriteLib.ParticleEngine.ParticleEngine(gen);

            Vector2 toEngine = new Vector2(Position.X, Position.Y - Height / 2);
            toEngineLength = -toEngine.Length();
            toEngineAngle = toEngine.ToAngle();

            engine.Tracked = this;
        }
示例#36
0
        public void Update(Vector2 target, float dt)
        {
            var vectorFromPrevious = _body.Position - _previous.Position;

            var a = target.ToAngle();
            a += _angle;

            var currentTarget = VectorKit.AngleToVector(a);
            currentTarget.Normalize();
            currentTarget *= vectorFromPrevious.Length();

            var normal = new Vector2(vectorFromPrevious.Y, -vectorFromPrevious.X);
            if (Vector2.Dot(normal, currentTarget) < 0)
            {
                normal *= -1;
            }

            var angle = MathUtils.VectorAngle(currentTarget, vectorFromPrevious);
            var ratio = (float)Math.Abs(angle / Math.PI) * 20;

            var force = ratio * normal;

            var velocityProj = _body.LinearVelocity.ProjectOn(force);
            //if (Vector2.Dot(velocityProj, force) < 0)
            velocityProj *= -1;

            force += velocityProj;

            Annotate.Arrow(_previous.Position, currentTarget, Color.Tomato);
            // Annotate.Arrow(previous.Position, v.Norm(l));
            Annotate.Arrow(_body.Position, velocityProj * Hgl.Time.FixedDt);
            Annotate.Arrow(_body.Position, _body.LinearVelocity * Hgl.Time.FixedDt, Color.Yellow);
            // Annotate.Circle(previous.Position, l, Color.Blue);
            // Annotate.Segment(previous.Position, tail.Position, Color.Blue);
            // Annotate.Arrow(tail.Position, norm, Color.Blue);
            Annotate.Arrow(_body.Position, force, Color.Red);

            _body.ApplyForce(force);
        }
示例#37
0
文件: Spike.cs 项目: akbiggs/Trauma
        public Spike(Vector2 position, Vector2 size, Color color, Vector2 direction)
            : base(position, Vector2.Zero, Vector2.Zero, Vector2.Zero, Vector2.Zero, color, true, size,
            ResourceManager.GetTexture("Misc_Spikes"), direction.ToAngle())
        {
            // facing up
            if (direction.X == 0 && direction.Y < 0)
            {
                Facing = Direction.Up;
                this.Position = new Vector2(position.X, position.Y);
                this.Box.Position = new Vector2(position.X + size.X / 4, position.Y);
                this.box = new BBox((int)Box.Position.X - 20, (int)Box.Position.Y, (int)(box.Width * 1.75f), (int)box.Height);
            }

            // facing down
            if (direction.X == 0 && direction.Y > 0)
            {
                Facing = Direction.Down;
                this.Position = new Vector2(position.X + size.X, position.Y + size.Y);
                this.box = new BBox((int)(Position.X - size.X), (int)(Position.Y - size.Y), (int)box.Width * 2, (int)box.Height);
            }

            // facing left
            if (direction.X < 0 && direction.Y == 0)
            {
                Facing = Direction.Left;
                this.Position = new Vector2(position.X, position.Y + size.Y);
                this.box = new BBox((int)(Position.X), (int)(Position.Y - size.X), (int)box.Width, (int)box.Height * 2);
            }

            // facing right
            if (direction.X > 0 && direction.Y == 0)
            {
                Facing = Direction.Right;
                this.Position = new Vector2(position.X + size.X / 2, position.Y);
                this.box = new BBox((int)(Position.X - size.X/2), (int)Position.Y, (int)box.Width, (int)box.Height * 2);
            }

            Debug.Assert(Facing != Direction.None, "Didn't handle a spike direction for facing.");
        }
示例#38
0
        public override void Update(GameTime gt)
        {
            if (!isClone)
            {
                regenClonesDelay += gt.ElapsedGameTime;
                if (regenClonesDelay >= regenClones)
                {
                    regenClonesDelay = new TimeSpan(0);
                    StateManager.AllScreens[ScreenType.Game.ToInt()].Cast<Screens.GameScreen>().RegenerateClones();
                    IsTrackingPlayer = false;
                    noStackDelay = new TimeSpan(0);
                }
            }

            if (isClone && isFirstUpdate)
            {
                killWorth /= 10;
                DamagePerShot /= 5;
                _initHealth /= 10;
                CurrentHealth /= 10;
                noStackDelay = new TimeSpan(0);
            }

            noStackDelay += gt.ElapsedGameTime;
            if (closestAllyShipDistance.HasValue && closestAllyShipDistance.Value.LengthSquared() < Math.Pow(400, 2) && noStackDelay >= noStack)
            {
                targetPosition = null;
                XSpeed = 0f;
                YSpeed = 0f;
                _isTrackingPlayer = true;
            }
            else if (targetPosition.HasValue)
            {
                speedVector = targetPosition.Value - WorldCoords;
                speedVector.Normalize();
                Rotation.Radians = speedVector.ToAngle();
                speedVector *= new Vector2(2);

                XSpeed = speedVector.X;
                YSpeed = speedVector.Y;
                if (XSpeed < .01f && YSpeed < .01f)
                {
                    targetPosition = null;
                }
            }
            else
            {
                XSpeed = 0f;
                YSpeed = 0f;
                _isTrackingPlayer = true;
            }
            if (isFirstUpdate)
            {
                isFirstUpdate = false;
            }

            base.Update(gt);
        }
示例#39
0
        private void Fire(GameTime gameTime)
        {
            if (BulletFrequence.TotalMilliseconds > 0)
                BulletFrequence -= gameTime.ElapsedGameTime;
            else
            {
                BulletFrequence = TimeSpan.FromTicks((long)(Improvements.ShootFrequencyData[Improvements.ShootFrequencyData.Count - 3].Key * Config.PlayerShootFrequency.Ticks));

                var direction = new Vector2((float)Math.Sin(Rotation), (float)Math.Cos(Rotation) * -1);

                // Straight
                if (PlayerData.ShootTypeIndex != 1)
                {
                    // Add randomness to bullet direction
                    float aimAngle = direction.ToAngle();
                    Quaternion aimQuat = Quaternion.CreateFromYawPitchRoll(0, 0, aimAngle);
                    float spreadAmount = 0.25f;

                    if (_focusMode)
                        spreadAmount /= 3f;

                    float randomSpread = GameRef.Rand.NextFloat(-spreadAmount, spreadAmount);

                    direction = MathUtil.FromPolar(aimAngle + randomSpread, 11f);
                    direction.Normalize();

                    Vector2 offset = Vector2.Transform(new Vector2(0, 0), aimQuat);

                    var bullet = new Bullet(GameRef, _bulletSprite, Position + offset, direction, Config.PlayerBulletVelocity);
                    bullet.WaveMode = false;

                    AddBullet(bullet);
                }

                // Front sides 1/2 diagonal
                if (PlayerData.ShootTypeIndex > 0)
                {
                    Vector2 directionLeft = direction;
                    Vector2 positionLeft = new Vector2(Position.X - 25f * (float)Math.Cos(Rotation), Position.Y - 25f * (float)Math.Sin(Rotation));
                    Vector2 directionRight = direction;
                    Vector2 positionRight = new Vector2(Position.X + 25f * (float)Math.Cos(Rotation), Position.Y + 25f * (float)Math.Sin(Rotation));

                    if (!SlowMode)
                    {
                        directionLeft = new Vector2((float)Math.Sin(Rotation - Math.PI / 4), (float)Math.Cos(Rotation - Math.PI / 4) * -1);
                        directionRight = new Vector2((float)Math.Sin(Rotation + Math.PI / 4), (float)Math.Cos(Rotation + Math.PI / 4) * -1);
                    }

                    var bulletLeft = new Bullet(GameRef, _bulletSprite, positionLeft, directionLeft, Config.PlayerBulletVelocity);

                    var bulletRight = new Bullet(GameRef, _bulletSprite, positionRight, directionRight, Config.PlayerBulletVelocity);

                    AddBullet(bulletLeft);
                    AddBullet(bulletRight);
                }

                // Front sides 1/4 diagonal
                if (PlayerData.ShootTypeIndex >= 3)
                {
                    Vector2 directionLeft = direction;
                    Vector2 positionLeft = new Vector2(Position.X - 10f * (float)Math.Cos(Rotation), Position.Y - 10f * (float)Math.Sin(Rotation));
                    Vector2 directionRight = direction;
                    Vector2 positionRight = new Vector2(Position.X + 10f * (float)Math.Cos(Rotation), Position.Y + 10f * (float)Math.Sin(Rotation));

                    if (!SlowMode)
                    {
                        directionLeft = new Vector2((float)Math.Sin(Rotation - Math.PI / 8), (float)Math.Cos(Rotation - Math.PI / 8) * -1);
                        directionRight = new Vector2((float)Math.Sin(Rotation + Math.PI / 8), (float)Math.Cos(Rotation + Math.PI / 8) * -1);
                    }

                    var bulletLeft = new Bullet(GameRef, _bulletSprite, positionLeft, directionLeft, Config.PlayerBulletVelocity);
                    bulletLeft.Power = 0.5f;

                    var bulletRight = new Bullet(GameRef, _bulletSprite, positionRight, directionRight, Config.PlayerBulletVelocity);
                    bulletRight.Power = 0.5f;

                    AddBullet(bulletLeft);
                    AddBullet(bulletRight);
                }

                // Behind
                if (PlayerData.ShootTypeIndex >= 2)
                {
                    var directionBehind = new Vector2((float)Math.Sin(Rotation) * -1, (float)Math.Cos(Rotation));

                    var bullet = new Bullet(GameRef, _bulletSprite, Position, directionBehind, Config.PlayerBulletVelocity);
                    bullet.Power = Improvements.ShootPowerData[PlayerData.ShootPowerIndex].Key;
                    bullet.WaveMode = false;

                    AddBullet(bullet);
                }

                _shootSound.Play();

                //FireParticles(gameTime);
            }
        }
示例#40
0
        private void FireParticles(GameTime gameTime)
        {
            double t = gameTime.TotalGameTime.TotalSeconds;

            var direction = new Vector2((float)Math.Sin(Rotation), (float)Math.Cos(Rotation) * -1);
            float aimAngle = direction.ToAngle();
            Quaternion rot = Quaternion.CreateFromYawPitchRoll(0, 0, aimAngle);

            // The primary velocity of the particles is 3 pixels/frame in the direction opposite to which the ship is travelling.
            Vector2 baseVel = direction.ScaleTo(2);

            // Calculate the sideways velocity for the two side streams. The direction is perpendicular to the ship's velocity and the
            // magnitude varies sinusoidally.
            var perpVel = new Vector2(baseVel.Y, -baseVel.X) * (0.6f * (float)Math.Sin(t * 10));
            var sideColor = new Color(200, 38, 9);    // deep red
            var midColor = new Color(255, 187, 30);   // orange-yellow
            var pos = Position;   // position of the ship's exhaust pipe.
            const float alpha = 0.7f;

            // middle particle stream
            Vector2 velMid = baseVel + GameRef.Rand.NextVector2(0, 1);

            GameRef.ParticleManager.CreateParticle(GameRef.LineParticle, pos, Color.White * alpha, 60f, new Vector2(0.5f, 1),
                new ParticleState(velMid, ParticleType.Enemy));
            GameRef.ParticleManager.CreateParticle(GameRef.Glow, pos, midColor * alpha, 60f, new Vector2(0.5f, 1),
                new ParticleState(velMid, ParticleType.Enemy));

            // side particle streams
            Vector2 vel1 = baseVel + perpVel + GameRef.Rand.NextVector2(0, 0.3f);
            Vector2 vel2 = baseVel - perpVel + GameRef.Rand.NextVector2(0, 0.3f);

            GameRef.ParticleManager.CreateParticle(GameRef.LineParticle, pos, Color.White * alpha, 60f, new Vector2(0.5f, 1),
                new ParticleState(vel1, ParticleType.Enemy));
            GameRef.ParticleManager.CreateParticle(GameRef.LineParticle, pos, Color.White * alpha, 60f, new Vector2(0.5f, 1),
                new ParticleState(vel2, ParticleType.Enemy));

            GameRef.ParticleManager.CreateParticle(
                GameRef.Glow, pos, sideColor * alpha, 60f, new Vector2(0.5f, 1),
                new ParticleState(vel1, ParticleType.Enemy)
            );
            GameRef.ParticleManager.CreateParticle(
                GameRef.Glow, pos, sideColor * alpha, 60f, new Vector2(0.5f, 1),
                new ParticleState(vel2, ParticleType.Enemy)
            );
        }
示例#41
0
        public Ship(Texture2D texture, Vector2 location, SpriteBatch spriteBatch)
            : base(texture, location, spriteBatch)
        {
            StateManager.Options.ScreenResolutionChanged += new EventHandler<ViewportEventArgs>(Options_ScreenResolutionChanged);
            _healthBar = new ProgressBar(new Vector2(X, Y), Color.DarkGreen, Color.Red, spriteBatch);
            _healthBar.WidthScale = 1;
            _healthBar.HeightScale = 10;
            Moved += new EventHandler(Ship_Moved);
            _shipID = Guid.NewGuid();
            _initHealth = 100;
            _healthBar.X -= (_healthBar.Width / 2);
            _healthBar.Y -= (_healthBar.Height / 1.5f);

            _isDead = false;

            Explosion = GameContent.Assets.Images.SpriteSheets[SpriteSheetType.Explosion];
            _explosionSheet = new SpriteSheet(GameContent.Assets.Images.SpriteSheets[SpriteSheetType.Explosion], new Rectangle(0, 0, 50, 50), this.Position, spriteBatch, 8, 9);

            _explosionSheet.IsAnimated = true;
            _explosionSheet.Scale = new Vector2(1.5f);
            _explosionSheet.RestartAnimation = false;
            _currentHealth = _initHealth;

            ExplosionSFX = GameContent.Assets.Sound[SoundEffectType.EnemyExplodes];
            FriendlyName = ShipType.ToFriendlyString();

            particles[0] = GameContent.Assets.Images.particles[ParticleType.Circle];
            particles[1] = GameContent.Assets.Images.particles[ParticleType.Square];
            gen = new RandomParticleGenerator(SpriteBatch, particles);
            gen.TTLSettings = TimeToLiveSettings.AlphaLess100;
            gen.RandomProperties = new RandomParticleProperties() { ColorFactor = 0.985f, Tint = Color.White };
            gen.ParticlesToGenerate = 1;
            engine = new Glib.XNA.SpriteLib.ParticleEngine.ParticleEngine(gen);

            Vector2 toEngine = new Vector2(Position.X, Position.Y - texture.Height / 2);
            toEngineLength = -toEngine.Length();
            toEngineAngle = toEngine.ToAngle();

            engine.PositionOffset = new Vector2(0, texture.Height / 2);

            engine.Tracked = this;
        }
示例#42
0
文件: Thruster.cs 项目: hgrandry/Mgx
 private void RotateWithGamePad(Vector2 input)
 {
     _targetRotation = -input.ToAngle() + MathKit.Pi;
 }
        public void Vector2_ToAngle_Test()
        {
            var a = new Vector2(0, -10);
            var b = new Vector2(10, 0);
            var c = -Vector2.UnitY.Rotate(MathHelper.ToRadians(45));

            Assert.AreEqual(MathHelper.ToRadians(0), a.ToAngle());
            Assert.AreEqual(MathHelper.ToRadians(90), b.ToAngle());
            Assert.AreEqual(MathHelper.ToRadians(45), c.ToAngle());
        }
示例#44
0
 public static float ConvertToGlobal(this float orientation, Vector2 origin)
 {
     return origin.ToAngle() + orientation;
 }
示例#45
0
 public void TextureChanged()
 {
     Vector2 toEngine = new Vector2(Texture.Bounds.Left - Texture.Width / 2 * Scale.X, Texture.Bounds.Top - Texture.Height / 2 * Scale.Y);
     toEngineLength = -toEngine.Length();
     toEngineAngle = toEngine.ToAngle();
 }