コード例 #1
0
        //Resets the game in order to make a fresh, new game
        public static void NewGame()
        {
            //Disposes of menu music, and plays game music
            bgmplay.Dispose();
            Bgm bgm2 = new Bgm("/Application/Sounds/RomanticFall.mp3");

            bgmplay2      = bgm2.CreatePlayer();
            bgmplay2.Loop = true;
            bgmplay2.Play();
            background       = new Background(graphics, backTex);
            backplanets      = new BackgroundPlanets(graphics);
            enemyTimeCounter = 0;
            weapons          = new List <Weapon> ();
            enemies          = new List <Enemy> ();
            pickups          = new List <Pickup> ();
            ebullets         = new List <EnemyBullet> ();
            p             = new Player(graphics, 100, 100, pTex);
            counter       = -1;
            currentWeapon = GameWeapons.Missles;
            enemyCounter  = enemies.Count;
            timeDelta     = 0;
            hasLaser      = false;
            hasMissle     = true;
            hasSpread     = false;
            p1            = new Pickup(graphics, powTex, gen.Next(100, 700), gen.Next(100, 500));
            pickups.Add(p1);
            p2 = new Pickup(graphics, powTex, gen.Next(100, 700), gen.Next(100, 500));
            pickups.Add(p2);
            spreadNext   = false;
            laserNext    = false;
            playerScore  = 0;
            enterName    = "";
            newHighScore = false;
        }
コード例 #2
0
        public static void UpdatePlaying()
        {
            var gamePadData = GamePad.GetData(0);

            if (p.IsAlive == true)
            {
                if ((gamePadData.ButtonsDown & GamePadButtons.R) != 0)
                {
                    HandleShooting();
                }

                //Switches Weapons
                if ((gamePadData.ButtonsDown & GamePadButtons.L) != 0)
                {
                    currentWeapon++;
                    if (currentWeapon > GameWeapons.Spread)
                    {
                        currentWeapon = GameWeapons.Missles;
                    }
                }
            }
            if ((gamePadData.ButtonsDown & GamePadButtons.Start) != 0)
            {
                currentState = GameState.Paused;
            }
            backplanets.Update();
            background.Update();
            HandleWeapons();
            HandleEnemies();
            HandleEnemyBullets();
            ShipPickupCollision();
            CheckForCollisions();



            foreach (EnemyBullet eb in ebullets)
            {
                eb.Update();
            }

            if (ShipEnemyCollision() == true)
            {
                p.IsAlive = false;
            }

            if (ShipEnemyCollision() == true || ShipEnenmyBulletCollision() == true)
            {
                currentState = GameState.Dead;
            }
            //If you press Z or Select the game will close
            if ((gamePadData.ButtonsDown & GamePadButtons.Select) != 0)
            {
                running = false;
            }

            p.Update(gamePadData);
        }
コード例 #3
0
 public void SetToss(bool isPlayerToss, GameWeapons weapon, Vector3 velocity)
 {
     gameObject.SetActive(true);
     boxCollider.enabled = isPlayerToss ? true : false;
     isBeingTossed       = isPlayerToss ? true : false;
     IsPlayerToss        = isPlayerToss;
     WeaponType          = weapon;
     SetSprite(GameManager.Instance.GetspriteForWeapon(weapon));
     rigidBody2D.velocity = velocity;
 }
コード例 #4
0
        //Depending on the selected weapon, and the weapons in the player's inventory, the corresponding weapon will be fired.
        public static void HandleShooting()
        {
            switch (currentWeapon)
            {
            case (GameWeapons.Missles):
            {
                if (hasMissle == true)
                {
                    missleSP.Volume = .35f;
                    missleSP.Play();
                    Missle m = new Missle(graphics, mTex, (p.Position + weaponOffset), p.Rotation);
                    weapons.Add(m);
                    break;
                }
                currentWeapon = GameWeapons.Lasers;
                HandleShooting();
                break;
            }

            case (GameWeapons.Lasers):
            {
                if (hasLaser == true)
                {
                    laserSP.Volume = .25f;
                    laserSP.Play();
                    Laser l = new Laser(graphics, lTex, (p.Position + weaponOffset), p.Rotation);
                    weapons.Add(l);
                    break;
                }
                currentWeapon = GameWeapons.Spread;
                HandleShooting();
                break;
            }

            case (GameWeapons.Spread):
            {
                if (hasSpread == true)
                {
                    laserSP.Volume = .25f;
                    laserSP.Play();
                    SpreadGun sp = new SpreadGun(graphics, sTex, (p.Position + weaponOffset), counter, p.Rotation);
                    weapons.Add(sp);
                    counter++;
                    if (counter > 1)
                    {
                        counter = -1;
                    }
                    break;
                }
                currentWeapon = GameWeapons.Missles;
                HandleShooting();
                break;
            }
            }
        }