Пример #1
0
        public static void Instantiate()
        {
            //Instantiate the sprite
            background = new Sprite();

            //Initialize the array
            arrows = new Sprite[8];

            //Instantiate the lock
            locked = new Sprite();

            //Instantiate the arrows
            for (int i = 0; i < arrows.Length; i++)
            {
                arrows[i] = new Sprite();
            }

            //Instantiate the currently selected array
            currentlySelected = new int[4];

            //Instantiate the unlocked array
            unlocked = new bool[4];

            //Instantiate the examples
            exampleColour = new Sprite();
            exampleCar = new Sprite[4];
            for (int i = 0; i < exampleCar.Length; i++)
            {
                exampleCar[i] = new Sprite();
            }
            exampleOffUpgr = new Sprite[4];
            for (int i = 0; i < exampleOffUpgr.Length; i++)
            {
                exampleOffUpgr[i] = new Sprite();
            }
            exampleShield = new Sprite();
            exampleShieldGlow = new Sprite();

            //Instantiate the example road
            exampleRoad = new Sprite();
            example = new Car();
        }
Пример #2
0
        public static void Instantiate()
        {
            background = new Sprite();
            buttons = new ButtonGroup();
            moneyDisplay = new Sprite();

            ArenaShop.Instantiate();
            CarShop.Instantiate();
            DefensiveUpgradeShop.Instantiate();
            OffensiveUpgradeShop.Instantiate();

            //Instantiate the example
            example = new Car();
            exampleRoad = new Sprite();

            //Instantiate the popups
            notEnoughMoneyNotice = new Popup();
            areYouSurePopup = new Popup();
        }
Пример #3
0
        public static void Instantiate()
        {
            //Instantiate the arena post processing class
            ArenaPostProcessing.Instantiate();

            //Instantiate the pause screen
            PauseMenu.Instantiate();

            //Instantiate the b-button
            bButton = new Sprite();
            xButton = new Sprite();

            //Instantiate the fader
            fader = new Sprite();

            cars = new Car[4];
            //Instantiate the cars
            for (int i = 0; i < cars.Length; i++)
            {
                cars[i] = new Car();
            }

            //Instantiate the upgrade lists
            mines = new List<Mine>();
            rockets = new List<Rocket>();
            cRockets = new List<CRocket>();

            //Instantiate the audioengine
            AudioEngine.Instantiate();
        }
Пример #4
0
        public static void FireRocket(Car sender)
        {
            Rocket tempRocket = new Rocket();
            if (sender.LastFire >= tempRocket.ReloadTime)
            {
                tempRocket.Initialize();
                tempRocket.LoadContent();

                rockets.Add(tempRocket);
                rockets[rockets.Count - 1].Fire(sender);

                //Set the last fire to 0
                sender.LastFire = 0;
            }
        }
Пример #5
0
        public static void FireCRocket(Car sender)
        {
            CRocket tempRocket = new CRocket();

            //Check if the player can fire again
            if (sender.LastFire >= tempRocket.ReloadTime)
            {
                tempRocket.Initialize();
                tempRocket.LoadContent();

                cRockets.Add(tempRocket);
                cRockets[cRockets.Count - 1].Fire(sender);

                //Set the last fire to 0
                sender.LastFire = 0;
            }
        }
Пример #6
0
        public static void DropMine(Car sender)
        {
            Mine tempMine = new Mine();
            if (sender.LastFire >= tempMine.ReloadTime)
            {
                tempMine.Initialize();
                tempMine.LoadContent();

                mines.Add(tempMine);
                mines[mines.Count - 1].Drop(sender.Position, sender.Driver);

                //Set the last fire to 0
                sender.LastFire = 0;
            }
        }
Пример #7
0
        //Method to check for collision
        public void CheckCollision(ref Car otherCar, int precision)
        {
            Vector2 collisionPosition = bounds.Intersects(otherCar.bounds, precision);

            if (collisionPosition != Vector2.Zero)
            {
                //Set the last rotation even if there is no front collision
                //rotation = lastRotation;
                //otherCar.rotation = otherCar.lastRotation;

                #region Check if this car does damage
                //First, I want the angle of impact from both cars
                float dx = collisionPosition.X - position.X;
                float dy = collisionPosition.Y - position.Y;

                float angleOfImpact = (float)Math.Atan(dy / dx);

                //If dx is lower than 0, the tanges returns the angle on the wrong side of the
                //Unit circle, this needs to be corrected
                if (dx < 0)
                {
                    angleOfImpact += (float)Math.PI;
                }

                //Set the range of the angle between 0 and 2*PI
                while (angleOfImpact > 2 * Math.PI)
                {
                    angleOfImpact -= 2 * (float)Math.PI;
                }

                while (angleOfImpact < 0)
                {
                    angleOfImpact += 2 * (float)Math.PI;
                }

                //We now have the correct angle of impact!
                //Lets adjust this to the cars angle, and store it in a new variable!
                float relativeAngleOfImpact = rotation - angleOfImpact;

                //Get the angle of one of the front corners
                //The other front corner has the negative angle
                float frontCornersAngle = (float)(Math.Atan((float)(bounds.Height / 2) / (float)(bounds.Width / 2)) + (Math.PI / (precision / 5)));

                while (relativeAngleOfImpact < -Math.PI)
                {
                    relativeAngleOfImpact += (float)Math.PI * 2;
                }

                //Check if the collision is between the front corners. This would mean the driver hit the other car on purpose
                //If the car is driving backwards, check for back corners.
                if (speed > 0)
                {
                    if (relativeAngleOfImpact < frontCornersAngle || relativeAngleOfImpact > (Math.PI * 2) - frontCornersAngle)
                    {
                        position = lastPosition;

                        if (speed > .5f)
                        {
                            otherCar.DecreaseHealth((int)(damageFactor * Math.Abs(speed)));
                            damageDealt += otherCar.lastHealth - otherCar.HealthT;

                            otherCar.TakeMomentum(splitSpeed + momentum);
                        }

                        speed = 0;
                    }
                    else
                    {
                        rotation = lastRotation;
                    }
                }
                else if (speed < 0)
                {
                    if (relativeAngleOfImpact < frontCornersAngle + Math.PI && relativeAngleOfImpact > (Math.PI * 2) - frontCornersAngle + Math.PI)
                    {
                        position = lastPosition;

                        if (speed < -.5f)
                        {
                            otherCar.DecreaseHealth((int)(damageFactor * Math.Abs(speed)));
                            damageDealt += otherCar.lastHealth - otherCar.HealthT;

                            otherCar.TakeMomentum(splitSpeed + momentum);
                        }

                        speed = 0;
                    }
                    else
                    {
                        rotation = lastRotation;
                    }
                }

                #endregion

                #region check if other car does damage
                //First, I want the angle of impact from both cars
                dx = collisionPosition.X - otherCar.position.X;
                dy = collisionPosition.Y - otherCar.position.Y;

                angleOfImpact = (float)Math.Atan(dy / dx);

                //If dx is lower than 0, the tanges returns the angle on the wrong side of the
                //Unit circle, this needs to be corrected
                if (dx < 0)
                {
                    angleOfImpact += (float)Math.PI;
                }

                //Set the range of the angle between 0 and 2*PI
                while (angleOfImpact > 2 * Math.PI)
                {
                    angleOfImpact -= 2 * (float)Math.PI;
                }

                while (angleOfImpact < 0)
                {
                    angleOfImpact += 2 * (float)Math.PI;
                }

                //We now have the correct angle of impact!
                //Lets adjust this to the cars angle, and store it in a new variable!
                relativeAngleOfImpact = otherCar.rotation - angleOfImpact;

                //Get the angle of one of the front corners
                //The other front corner has the negative angle
                frontCornersAngle = (float)(Math.Atan((float)(otherCar.bounds.Height / 2) / (float)(otherCar.bounds.Width / 2)) + (Math.PI / (precision / 5)));

                //Check if the collision is between the front corners. This would mean the driver hit the other car on purpose
                //If the car is driving backwards, check for back corners.
                if (otherCar.speed > 0)
                {
                    if (relativeAngleOfImpact < frontCornersAngle || relativeAngleOfImpact > (Math.PI * 2) - frontCornersAngle)
                    {
                        otherCar.position = otherCar.lastPosition;

                        if (otherCar.speed > .5f)
                        {
                            DecreaseHealth((int)(otherCar.damageFactor * Math.Abs(otherCar.speed)));
                            otherCar.damageDealt += lastHealth - HealthT;

                            TakeMomentum(otherCar.splitSpeed + otherCar.momentum);
                        }

                        otherCar.speed = 0;

                    }
                    else
                    {
                        otherCar.rotation = otherCar.lastRotation;
                    }
                }
                else if (otherCar.speed < 0)
                {
                    if (relativeAngleOfImpact < frontCornersAngle + Math.PI && relativeAngleOfImpact > -frontCornersAngle + Math.PI)
                    {
                        otherCar.position = otherCar.lastPosition;

                        if (otherCar.speed < -.5f)
                        {
                            DecreaseHealth((int)(otherCar.damageFactor * Math.Abs(otherCar.speed)));
                            otherCar.damageDealt += Math.Min((int)(otherCar.damageFactor * Math.Abs(otherCar.speed)), HealthT);

                                                    TakeMomentum(otherCar.splitSpeed + otherCar.momentum);
                        }

                        otherCar.speed = 0;

                    }
                    else
                    {
                        otherCar.rotation = otherCar.lastRotation;
                    }
                }
                #endregion
            }
        }