Ejemplo n.º 1
0
        protected override void Update(GameTime gameTime)
        {
            kbs = Keyboard.GetState();
            gps = GamePad.GetState(PlayerIndex.One);

            if(gps.IsConnected) {
                if(gps.DPad.Down == ButtonState.Pressed && !(ogps.DPad.Down == ButtonState.Pressed)) {
                    if(EffectVolume > 0f) { EffectVolume -= 0.1f; if(EffectVolume<0) EffectVolume=0f;} }
                if(gps.DPad.Up == ButtonState.Pressed && !(ogps.DPad.Up == ButtonState.Pressed)) {
                    if(EffectVolume < 1f) { EffectVolume += 0.1f; if(EffectVolume>1) EffectVolume=1f; } }
                if(gps.DPad.Left == ButtonState.Pressed && !(ogps.DPad.Left == ButtonState.Pressed)) {
                    if(MusicVolume > 0f) { MusicVolume -= 0.1f; if(MusicVolume<0) MusicVolume=0f; } }
                if(gps.DPad.Right == ButtonState.Pressed && !(ogps.DPad.Right == ButtonState.Pressed)) {
                    if(MusicVolume < 1f) { MusicVolume += 0.1f; if(MusicVolume>1) MusicVolume=1f; } }
            }

            if(kbs.IsKeyDown(Keys.NumPad2) && !(okbs.IsKeyDown(Keys.NumPad2))){
                if(EffectVolume > 0f) { EffectVolume -= 0.1f; if(EffectVolume<0) EffectVolume=0f;} }
            if(kbs.IsKeyDown(Keys.NumPad8) && !(okbs.IsKeyDown(Keys.NumPad8))){
                if(EffectVolume < 1f) { EffectVolume += 0.1f; if(EffectVolume>1) EffectVolume=1f; } }
            if(kbs.IsKeyDown(Keys.NumPad4) && !(okbs.IsKeyDown(Keys.NumPad4))){
                if(MusicVolume > 0f) { MusicVolume -= 0.1f; if(MusicVolume<0) MusicVolume=0f; } }
            if(kbs.IsKeyDown(Keys.NumPad6) && !(okbs.IsKeyDown(Keys.NumPad6))){
                if(MusicVolume < 1f) { MusicVolume += 0.1f; if(MusicVolume>1) MusicVolume=1f; } }

            if(fadein) {
                blackFadeTimer-=2; if(blackFadeTimer<=0) { blackFadeTimer=0; fadein = false;}}
            if(fade) blackFadeTimer++;
            if(blackFadeTimer<=blackFadeTimerFreq) {
                music.Volume = MusicVolume*((float)blackFadeTimerFreq-blackFadeTimer)/blackFadeTimerFreq;
            }

            switch(GameState) {
                case GameStates.MainMenu:
                    if(!(music.State == SoundState.Playing)) {
                        music.Play();
                    }
                    if(gps.Buttons.Back == ButtonState.Pressed && !(ogps.Buttons.Back == ButtonState.Pressed) || (kbs.IsKeyDown(Keys.Escape) && !okbs.IsKeyDown(Keys.Escape))) {
                        sound_shieldbreak.Play(EffectVolume,0f,0f);
                        fade = true;
                        blackFadeTimer = 0;
                        quitting = true;
                    }

                    if(blackFadeTimer >= blackFadeTimerFreq+(quitting?30:0) && fade) {
                        if(quitting) {
                            this.Exit();
                        } else {
                            GameState = GameStates.Game;
                            fade = false;
                            fadein = true;
                        }
                    }

                    menu_switchTimer--;
                    if(gps.IsConnected) {
                        if(gps.DPad.Up == ButtonState.Pressed && !(ogps.DPad.Up == ButtonState.Pressed)) {
                            for(int i = 1;i<10;i++) { secret[i-1] = secret[i]; }
                            secret[9] = 'u';
                        }
                        if(gps.DPad.Down == ButtonState.Pressed && !(ogps.DPad.Down == ButtonState.Pressed)) {
                            for(int i = 1;i<10;i++) { secret[i-1] = secret[i]; }
                            secret[9] = 'd';
                        }
                        if(gps.DPad.Left == ButtonState.Pressed && !(ogps.DPad.Left == ButtonState.Pressed)) {
                            for(int i = 1;i<10;i++) { secret[i-1] = secret[i]; }
                            secret[9] = 'l';
                        }
                        if(gps.DPad.Right == ButtonState.Pressed && !(ogps.DPad.Right == ButtonState.Pressed)) {
                            for(int i = 1;i<10;i++) { secret[i-1] = secret[i]; }
                            secret[9] = 'r';
                        }
                        if(gps.Buttons.A == ButtonState.Pressed && !(ogps.Buttons.A == ButtonState.Pressed)) {
                            for(int i = 1;i<10;i++) { secret[i-1] = secret[i]; }
                            secret[9] = 'a';
                        }
                        if(gps.Buttons.B == ButtonState.Pressed && !(ogps.Buttons.B == ButtonState.Pressed)) {
                            for(int i = 1;i<10;i++) { secret[i-1] = secret[i]; }
                            secret[9] = 'b';
                        }
                        if(gps.Buttons.Start == ButtonState.Pressed && !(ogps.Buttons.Start == ButtonState.Pressed)) {
                            for(int i = 1;i<10;i++) { secret[i-1] = secret[i]; }
                            secret[9] = 's';
                        }
                    }
                        if(
                            (gps.ThumbSticks.Left.Y > 0.5&&menu_switchTimer <= 0) ||
                            (kbs.IsKeyDown(Keys.Up)&&!(okbs.IsKeyDown(Keys.Up)))) {
                            menu_choice += 3;
                            menu_choice = menu_choice % 4;
                            menu_switchTimer = menu_switchTimerFreq;
                            sound_boop.Play(EffectVolume,0f,0f);
                        }
                        if(
                            (gps.ThumbSticks.Left.Y < -0.5&&menu_switchTimer <= 0) ||
                            (kbs.IsKeyDown(Keys.Down)&&!(okbs.IsKeyDown(Keys.Down)))) {
                            menu_choice += 1;
                            menu_choice = menu_choice % 4;
                            menu_switchTimer = menu_switchTimerFreq;
                            sound_boop.Play(EffectVolume,0f,0f);
                        }

                        if(!(ogps.Buttons.A == ButtonState.Pressed)) {
                            if(gps.Buttons.A == ButtonState.Pressed || (kbs.IsKeyDown(Keys.Z)&&!(okbs.IsKeyDown(Keys.Z)))) {
                                sound_hit.Play(EffectVolume,0f,0f);

                                if(menu_choices[menu_choice] == "Start Game") {
                                    if(new string(secret) == "uuddlrlrba") {
                                        player.drunken = !player.drunken;
                                        sound_konami.Play(EffectVolume,0f,0f);
                                    }
                                    fade = true;
                                    blackFadeTimer = 0;
                                    restart();
                                }
                                else if(menu_choices[menu_choice] == "Help") {
                                    GameState = GameStates.HelpMenu;
                                }
                                else if(menu_choices[menu_choice] == "Options") {
                                    GameState = GameStates.OptionsMenu;
                                    switch(Difficulty) {
                                        case Difficulties.Recruit:
                                            menu_choice = 0; break;
                                        case Difficulties.Veteran:
                                            menu_choice = 1; break;
                                        case Difficulties.General:
                                            menu_choice = 2; break;
                                        case Difficulties.SpaceAce:
                                            menu_choice = 3; break;
                                    }
                                }
                                else if(menu_choices[menu_choice] == "Quit") {
                                    quitting = true;
                                    fade = true;
                                    blackFadeTimer = 0;
                                    sound_shieldbreak.Play(EffectVolume,0f,0f);
                                }
                            }
                        }
                    break;
                case GameStates.HelpMenu:
                    if(gps.Buttons.A == ButtonState.Pressed && !(ogps.Buttons.A == ButtonState.Pressed) ||
                        gps.Buttons.B == ButtonState.Pressed && !(ogps.Buttons.B == ButtonState.Pressed) ||
                        (kbs.IsKeyDown(Keys.X)&&!(okbs.IsKeyDown(Keys.X))) ||
                        (kbs.IsKeyDown(Keys.Z)&&!(okbs.IsKeyDown(Keys.Z))) ||
                        (kbs.IsKeyDown(Keys.Escape)&&!(okbs.IsKeyDown(Keys.Escape)))
                        ) {
                        GameState = GameStates.MainMenu;
                        sound_hit.Play(EffectVolume,0f,0f);
                    }
                    break;
                case GameStates.OptionsMenu:
                    if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                    gps.Buttons.B == ButtonState.Pressed ||
                    (kbs.IsKeyDown(Keys.Escape)&&!(okbs.IsKeyDown(Keys.Escape))) ||
                    (kbs.IsKeyDown(Keys.X)&&!(okbs.IsKeyDown(Keys.X)))
                        ){
                        GameState = GameStates.MainMenu;
                        menu_choice = 2;
                        sound_hit.Play(EffectVolume,0f,0f);
                    }

                    menu_switchTimer--;
                    if(
                        (gps.ThumbSticks.Left.Y > 0.5&&menu_switchTimer <= 0) ||
                        (kbs.IsKeyDown(Keys.Up)&&!(okbs.IsKeyDown(Keys.Up)))) {
                        menu_choice += 3;
                        menu_choice = menu_choice % 4;
                        menu_switchTimer = menu_switchTimerFreq;
                        sound_boop.Play(EffectVolume,0f,0f);
                    }

                    if(
                        (gps.ThumbSticks.Left.Y < -0.5&&menu_switchTimer <= 0) ||
                        (kbs.IsKeyDown(Keys.Down)&&!(okbs.IsKeyDown(Keys.Down)))) {
                        menu_choice += 1;
                        menu_choice = menu_choice % 4;
                        menu_switchTimer = menu_switchTimerFreq;
                        sound_boop.Play(EffectVolume,0f,0f);
                    }

                    if(!(ogps.Buttons.A == ButtonState.Pressed)) {
                        if(gps.Buttons.A == ButtonState.Pressed || (kbs.IsKeyDown(Keys.Z)&&!(okbs.IsKeyDown(Keys.Z)))) {
                            sound_hit.Play(EffectVolume,0f,0f);
                            switch(menu_choice) {
                                case 0:
                                    Difficulty = Difficulties.Recruit;
                                    applyDifficulty();
                                    break;
                                case 1:
                                    Difficulty = Difficulties.Veteran;
                                    applyDifficulty();
                                    break;
                                case 2:
                                    Difficulty = Difficulties.General;
                                    applyDifficulty();
                                    break;
                                case 3:
                                    Difficulty = Difficulties.SpaceAce;
                                    applyDifficulty();
                                    break;
                            }
                            menu_choice = 0;
                            GameState = GameStates.MainMenu;
                        }
                    }
                    break;
                case GameStates.Game:
                    if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || kbs.IsKeyDown(Keys.Escape)) {
                        fade = true;
                        blackFadeTimer = 0;
                    }

                    if(fadein == false) {if(blackFadeTimer >= blackFadeTimerFreq+10) {
                            GameState = GameStates.MainMenu;
                            fade = false;
                            fadein = true;
                        }
                    }

                    if(blackFadeTimer >= blackFadeTimerFreq+30 && fade) {
                        this.Exit();
                    }

                    player.Update();
                    backgroundScroll += 3;
                    if(backgroundScroll >= roomSize.X) {
                        backgroundScroll = 0;
                    }

                    int difficultyMultiplier = 1;
                    switch(Difficulty) {
                        case Difficulties.Recruit: difficultyMultiplier = 1; break;
                        case Difficulties.Veteran: difficultyMultiplier = 2; break;
                        case Difficulties.General: difficultyMultiplier = 3; break;
                        case Difficulties.SpaceAce: difficultyMultiplier = 5; break;
                    }
                    if(!player.dead) {
                        multiplier = (10+killsSinceLeak*2)*difficultyMultiplier;
                    }

                    for(int i = 0;i<bullets.Count;i++) {
                        Bullet b = bullets[i];
                        b.position += b.velocity;
                        if((b.position.X > roomSize.X && b.velocity.X > 0) || (b.position.X < 0 && b.velocity.X < 0)) {
                            bullets.RemoveAt(i);
                        }
                    }

                    if(blackFadeTimer<=0) enemyTimer--;
                    if(enemyTimer <= 0) {
                        enemyTimer = enemyTimerFreq;
                        float angle = 325+(float)random.NextDouble()*135;
                        int r = 45;
                        angle = 180-r+(float)random.NextDouble()*(r*2);
                        Enemy e = new Enemy(this,
                            new Vector2(roomSize.X+60, (roomSize.Y/8)+(float)(random.NextDouble()*roomSize.Y)*((float)6/8)),
                            new Vector2(
                                (float)Math.Cos(MathHelper.ToRadians(angle)),
                                (float)Math.Sin(MathHelper.ToRadians(angle)))*3);
                        e.spriteSheet = texture_enemy;
                        enemies.Add(e);
                    }
                    for(int i = 0;i<enemies.Count;i++) {
                        Enemy e = enemies[i];
                        e.Update();
                    }

                    if(asteroidTimerFreq != -1) {
                        if(blackFadeTimer<=0) asteroidTimer--;
                        if(asteroidTimer <= 0) {
                            asteroidTimer = asteroidTimerFreq;
                            Asteroid a = new Asteroid(this,
                                new Vector2(roomSize.X+60, roomSize.Y/8+(float)(random.NextDouble()*roomSize.Y)*((float)6/8)),
                                new Vector2(-4, 0), new Vector2(16,16));
                            a.texture = texture_asteroid;
                            asteroids.Add(a);
                        }
                        for(int i = 0;i<asteroids.Count;i++) {
                            Asteroid a = asteroids[i];
                            a.Update();
                        }
                    }

                    for(int i = 0;i<particles.Count;i++) {
                        Particle p = particles[i];
                        p.Update();
                    }

                    if(shake > 0) shake-=1;

                    break;
            }

            okbs = kbs;
            ogps = gps;

            base.Update(gameTime);
        }
Ejemplo n.º 2
0
        public void Update()
        {
            time++;
            if (super.gps.IsConnected || (super.kbs.IsKeyDown(Keys.Enter) && !super.okbs.IsKeyDown(Keys.Enter)))
            {
                if (super.gps.Buttons.Start == ButtonState.Pressed || super.kbs.IsKeyDown(Keys.Enter))
                {
                    super.restart();
                }
            }
            if (dead)
            {
                return;
            }
            //logic
            bulletTimer -= 1;
            if (bulletTimer <= 0)
            {
                bullets     = bulletsMax;
                bulletTimer = bulletTimerFreq;
            }

            if (rollTimer > 0)
            {
                rollTimer -= 1;
            }
            if (rollTimer <= 0 && rolling)
            {
                rollframe += rolldir;
                if (rolldir == -1 && rollframe == 1)
                {
                    rolling   = false;
                    rollframe = 1;
                }
                if (rolldir == 1 && rollframe == 5)
                {
                    rolling   = false;
                    rollframe = 1;
                }
                rollTimer = rollTimerFreq;
            }

            for (int i = 0; i < super.bullets.Count; i++)
            {
                Bullet b = super.bullets[i];
                if (b.playerBullet)
                {
                    continue;
                }
                if (!(
                        position.X - size.X / 2 > b.position.X + b.size.X / 2 ||
                        position.X + size.X / 2 < b.position.X - b.size.X / 2 ||
                        position.Y - size.Y / 2 > b.position.Y + b.size.Y / 2 ||
                        position.Y + size.Y / 2 < b.position.Y - b.size.Y / 2))
                {
                    if (!rolling)
                    {
                        hit();
                        super.bullets.Remove(b);
                    }
                    else
                    {
                        super.score += (int)(graceScore * super.multiplier);
                    }
                }
            }

            for (int i = 0; i < super.enemies.Count; i++)
            {
                Enemy e = super.enemies[i];
                if (!(
                        position.X - size.X / 2 > e.position.X + e.size.X / 2 ||
                        position.X + size.X / 2 < e.position.X - e.size.X / 2 ||
                        position.Y - size.Y / 2 > e.position.Y + e.size.Y / 2 ||
                        position.Y + size.Y / 2 < e.position.Y - e.size.Y / 2))
                {
                    if (!rolling)
                    {
                        hit();
                        e.die();
                    }
                    else
                    {
                        super.score += (int)(graceScore * super.multiplier);
                    }
                }
            }

            for (int i = 0; i < super.asteroids.Count; i++)
            {
                Asteroid a = super.asteroids[i];
                if (!(
                        position.X - size.X / 2 > a.position.X + a.size.X / 2 ||
                        position.X + size.X / 2 < a.position.X - a.size.X / 2 ||
                        position.Y - size.Y / 2 > a.position.Y + a.size.Y / 2 ||
                        position.Y + size.Y / 2 < a.position.Y - a.size.Y / 2))
                {
                    if (!rolling)
                    {
                        hit();
                        super.asteroids.Remove(a);
                    }
                    else
                    {
                        super.score += (int)(graceScore * super.multiplier);
                    }
                }
            }


            //input
            Vector2 velocity = Vector2.Zero;

            if (super.gps.IsConnected)
            {
                velocity = new Vector2(
                    super.gps.ThumbSticks.Left.X * speed * (rolling?1.5f:1),
                    -super.gps.ThumbSticks.Left.Y * speed * (rolling?1.5f:1));
            }

            if (super.kbs.IsKeyDown(Keys.Down))
            {
                velocity = new Vector2(0, speed * (rolling?1.5f:1));
            }
            if (super.kbs.IsKeyDown(Keys.Up))
            {
                velocity = new Vector2(0, -speed * (rolling?1.5f:1));
            }
            if (super.kbs.IsKeyDown(Keys.Left))
            {
                velocity = new Vector2(-speed * (rolling?1.5f:1), 0);
            }
            if (super.kbs.IsKeyDown(Keys.Right))
            {
                velocity = new Vector2(speed * (rolling?1.5f:1), 0);
            }

            position += (drunken?-1:1) * velocity;

            if (position.X > super.roomSize.X || position.X < 0)
            {
                position.X -= (drunken?-1:1) * velocity.X;
            }
            if (position.Y > super.roomSize.Y || position.Y < 0)
            {
                position.Y -= (drunken?-1:1) * velocity.Y;
            }

            for (int i = 0; i < 8; i++)
            {
                Particle p = new Particle(
                    super, 4, position - new Vector2(4, 0), -velocity - new Vector2(1, 1) + new Vector2((float)super.random.NextDouble(), (float)super.random.NextDouble()), new Vector2(2, 2));
                p.color = i > 4?new Color(1f, 0f, 0f):new Color(1f, 1f, 0f);
                super.particles.Add(p);
            }

            if (super.gps.IsConnected || super.kbs.IsKeyDown(Keys.Z))
            {
                if (super.gps.Buttons.A == ButtonState.Pressed || super.kbs.IsKeyDown(Keys.Z))
                {
                    if (bullets > 0 && !rolling)
                    {
                        Bullet b = new Bullet(super, position, new Vector2(8, 0), new Vector2(8, 8));
                        b.texture      = super.texture_bullet1;
                        b.playerBullet = true;
                        super.bullets.Add(b);
                        bullets -= 1;
                        float pitch = (float)Math.Sin(MathHelper.ToRadians(5f * 60 * (time % 60)));
                        super.sound_shot.Play(1.0f, pitch, 0f);
                    }
                }
            }

            if (super.gps.IsConnected || super.kbs.IsKeyDown(Keys.X))
            {
                if ((super.gps.Buttons.B == ButtonState.Pressed || super.kbs.IsKeyDown(Keys.X)) && !rolling)
                {
                    if (Math.Abs(super.gps.ThumbSticks.Left.Y) > 0.4 || super.kbs.IsKeyDown(Keys.X))
                    {
                        rolldir   = Math.Sign(super.gps.ThumbSticks.Left.Y) == -1?(short)1:(short)-1;
                        rollframe = rolldir == -1?4:2;
                        rollTimer = rollTimerFreq;
                        rolling   = true;
                        super.sound_roll.Play(super.EffectVolume, 0f, 0f);
                    }
                }
            }
        }