Exemple #1
0
        public bool isColliding(RotatingSprite obj)
        {
            //Get Rotated Corners
            Vector2[] targetCorners = getCorners(obj);
            Vector2[] myCorners     = getCorners(this);

            //Get all axis
            List <Vector2> checkedAxis = new List <Vector2>();

            List <Vector2> axiss = getAxis(myCorners);

            axiss.AddRange(getAxis(targetCorners));

            foreach (Vector2 axis in axiss)
            {
                if (!checkedAxis.Contains(axis))
                {
                    //index: 0 = min, 1 = Max
                    float[] box1 = getMinMaxDP(myCorners, axis);
                    float[] box2 = getMinMaxDP(targetCorners, axis);

                    //Check for overlap
                    if (box1[1] < box2[0] || box1[0] > box2[1])
                    {
                        return(false);
                    }

                    checkedAxis.Add(axis);
                }
            }
            return(true);
        }
Exemple #2
0
        private Vector2[] getCorners(RotatingSprite obj)
        {
            Vector2[] corners = new Vector2[4];

            //Get the Corners of the object's Rectangle
            int halfWidth, halfHeight;

            halfWidth  = obj.Rec.Width / 2;
            halfHeight = obj.Rec.Height / 2;
            corners[0] = new Vector2(obj.Rec.X - halfWidth, obj.Rec.Y - halfHeight);
            corners[1] = new Vector2(obj.Rec.X + halfWidth, obj.Rec.Y - halfHeight);
            corners[2] = new Vector2(obj.Rec.X + halfWidth, obj.Rec.Y + halfHeight);
            corners[3] = new Vector2(obj.Rec.X - halfWidth, obj.Rec.Y + halfHeight);

            //Rotates the corners to their accurate position
            Vector2[] rotatedCorners   = (Vector2[])corners.Clone();
            Matrix    myRotationMatrix = Matrix.CreateRotationZ(obj.Rotation);

            for (int i = 0; i < rotatedCorners.Length; i++)
            {
                Vector2 rotatedVector = Vector2.Transform(rotatedCorners[i] - new Vector2(obj.Rec.X, obj.Rec.Y), myRotationMatrix);
                rotatedCorners[i] = rotatedVector + new Vector2(obj.Rec.X, obj.Rec.Y);
            }

            return(rotatedCorners);
        }
Exemple #3
0
 public PhysicalGun(Character character, WeaponType wepType, int iq, int damage, float accuracy, float reloadSpd, float fireRate, float range,
                    int MagSize, int numShots = 1, int pierce = 1, bool isAutomatic = true)
     : base(character, wepType, iq, damage, accuracy, reloadSpd, fireRate, range, MagSize, numShots, pierce, isAutomatic)
 {
     muzzleFlare  = new RotatingSprite(Image.Muzzle.Physical, 0.05f, 0, Vector2.Zero, this.Rotation);
     muzzleOffset = new Vector2(0, (int)(-muzzleFlare.Rec.Height * 0.28f - this.Rec.Height / 2));
 }
Exemple #4
0
 protected virtual void hitObject(RotatingSprite obj)
 {
     if (obj.GetType().IsSubclassOf(typeof(Enemy)))
     {
         Enemy ene = (Enemy)obj;
         ene.damage(this);
     }
 }
Exemple #5
0
        public override void draw(SpriteBatch spriteBatch)
        {
            //Draw bullets
            foreach (Bullet bull in bulls)
            {
                bull.draw(spriteBatch);
            }

            //if(this gun isn't equipt) : only draw the bullets
            if (Holder.CurGun != this)
            {
                return;
            }

            //Draw Muzzle flare
            Matrix  myRotationMatrix = Matrix.CreateRotationZ(this.Rotation);
            Vector2 muzzPos          = Vector2.Transform(muzzleOffset, myRotationMatrix) + this.Position;

            muzzleFlare = new RotatingSprite(muzzleFlare.Texture, muzzleFlare.ScaleFactor, 0, muzzPos, this.Rotation);

            if (isShooting)
            {
                muzzleFlare.draw(spriteBatch);
            }

            //Draw Ammo count or Reload timer
            Vector2 ammoPos = Holder.Position + new Vector2(Holder.Rec.Width * 0.9f, Holder.Speed * 10);

            if (reloadTimer > 0)
            {
                spriteBatch.DrawString(Fonts.Normal, reloadTimer.ToString("0.0"), ammoPos, Color.Red);
            }
            else
            {
                spriteBatch.DrawString(Fonts.Normal, "" + CurrMag + "/" + CurAmmo, ammoPos, Color.White);
            }

            //Draw Gun
            base.draw(spriteBatch);
        }
Exemple #6
0
        private void init(Character holder, WeaponType wepType, int iq, int damage, float accuracy, float reloadSpd, float fireRate, float range,
                          int magSize, int numShots = 1, int pierce = 1, bool isAutomatic = true)
        {
            this.IQ      = iq;
            this.wepType = wepType;
            setImage();

            bool isSmallArms = wepType == WeaponType.PISTOL || wepType == WeaponType.SMG;

            if (!isSmallArms)
            {
                offset = new Vector2(holder.Rec.Width * 0.33f, holder.Rec.Height * 0.001f);
            }
            else
            {
                offset = new Vector2(holder.Rec.Width * 0.20f, holder.Rec.Height * -0.12f);
            }

            this.Position = holder.Position;
            muzzleFlare   = new RotatingSprite(Image.Muzzle.Physical, 0.05f, 0, Vector2.Zero, this.Rotation);
            muzzleOffset  = new Vector2(this.Position.X, (int)(this.Position.Y - muzzleFlare.Rec.Height * 0.28f - this.Rec.Height / 2));

            Name        = "";
            bulls       = new List <Bullet>();
            this.Holder = holder;

            this.isAutomatic = isAutomatic;

            this.Damage    = damage;
            this.Pierce    = pierce;
            this.NumShots  = numShots;
            this.Range     = range;
            this.Accuracy  = accuracy;
            this.ReloadSpd = reloadSpd;
            this.FireRate  = fireRate;

            this.CurrMag = this.MagSize = magSize;

            fireTimer = 1 / FireRate;
        }