Exemplo n.º 1
0
 public Shield(Shield bumper)
 {
     this.health = bumper.health;
     this.shield = bumper.shield;
     this.glow = bumper.glow;
     this.maxHealth = bumper.maxHealth;
     this.bounds = bumper.bounds;
 }
Exemplo n.º 2
0
        public virtual void LoadContent(ContentManager content)
        {
            //Load the shield graphics
            shield.LoadContent(content.Load<Texture2D>("Graphics/Cars/Def_Upgr/Shield"));
            glow.LoadContent(content.Load<Texture2D>("Graphics/Cars/Def_Upgr/Shield_Glow"));

            //Set the origin of the shield to the middle
            shield.Origin = new Vector2(shield.Texture.Bounds.Width, shield.Texture.Bounds.Height) / 2;
            glow.Origin = new Vector2(glow.Texture.Bounds.Width, glow.Texture.Bounds.Height) / 2;

            //Set the bounds
            bounds = new RotatableRectangle(0, 0, shield.Texture.Width, shield.Texture.Height);
        }
Exemplo n.º 3
0
        public Vector2 Intersects(RotatableRectangle rectangle, int precision)
        {
            Vector2[] edgesRect1 = new Vector2[precision * 4];
            Vector2[] edgesRect2 = new Vector2[precision * 4];

            #region Filling the cornersInOrder NEW METHOD
            #region Set up the corners in the correct order from top counter-clockwise
            //Set up the arrays for the corner in order
            Vector2[] cornersInOrder1 = new Vector2[4];
            Vector2[] cornersInOrder2 = new Vector2[4];

            //Create variables to keep track of what is the lowest point yet.
            //I set them to a value sure to be more right or lower, and a buffer of 10 pixels
            float highestYValue = position.Y + radius + 10;
            float mostLefttXValue = position.X + radius + 10;
            int nrOneCorner = 0;

            #region fill corners in order of this rectangle
            //Check every corner
            for (int i = 0; i < 4; i++)
            {
                //Is the corner equal to a previously measured Y value? (The dots are on the same height)
                //Then check if this corner is more left then the other
                if (corners[i].Y == highestYValue &&
                    corners[i].X < mostLefttXValue)
                {
                    highestYValue = corners[i].Y;
                    mostLefttXValue = corners[i].X;
                    nrOneCorner = i;
                }

                //If the y value of the current corner is lower than the last lowest y value
                //This corner is higher. so set this as the nr1 corner
                if (corners[i].Y < highestYValue)
                {
                    highestYValue = corners[i].Y;
                    mostLefttXValue = corners[i].X;
                    nrOneCorner = i;
                }
            }

            //Now fill in the corners in order
            int currentCorner = nrOneCorner;
            for (int i = 0; i < 4; i++)
            {
                cornersInOrder1[i] = corners[currentCorner];

                //Set the next corner as the current corner
                currentCorner++;

                //If we are currently getting the 5th corner, we will get an error.
                //The 5th corner should be the first, so:
                if (currentCorner > 3)
                {
                    currentCorner = 0;
                }
            }
            #endregion

            #region fill corners in order of the other rectangle
            highestYValue = rectangle.position.Y + rectangle.radius + 10;
            mostLefttXValue = rectangle.position.X + rectangle.radius + 10;
            nrOneCorner = 0;

            //Check every corner
            for (int i = 0; i < 4; i++)
            {
                //Is the corner equal to a previously measured Y value? (The dots are on the same height)
                //Then check if this corner is more left then the other
                if (rectangle.corners[i].Y == highestYValue &&
                    rectangle.corners[i].X < mostLefttXValue)
                {
                    highestYValue = rectangle.corners[i].Y;
                    mostLefttXValue = rectangle.corners[i].X;
                    nrOneCorner = i;
                }

                //If the y value of the current corner is lower than the last lowest y value
                //This corner is higher. so set this as the nr1 corner
                if (rectangle.corners[i].Y < highestYValue)
                {
                    highestYValue = rectangle.corners[i].Y;
                    mostLefttXValue = rectangle.corners[i].X;
                    nrOneCorner = i;
                }
            }

            //Now fill in the corners in order
            currentCorner = nrOneCorner;
            for (int i = 0; i < 4; i++)
            {
                cornersInOrder2[i] = rectangle.corners[currentCorner];

                //Set the next corner as the current corner
                currentCorner++;

                //If we are currently getting the 5th corner, we will get an error.
                //The 5th corner should be the first, so:
                if (currentCorner > 3)
                {
                    currentCorner = 0;
                }
            }
            #endregion
            #endregion
            #endregion

            #region Filling the edges arrays with the proper Vectors
            for (int i = 0; i < 4; i++)
            {
                #region Gaining the steps
                float xStep1, yStep1, xStep2, yStep2;

                //Getting the steps
                if (i + 1 == 4)
                {
                    xStep1 = (cornersInOrder1[0].X - cornersInOrder1[i].X) / precision;
                    yStep1 = (cornersInOrder1[0].Y - cornersInOrder1[i].Y) / precision;

                    xStep2 = (cornersInOrder2[0].X - cornersInOrder2[i].X) / precision;
                    yStep2 = (cornersInOrder2[0].Y - cornersInOrder2[i].Y) / precision;
                }
                else
                {
                    xStep1 = (cornersInOrder1[i + 1].X - cornersInOrder1[i].X) / precision;
                    yStep1 = (cornersInOrder1[i + 1].Y - cornersInOrder1[i].Y) / precision;

                    xStep2 = (cornersInOrder2[i + 1].X - cornersInOrder2[i].X) / precision;
                    yStep2 = (cornersInOrder2[i + 1].Y - cornersInOrder2[i].Y) / precision;
                }
                #endregion

                for (int j = 0; j < precision; j++)
                {
                    //Filling the arrays
                    edgesRect1[precision * i + j] = new Vector2(cornersInOrder1[i].X + xStep1 * j, cornersInOrder1[i].Y + yStep1 * j);
                    edgesRect2[precision * i + j] = new Vector2(cornersInOrder2[i].X + xStep2 * j, cornersInOrder2[i].Y + yStep2 * j);
                }
            }

            #endregion

            #region Comparing the 2 Arrays
            Rectangle[] LeftToRight = new Rectangle[2 * precision];
            Rectangle[] RightToLeft = new Rectangle[2 * precision];

            for (int i = 0; i < 2 * precision; i++)
            {
                LeftToRight[i] = new Rectangle((int)edgesRect1[i].X, (int)edgesRect1[i].Y, (int)radius * 2, (int)(edgesRect1[i + 1].Y - edgesRect1[i].Y + 1));
                RightToLeft[i] = new Rectangle((int)(edgesRect1[precision * 4 - (i + 1)].X - radius * 2), (int)edgesRect1[precision * 4 - (i + 1)].Y,
                    (int)radius * 2, (int)(edgesRect1[precision * 4 - (i + 2)].Y - edgesRect1[precision * 4 - (i + 1)].Y + 1));
            }

            bool isInFromLeft = false;
            bool isInFromRight = false;

            for (int i = 0; i < precision * 4; i++)
            {
                for (int j = 0; j < 2 * precision; j++)
                {
                    if (LeftToRight[j].Intersects(new Rectangle((int)edgesRect2[i].X, (int)edgesRect2[i].Y, 1, 1)))
                    {
                        isInFromLeft = true;
                    }

                    if (RightToLeft[j].Intersects(new Rectangle((int)edgesRect2[i].X, (int)edgesRect2[i].Y, 1, 1)))
                    {
                        isInFromRight = true;
                    }

                    if (isInFromLeft && isInFromRight)
                    {
                        collisionPositions.Add(new Vector2(edgesRect2[i].X, edgesRect2[i].Y));
                        return new Vector2(edgesRect2[i].X, edgesRect2[i].Y);
                    }
                }
            }

            #endregion

            //No side is returned, so return none.
            return Vector2.Zero;
        }
Exemplo n.º 4
0
        public void Set()
        {
            //Set the car showing
            carShown = InfoPacket.PlayerStatistics[playerNumber].CarUsing;

            //Set the spritetexture as the currently used cartexture by the player using this class.
            carSprite.LoadContent(carTextures[InfoPacket.PlayerStatistics[playerNumber].CarUsing]);
            windowSprite.LoadContent(windowTextures[InfoPacket.PlayerStatistics[playerNumber].CarUsing]);

            //Set the colour of the car
            color = InfoPacket.PlayerStatistics[playerNumber].CarColour;
            carSprite.Color = color;

            //Set the rotation of the sprite
            carSprite.Rotation = rotation;
            windowSprite.Rotation = rotation;

            //Set the car stats to the current car used by the player
            if (carShown == 0)
            {
                totalHealth = 100;
                maxSpeed = 5;
                maxAcceleration = .1f;
                damageFactor = 1.5f * stdFactor;
            }
            else if (carShown == 1)
            {
                totalHealth = 200;
                maxSpeed = 6;
                maxAcceleration = .2f;
                damageFactor = 2 * stdFactor;
            }
            else if (carShown == 2)
            {
                totalHealth = 300;
                maxSpeed = 4;
                maxAcceleration = .15f;
                damageFactor = 4 * stdFactor;
            }
            else if (carShown == 3)
            {
                totalHealth = 300;
                maxSpeed = 9;
                maxAcceleration = .5f;
                damageFactor = 2 * stdFactor;
            }

            rotationSpeed = maxSpeed * .05f;

            //Set health to full
            currentHealth = totalHealth;

            //Set damageDealt to 0
            damageDealt = 0;

            //Set time in game to 0
            msAlive = 0;

            //Set the speed to 0
            speed = 0;

            //Set the rotation speed
            rotationSpeed -= .0075f * maxSpeed;

            //Set the last fire very high
            lastFire = 100000;

            //Set the shield
            shield.Set(this);

            if (shield.Strenght != 0)
            {
                bounds = shield.Bounds;
            }
        }
Exemplo n.º 5
0
        public void DecreaseHealth(int value)
        {
            if (shield.Health != 0)
            {
                shield.Damage(Math.Min(shield.Health, value));

                if (shield.Health == 0)
                {
                    //Set the bounds back to no bumper
                    bounds = new RotatableRectangle((int)position.X, (int)position.Y, 80, 40);
                    bounds.Rotation = rotation;

                    //Keep the health in bounds
                    shield.Health = 0;
                }
            }
            else
            {
                currentHealth -= value;

                if (currentHealth < 0)
                {
                    currentHealth = 0;
                }
            }
        }
Exemplo n.º 6
0
        public Car()
        {
            //Instantiate the texture array
            carTextures = new Texture2D[4];
            windowTextures = new Texture2D[4];

            //Instantiate the car sprite
            carSprite = new Sprite();
            windowSprite = new Sprite();

            //Instantiate the bounds
            bounds = new RotatableRectangle(0, 0, 80, 40);

            //Instantiate the shield
            shield = new Shield();
        }
Exemplo n.º 7
0
        public Rocket()
        {
            //Instantiate the sprites
            rocket = new Sprite();
            explosion = new Sprite();
            tail = new Sprite();
            cRocket = new Sprite();

            //Instantiate the bounds
            bounds = new RotatableRectangle(0, 0, 64, 16);
            explosionBounds = new Circle(16, Vector2.Zero);

            //Instantiate the array
            hasHit = new bool[4];
        }