Example #1
0
static void
trigger_game_over(void)
{
	fade_music();
	initialize_stats_table(&game_stat_counters);
	set_inner_state(IS_GAME_OVER);
}
Example #2
0
void Game::update(float dt) {

    switch(current_mode) {
    case MODE_READY:
        fade_music(dt);
        if(start_pressed()) {
            current_mode = MODE_GAME;
            initialize();
        }
        break;
    case MODE_GAME:
    {
        if(life <= 0) {

            // Delete all enemies.
            for(auto it = enemies.begin(); it != enemies.end(); ) {
                delete *it;
                it = enemies.erase(it);
            }

            //delete music;
            current_mode = MODE_HIGHSCORE;

            highscore->add_entry(score);

            score_text.set_alignment(Text::RIGHT_ALIGNED);
            score_text.set_number(score);
            score_text.set_color(highscore_color);
            score_text.set_scale(30.0 * hud_scale.x);
            score_text.set_position(glm::vec3(glm::vec2(150.f, 270.f) * hud_scale, 0.f));

            int i = 0;
            bool selected = false;
            for(int e : highscore->get_entries()) {
                if(e > 0) {
                    if(!selected && e == score) {
                        highscore_entries[i].set_color(hud_font_color);
                    } else {
                        highscore_entries[i].set_color(highscore_color);
                    }
                    highscore_entries[i].set_number(e);
                } else {
                    highscore_entries[i].set_text("");
                }
                ++i;
            }
#ifdef WIN32
            if(useWII) WII->setRumble(false);
#endif

            return;
        }

        // Change wind direction
        wind_velocity = glm::rotateY(wind_velocity, (float)(0.8f + sin(global_time)));
        update_wind_velocity();

        //input.update_object(camera, dt);

        bool buttonFirePressed = (input.has_changed(Input::ACTION_0, 0.2f) && input.current_value(Input::ACTION_0) > 0.9f);
        bool buttonSwapForwPressed = (input.has_changed(Input::ACTION_3, 0.2f) && input.current_value(Input::ACTION_3) > 0.9f);
        bool buttonSwapBackPressed = (input.has_changed(Input::ACTION_2, 0.2f) && input.current_value(Input::ACTION_2) > 0.9f);
        bool buttonBreakPressed = (input.has_changed(Input::ACTION_1, 0.2f) && input.current_value(Input::ACTION_1) > 0.9f);
        bool buttonMutePressed = false;

#ifdef WIN32
        if (useWII) {
            float pitch = WII->getPitch(), roll = -1 * WII->getRoll(); // [-90, 90].
            pitch = glm::clamp(pitch - 10, -90.0f, 90.0f);
            //pitch = glm::clamp(-10 + 90 * glm::sign(pitch) * glm::pow(glm::abs(1.0f * pitch / 90), 1.0f), -90.0f, 90.0f);
            //roll = glm::clamp(90 * glm::sign(roll) * glm::pow(glm::abs(1.0f * roll / 90), 1.0f), -90.0f, 90.0f);
            player.set_canon_pitch(pitch);
            player.set_canon_yaw(roll);

            buttonFirePressed = WII->getButtonAPressed();
            buttonSwapBackPressed = WII->getArrowLeftPressed();

            buttonSwapForwPressed = WII->getArrowRightPressed();
            buttonBreakPressed = WII->getButtonBDown();
            //buttonMutePressed = WII->getArrowUpPressed();
            const bool wiiSwapAB = false;
            if (wiiSwapAB) std::swap(buttonFirePressed, buttonBreakPressed);
        } else {
#endif
            player.set_canon_pitch(input.current_value(Input::MOVE_Y) * 90.f);
            player.set_canon_yaw(input.current_value(Input::MOVE_X) * 90.f);
#ifdef WIN32
        }
#endif
        if (buttonFirePressed) {
            shoot();

#ifdef WIN32
            if(useWII) WII->setRumble(true);
        } else {
            if(useWII) WII->setRumble(false);
#endif

        }

        if(buttonMutePressed) {
            music_mute = !music_mute;
            if(music_mute) {
                music ->stop();
            }
            //change_particles(-1);

        }

        if (buttonSwapForwPressed) {
            change_particles(1);
        }
        if (buttonSwapBackPressed) {
            change_particles(-1);
        }

        if( buttonBreakPressed && global_time - last_break > break_cooldown)
            last_break = global_time;

        float speed = current_movement_speed;
        if (global_time - last_break < break_duration)
            speed *= break_factor;



        player.update_position(path, player.path_position() + speed * dt);

        update_camera();

        update_enemies(dt);

        smoke->update(dt);
        attack_particles->update(dt, enemies, this);

        dust->config.spawn_position = glm::vec4(path->at(player.path_position() + dust_spawn_ahead) - half_dust_spawn_area, 1.f);
        dust->update_config();
        dust->update(dt);

        explosions->update(dt);

        life_text.set_number(life);
        score_text.set_number(score);

        dust->config.spawn_position = glm::vec4(path->at(player.path_position() + dust_spawn_ahead) - half_dust_spawn_area, 1.f);
        dust->update_config();
        dust->update(dt);

        explosions->update(dt);

        active_sounds.remove_if([](const Sound * s) {
            if(s->is_done()) {
                delete s;
                return true;
            };
            return false;
        });
        // Really ugly way of looping the music:
        if(music != nullptr && music->is_done() && !music_mute)
        {
            delete music;
            music = new Sound("ecstacy.mp3", 5);
            music->play();
        }
    }
    break;
    case MODE_HIGHSCORE:
        fade_music(dt);
        if(start_pressed()) {
            current_mode = MODE_READY;
        }
        break;
    }

    input.update(dt);
}