public void Move(GameObject obj, ShipUpdateInfo info)
        {
            //Get the direction from the player (controller)
            Vector2 direction = player.input.ShipMoveDirNormal();

            //Check is the player is trying to move
            //Since update (GameObject) will try and move the ship
            //if player is not trying to move we flag it false
            if (direction.X == 0 && direction.Y == 0)
            {
                obj.moving = false;
            }
            else
            {
                obj.moving = true;             //re-flag true in case set to false

                direction.Normalize();         //just in case....
                obj.SetRotation(direction);

                //Since SetRotation() above, also turns the "face" direction
                //we need to correct this for the human players whose ships
                //always face directly upwards on the screen
                obj.SetFaceDir(VecUtil.GetNormUP());
            }
        }
 public virtual void Rotate(Vector2 v)
 {
     v.Normalize();
     VecUtil.Rotate((double)VecUtil.GetAngle(ref v), ref faceDir);
     VecUtil.Rotate((double)VecUtil.GetAngle(ref v), ref moveDir);
     UpdateRotation();
 }
Example #3
0
        //Screen coordinates where the bullets should appear (orriginate from)
        public Vector2 GetBulletSpawnPosition()
        {
            Vector2 v = this.bulletOffset;

            VecUtil.Rotate((double)this.rotation, ref v);

            return(new Vector2(this.position.X + v.X, this.position.Y + v.Y));
        }
Example #4
0
        public List <Bullet> GetBullets(Weapon weapon)
        {
            List <Bullet> toReturn = new List <Bullet>();

            toReturn.Add(
                Creator.CreateBullet(
                    weapon.bulletType,
                    weapon.GetBulletSpawnPosition(),
                    VecUtil.GetNormAng(weapon.rotation)));

            return(toReturn);
        }
        public void Move(GameObject obj, ShipUpdateInfo info)
        {
            if (done)
            {
                return;
            }

            if (obj.position.X > (info.viewport.Left + 100) &&
                obj.position.X < (info.viewport.Right - 100))
            {
                done = true;
                obj.SetRotation(VecUtil.GetNormDown());
            }
        }
        public virtual void SetFaceDir(Vector2 v)
        {
            if (v.X == 0 && v.Y == 0)
            {
                v = VecUtil.GetNormDown();
            }
            else
            {
                v.Normalize();
            }

            faceDir = v;
            UpdateRotation();
        }
        public void Move(GameObject obj, ShipUpdateInfo info)
        {
            timer.Update(info.gameTime);

            switch (timer.Current)
            {
            case Timer2.TimerNum.First:
                obj.SetRotation(VecUtil.GetNormLeft());
                break;

            case Timer2.TimerNum.Second:
                obj.SetRotation(VecUtil.GetNormRight());
                break;
            }

            obj.SetFaceDir(VecUtil.GetNormDown());
        }
Example #8
0
        //Make sure the weapon is positioned and rotated correctly
        //according to ship position, and AimMethod
        public void AdjustWeaponPos()
        {
            for (int i = 0; i < weapons.Length; i++)
            {
                //possibly lost a weapon at some point
                //Or ship starts with more weapon ports then weapons
                if (weapons[i] == null)
                {
                    continue;
                }

                //Rotate the weapon position to match ship rotation
                Vector2 v = weaponPortSave[i];                //get orrignal offset
                VecUtil.Rotate((double)this.rotation, ref v); //rotate it to match ship rotation
                this.weaponPort[i] = v;                       //update real offset

                //move weapon to new offset
                weapons[i].MoveTo(new Vector2(position.X + v.X, position.Y + v.Y));
            }
        }
        private Vector2 dir;    //left, right, up, or down, in Vector2 form

        public MMCardinal(Cardinal direction)
        {
            switch (direction)
            {
            case Cardinal.Down:
                dir = VecUtil.GetNormDown();
                break;

            case Cardinal.Up:
                dir = VecUtil.GetNormUP();
                break;

            case Cardinal.Left:
                dir = VecUtil.GetNormLeft();
                break;

            case Cardinal.Right:
                dir = VecUtil.GetNormRight();
                break;
            }
        }
Example #10
0
        public override void Update(ShipUpdateInfo info)
        {
            if (!sleep)     //do nothing while sleeping
            {
                if (moving) //while moving, fix subShip positions manually
                {
                    //Override the boss move method
                    base.SetRotation(VecUtil.GetNormDown());
                    CenterInHoriz(info.viewport);

                    //move boss down at a fixed rate
                    float speed = 0.05f;
                    speed *= (float)info.gameTime.ElapsedGameTime.Milliseconds;
                    Vector2 v = new Vector2(0, speed);
                    base.Offset(v);

                    AdjustWeaponPos();

                    //base.Update(info, false);

                    //Override subship movement
                    FixSubShipPositions();
                }
                else  //once stopped moving allow sub ships to move themselves
                {
                    hp.MoveTopLeftTo(new Vector2(info.viewport.Left + 150f, info.viewport.Top + 30));
                    hp.SetHealth(this.health);

                    //Allow all the subShips to move
                    foreach (Ship s in subShips)
                    {
                        s.Update(info);
                    }

                    //Allow main boss ship to move according ot its move method
                    base.Update(info);
                }
            }
        }
Example #11
0
        public List <Bullet> GetBullets(Weapon weapon)
        {
            List <Bullet> toReturn = new List <Bullet>();

            Vector2 v1, v2, v3;

            v1 = new Vector2(-0.1f, 1);  //x degrees left
            v2 = new Vector2(0, 1);      //Striaght up
            v3 = new Vector2(0.1f, 1);   //x degrees right
            v1.Normalize();
            v3.Normalize();

            //Rotate the 3 bullets to match (this) weapon rotation
            VecUtil.Rotate((double)weapon.rotation, ref v1);
            VecUtil.Rotate((double)weapon.rotation, ref v2);
            VecUtil.Rotate((double)weapon.rotation, ref v3);

            toReturn.Add(Creator.CreateBullet(weapon.bulletType, weapon.GetBulletSpawnPosition(), v1));
            toReturn.Add(Creator.CreateBullet(weapon.bulletType, weapon.GetBulletSpawnPosition(), v2));
            toReturn.Add(Creator.CreateBullet(weapon.bulletType, weapon.GetBulletSpawnPosition(), v3));

            return(toReturn);
        }
Example #12
0
        //############################################################################################
        //############################################################################################

        public static Bullet CreateBullet(BulletType type, Vector2 position, Vector2 direction)
        {
            Bullet b;

            switch (type)
            {
            case BulletType.PeaShot:

                b = new Bullet(Textures.TextureName.bulletBasic);
                b.LoadContent();

                b.MoveTo(position);
                b.speed = 0.3;
                b.SetRotation(VecUtil.GetAngle(ref direction));

                b.Damage = 1;

                return(b);


            case BulletType.Round:

                b = new Bullet(Textures.TextureName.bulletBasic2);
                b.LoadContent();

                b.MoveTo(position);
                b.speed = 0.3f;
                b.SetRotation(VecUtil.GetAngle(ref direction));
                b.moveMethod = new MMSnakeFast(MathHelper.ToRadians(180f) / 1000f, 400);


                b.Damage = 1;

                return(b);


            case BulletType.BRoundRedFast:

                b = new Bullet(Textures.TextureName.bulletRedRound);
                b.LoadContent();

                b.MoveTo(position);
                b.speed = 0.3f;
                b.SetRotation(VecUtil.GetAngle(ref direction));

                b.Damage = 1;

                return(b);


            case BulletType.BRoundRedSlow:

                b = new Bullet(Textures.TextureName.bulletRedRound);
                b.LoadContent();

                b.MoveTo(position);
                b.speed = 0.3f;
                b.SetRotation(VecUtil.GetAngle(ref direction));

                b.Damage = 1;

                return(b);


            case BulletType.Fatty:

                b = new Bullet(Textures.TextureName.bulletFatty);
                b.LoadContent();

                b.MoveTo(position);
                b.speed = 0.3;
                b.SetRotation(VecUtil.GetAngle(ref direction));

                b.Damage = 1;

                return(b);
            }

            return(null);
        }
 public virtual void SetRotation(float angle)
 {
     VecUtil.SetRotationNormal((double)angle, ref faceDir);
     VecUtil.SetRotationNormal((double)angle, ref moveDir);
     UpdateRotation();
 }
 private void UpdateRotation()
 {
     this.rotation = VecUtil.GetAngle(ref faceDir);
 }
 public virtual void SetFaceDir(float angle)
 {
     faceDir = VecUtil.GetNormAng(angle);
     UpdateRotation();
 }
 public virtual void Rotate(float angle)
 {
     VecUtil.Rotate((double)angle, ref faceDir);
     VecUtil.Rotate((double)angle, ref moveDir);
     UpdateRotation();
 }