예제 #1
0
        public override void OnCollisionPlayerBullet(PlayerBullet playerBullet)
        {//boss takes damage
            if (state == State.Appear || state == State.Swoon || state == State.Dying)
            {
                return;
            }

            life -= 1;

            if (life <= 0)
            {
                state = State.Dying;
            }

            if (playerBullet is MissileBullet)
            {//extra sounds and effects if hit by a missile
                Sound.Play(Sound.explosion);
                game.explosions.Add(new Explosion(playerBullet.x, playerBullet.y));
            }
        }
예제 #2
0
        public void Update()
        {
            Input.Update(); //updates inputs

            if (state == State.Title)
            {
                Sound.BGM(Sound.BGMMenu); //play menu music when returning to title screen

                if (Input.GetButtonDown(DX.PAD_INPUT_8) || Input.GetButtonDown(DX.PAD_INPUT_UP))
                {//move up
                    Sound.Play(Sound.menuMovement);
                    menuCount--;
                    if (menuCount < 0)
                    {
                        menuCount = 4;                //loop
                    }
                }
                else if (Input.GetButtonDown(DX.PAD_INPUT_5) || Input.GetButtonDown(DX.PAD_INPUT_DOWN))
                {//move down
                    Sound.Play(Sound.menuMovement);
                    menuCount++;
                    if (menuCount > 4)
                    {
                        menuCount = 0;
                    }
                }

                //Pressing Z triggers the bool which in turn activates the 'countdown'
                //once the 'countdown' counts 60 frames, activate selected option
                if (Input.GetButtonDown(DX.PAD_INPUT_1))
                {
                    Sound.Play(Sound.menuSelect);
                    optionSelected = true;
                }
                if (optionSelected)
                {
                    startCountDown++;
                }
                if (menuCount == 0 && startCountDown == 60)
                {                           //Normal mode
                    state          = State.Restart;
                    optionSelected = false; //reset bool
                    startCountDown = 0;     //reset 'countdown'
                    gameType       = GameType.Normal;
                }
                if (menuCount == 1 && startCountDown == 60)
                {//Endless mode
                    state          = State.Restart;
                    optionSelected = false;
                    startCountDown = 0;
                    gameType       = GameType.Endless;
                }
                if (menuCount == 2 && startCountDown == 60)
                {//Endless mode - HP
                    state          = State.Restart;
                    optionSelected = false;
                    startCountDown = 0;
                    gameType       = GameType.EndlessHP;
                }
                if (menuCount == 3 && startCountDown == 60)
                {//Help
                    optionSelected = false;
                    startCountDown = 0;
                    state          = State.Help;
                }
                if (menuCount == 4 && startCountDown == 60)
                {//Options
                    optionSelected = false;
                    startCountDown = 0;
                    state          = State.Options;
                }
            }

            if (state == State.Options)
            {
                if (Input.GetButtonDown(DX.PAD_INPUT_2) && option == Option.Neutral)
                {//go back to menu
                    Sound.Play(Sound.cancel);
                    state = State.Title;
                }

                //Cicle through the options
                if (option == Option.Neutral)
                {
                    if (Input.GetButtonDown(DX.PAD_INPUT_8) || Input.GetButtonDown(DX.PAD_INPUT_UP))
                    {//Up
                        Sound.Play(Sound.menuMovement);
                        optionCount--;
                        if (optionCount < 0)
                        {
                            optionCount = 2;
                        }
                    }
                    else if (Input.GetButtonDown(DX.PAD_INPUT_5) || Input.GetButtonDown(DX.PAD_INPUT_DOWN))
                    {//down
                        Sound.Play(Sound.menuMovement);
                        optionCount++;
                        if (optionCount > 2)
                        {
                            optionCount = 0;
                        }
                    }
                }

                //If music option was selected
                if (Input.GetButtonDown(DX.PAD_INPUT_1) && optionCount == 0)
                {
                    option = Option.Music;
                }
                if (option == Option.Music)
                {     //now the player can cicle through the song list
                    if (Input.GetButtonDown(DX.PAD_INPUT_2))
                    { //back out of music selection
                        Sound.Play(Sound.cancel);
                        option = Option.Neutral;
                    }
                    if (Input.GetButtonDown(DX.PAD_INPUT_8) || Input.GetButtonDown(DX.PAD_INPUT_UP))
                    {//scroll list up
                        Sound.Play(Sound.menuMovement);
                        musicCount--;
                        if (musicCount < 0)
                        {
                            musicCount = 3;
                        }
                    }
                    else if (Input.GetButtonDown(DX.PAD_INPUT_5) || Input.GetButtonDown(DX.PAD_INPUT_DOWN))
                    {//scroll list down
                        Sound.Play(Sound.menuMovement);
                        musicCount++;
                        if (musicCount > 3)
                        {
                            musicCount = 0;
                        }
                    }
                    if (Input.GetButtonDown(DX.PAD_INPUT_1))
                    {//select music that will be played during the game
                        Sound.Play(Sound.menuSelect);
                        if (musicCount == 0)
                        {
                            Sound.musicID = 0;
                        }
                        if (musicCount == 1)
                        {
                            Sound.musicID = 1;
                        }
                        if (musicCount == 2)
                        {
                            Sound.musicID = 2;
                        }
                        if (musicCount == 3)
                        {
                            Sound.musicID = 3;
                        }
                        Sound.SetMusic();
                    }
                }

                //if BGM volume option was selected
                if (Input.GetButtonDown(DX.PAD_INPUT_1) && optionCount == 1)
                {
                    option = Option.BGMVolume;
                    Sound.Play(Sound.menuSelect);
                }
                if (option == Option.BGMVolume)
                {
                    if (Input.GetButtonDown(DX.PAD_INPUT_2))
                    {//back out of BGM Volume setting
                        Sound.Play(Sound.cancel);
                        option = Option.Neutral;
                    }
                    if (Input.GetButtonDown(DX.PAD_INPUT_4) || Input.GetButtonDown(DX.PAD_INPUT_LEFT))
                    {//press left to lower the volume by 10
                        Sound.Play(Sound.menuMovement);
                        Sound.BGMVolume -= 10;
                        if (Sound.BGMVolume < 0)
                        {
                            Sound.BGMVolume = 0;
                        }
                        Sound.SetVolume(); //updates the sounds so they actually change volume
                    }
                    if (Input.GetButtonDown(DX.PAD_INPUT_6) || Input.GetButtonDown(DX.PAD_INPUT_RIGHT))
                    {//press right to increase the volume by 10
                        Sound.Play(Sound.menuMovement);
                        Sound.BGMVolume += 10;
                        if (Sound.BGMVolume > 200)
                        {
                            Sound.BGMVolume = 200;
                        }
                        Sound.SetVolume();
                    }
                }

                //if SE volume option was selected
                if (Input.GetButtonDown(DX.PAD_INPUT_1) && optionCount == 2)
                {
                    option = Option.SEVolume;
                    Sound.Play(Sound.menuSelect);
                }
                if (option == Option.SEVolume)
                {
                    if (Input.GetButtonDown(DX.PAD_INPUT_2))
                    {//back out of music selection
                        Sound.Play(Sound.cancel);
                        option = Option.Neutral;
                    }
                    if (Input.GetButtonDown(DX.PAD_INPUT_4) || Input.GetButtonDown(DX.PAD_INPUT_LEFT))
                    {//press left to lower the volume by 10
                        Sound.Play(Sound.menuMovement);
                        Sound.SEVolume -= 10;
                        if (Sound.SEVolume < 0)
                        {
                            Sound.SEVolume = 0;
                        }
                        Sound.SetVolume();
                    }
                    if (Input.GetButtonDown(DX.PAD_INPUT_6) || Input.GetButtonDown(DX.PAD_INPUT_RIGHT))
                    {//press right to increase the volume by 10
                        Sound.Play(Sound.menuMovement);
                        Sound.SEVolume += 10;
                        if (Sound.SEVolume > 200)
                        {
                            Sound.SEVolume = 200;
                        }
                        Sound.SetVolume();
                    }
                }
            }

            if (state == State.Help)
            {
                if (Input.GetButtonDown(DX.PAD_INPUT_2))
                {
                    Sound.Play(Sound.cancel);
                    state = State.Title;
                }
            }

            if (state == State.Restart)
            {
                Restart();
            }

            if (state == State.Pause)
            {//Paused state, press Q again to un-pause
                if (Input.GetButtonDown(DX.PAD_INPUT_7))
                {
                    state = State.Game;
                }
                pause = true;
            }

            if (state == State.Game || state == State.End || state == State.Clear)
            {
                Sound.SetMusic(); //plays set music

                if (gameType == GameType.Normal)
                {
                    map.Scroll(scrollSpeed);
                    if (map.enemyCount == 0 && enemies.Count == 0)
                    {
                        state = State.Clear;
                    }
                }

                if (gameType == GameType.Endless || gameType == GameType.EndlessHP)
                {
                    wave.Update();
                }

                if (!player.isDead)
                {
                    mouse.Update();
                    player.Update();
                }
                else
                {
                    state = State.End;
                }

                foreach (PlayerBullet b in playerBullets)
                {
                    b.Update();
                }

                foreach (Enemy e in enemies)
                {
                    e.Update();
                }

                foreach (EnemyBullet b in enemyBullets)
                {
                    b.Update();
                }

                foreach (Item i in items)
                {
                    i.Update();
                }

                foreach (EnemyBullet enemyBullet in enemyBullets)
                {//player takes damage from enemy bullets
                    if (player.isDead)
                    {
                        break;
                    }

                    if (enemyBullet.isDead)
                    {
                        continue;
                    }

                    if (MyMath.SphereSphereIntersection(
                            player.x, player.y, player.collisionRadius,
                            enemyBullet.x, enemyBullet.y, enemyBullet.collisionRadius))
                    {
                        player.OnCollisionEnemyBullet(enemyBullet);
                    }
                }

                foreach (PlayerBullet playerBullet in playerBullets)
                {
                    if (playerBullet.isDead)
                    {
                        continue;
                    }

                    //for missiles
                    if (playerBullet is MissileBullet)
                    {
                        MissileBullet missile          = (MissileBullet)playerBullet;
                        float         shortestDistance = float.MaxValue;
                        foreach (Enemy enemy in enemies)
                        {//missile looks for closest enemy
                            if (MyMath.DistanceBetweenTwoPoints(missile.x, missile.y, enemy.x, enemy.y) < shortestDistance)
                            {
                                shortestDistance = MyMath.DistanceBetweenTwoPoints(missile.x, missile.y, enemy.x, enemy.y);
                                closeEnemyX      = enemy.x;
                                closeEnemyY      = enemy.y;
                            }
                            missile.AngleToEnemy(closeEnemyX, closeEnemyY);
                        }
                    }

                    //enemies take damage if hit by player bullet
                    foreach (Enemy enemy in enemies)
                    {
                        if (enemy.isDead)
                        {
                            continue;
                        }

                        if (enemy is Boss2)
                        {//if boss2 is in normal state (or when it is teleporting) it can't be hit by bullets - this way only the turrents can be hit
                            Boss2 boss = (Boss2)enemy;
                            if (boss.state == Boss2.State.Normal || boss.state == Boss2.State.Invincible)
                            {
                                continue;
                            }
                        }

                        if (MyMath.SphereSphereIntersection(
                                playerBullet.x, playerBullet.y, playerBullet.collisionRadius,
                                enemy.x, enemy.y, enemy.collisionRadius))
                        {
                            enemy.OnCollisionPlayerBullet(playerBullet);
                            playerBullet.OnCollisionEnemy(enemy);

                            if (playerBullet.isDead)
                            {
                                break;
                            }
                        }
                    }
                }

                foreach (Enemy enemy in enemies)
                {
                    if (player.isDead)
                    {
                        break;
                    }

                    if (enemy.isDead)
                    {
                        continue;
                    }

                    if (enemy is Boss2)
                    {//can't hurt player when boss is teleporting
                        Boss2 boss = (Boss2)enemy;
                        if (boss.state == Boss2.State.Invincible)
                        {
                            continue;
                        }
                    }

                    if (MyMath.SphereSphereIntersection(
                            player.x, player.y, player.collisionRadius,
                            enemy.x, enemy.y, enemy.collisionRadius))
                    {
                        player.OnCollisionEnemy(enemy);
                        enemy.OnCollisionPlayer();
                    }

                    enemy.OutOfBoundsKillFlag(); //enemies are removed if they are outside the boundaries for too long
                }

                //this decides item drop chance and score
                foreach (Enemy enemy in enemies)
                {
                    if (enemy.isDead)
                    {
                        //items have a 1 in 10 chance to drop something
                        int itemDrop = MyRandom.Range(0, 10);
                        if (itemDrop == 0)
                        {
                            items.Add(new HealthItem(enemy));
                        }
                        if (itemDrop == 1)
                        {
                            items.Add(new StrightBulletPowerUpItem(enemy));
                        }
                        if (itemDrop == 2)
                        {
                            items.Add(new SpreadBulletPowerUpItem(enemy));
                        }
                        if (itemDrop == 3)
                        {
                            items.Add(new MissileBulletPowerUpItem(enemy));
                        }

                        //most enemies are worth 10 points, 1 type of enemy is worth 20, and the boss is worth 100
                        //Note - points for mines and boss turrents are calculated in Zako4 and Boss2 respectivly
                        if (enemy is Zako0 || enemy is Zako1 || enemy is Zako2 || enemy is Zako3)
                        {
                            score += 10;
                        }
                        if (enemy is Zako4)
                        {
                            score += 20;
                        }
                        if (enemy is Boss2)
                        {
                            score += 100;
                        }
                    }
                }

                //updates items and detects if the player picks them up
                foreach (Item item in items)
                {
                    if (player.isDead)
                    {
                        break;
                    }

                    if (item.isDead)
                    {
                        continue;
                    }

                    if (MyMath.SphereSphereIntersection(
                            player.x, player.y, player.collisionRadius,
                            item.x, item.y, item.collisionRadius))
                    {
                        player.OnCollisionItem(item);
                        item.OnCollisionPlayer(player);
                    }
                }

                foreach (Explosion e in explosions)
                {
                    e.Update();
                }

                //removes all assets that are no longer used
                playerBullets.RemoveAll(pb => pb.isDead);
                enemies.RemoveAll(e => e.isDead);
                enemyBullets.RemoveAll(eb => eb.isDead);
                explosions.RemoveAll(e => e.isDead);
                items.RemoveAll(i => i.isDead);

                if (state == State.End || state == State.Clear)
                {//only save score if the player finishes or dies on a stage
                    //if current score is higher then max score, change max score to the current score
                    if (gameType == GameType.Normal && score > maxScore0)
                    {
                        maxScore0 = score;
                    }
                    if (gameType == GameType.Endless && score > maxScore1)
                    {
                        maxScore1 = score;
                    }
                    if (gameType == GameType.EndlessHP && score > maxScore2)
                    {
                        maxScore2 = score;
                    }
                }

                //player can reset or go back to the title screen at any time
                if (Input.GetButtonDown(DX.PAD_INPUT_1))
                {
                    state = State.Restart;
                }
                if (Input.GetButtonDown(DX.PAD_INPUT_2))
                {
                    state = State.Title;
                }

                //Press Q to pause
                if (Input.GetButtonDown(DX.PAD_INPUT_7) && pause == false)
                {
                    state = State.Pause;
                }
                if (pause == true)
                {
                    pause = false;
                }
            }
        }
예제 #3
0
 public Explosion(float x, float y)
 {
     this.x = x;
     this.y = y;
     Sound.Play(Sound.explosion);
 }
예제 #4
0
 public virtual void OnCollisionPlayer(Player player)
 {
     Sound.Play(Sound.powerup);
     isDead = true;
 }