Esempio n. 1
0
void ScreenPlay::Input(ALLEGRO_EVENT &event, float &xscale, float &yscale)
{
    int hlp = 0;

    if(couldnot_load_savefile == true)
    {
        if(buttons[OK]->Input(event, xscale, yscale) == 2)
        {
            buttons[OK]->unclick();
            buttons[OK]->Active(false);
            buttons[OK]->Print_active(false);
            couldnot_load_savefile = false;
            scan_save_files();
        }
        return;
    }

    if(is_any_button_clicked() == false)
    {
        scba->Input(event, xscale, yscale);

        for(int a = 0;a < (int)buttons.size();a++)
        {
            buttons[a]->Input(event, xscale, yscale);
        }
    }

    if(buttons[BACK]->is_button_clicked() == true)
    {
        but->unclick();
    }
    else if(buttons[NEWGAME]->is_button_clicked() == true)
    {
        //nasty and not 100% secure
        std::mt19937 generator(std::chrono::system_clock::now().time_since_epoch().count());
        std::uniform_int_distribution<long> distribution(0,9999999);
        time_t tt;
        time(&tt);
        struct tm *timeseed;
        timeseed = localtime(&tt);
        char bff[20] = {0};

        strftime(bff,20, "%S%M%H%e%m%Y",timeseed);
        std::string s2 = "saves/";
        s2 += bff;
        s2 += std::to_string(distribution(generator)) + ".sav";

        char bff2[20] = {0};
        strftime(bff2,20, "%D %X",timeseed);
        std::string s = bff2;

        global::save->Create( s2,"Save " + s );
        global::save->Save();
        but->unclick();
        global::play = true;
    }
    else if( (hlp = scba->What_button_is_clicked()) != 999)
    {
        if(global::save->Load(savefiles[hlp]) == false)
        {
            scba->buttons[hlp]->unclick();
            couldnot_load_savefile = true;
            buttons[OK]->Active(true);
            buttons[OK]->Print_active(true);

            return;
        }
        but->unclick();
        global::play = true;
    }


    return;
}
Esempio n. 2
0
void ScreenMain::Input(ALLEGRO_EVENT &event, float &xscale, float &yscale)
{
    if(global::play == true)
    {
        if(SCGame == nullptr)
        {
            SCGame = new ScreenGame();
        }

        SCGame->Input(event, xscale, yscale);

        return;
    }
    else
    {
        if(SCGame != nullptr)
        {
            delete SCGame;
        }
    }

    if(is_any_button_clicked() == false)
    {
        if(SCAbout != nullptr)
        {
            delete SCAbout;
            SCAbout = nullptr;
        }
        if(SCPlay != nullptr)
        {
            delete SCPlay;
            SCPlay = nullptr;
        }

        Musicb->Input(event, xscale, yscale);
        if(Musicb->is_button_clicked() == true)
        {
            Musicb->unclick();
            global::audio = (global::audio == true ? global::audio = false : global::audio = true);

            if(global::audio == true)
            {
                al_destroy_bitmap(Musicb->bmp);
                Musicb->bmp = al_load_bitmap(MusicON);
            }
            else
            {
                al_destroy_bitmap(Musicb->bmp);
                Musicb->bmp = al_load_bitmap(MusicOFF);
            }
        }

        for(int a = 0;a < buttons.size();a++)
        {
            buttons[a]->Input(event, xscale, yscale);
        }
    }

    if(buttons[EXIT]->is_button_clicked() == true)
    {
        global::loop = false;
    }
    else if(buttons[PLAY]->is_button_clicked() == true)
    {
        if(SCPlay == nullptr)
        {
            SCPlay = new ScreenPlay(buttons[PLAY]);
        }
        SCPlay->Input(event, xscale, yscale);
    }
    else if(buttons[ABOUT]->is_button_clicked() == true)
    {
        if(SCAbout == nullptr)
        {
            SCAbout = new ScreenAbout(buttons[ABOUT]);
        }
        SCAbout->Input(event, xscale, yscale);
    }

    return;
}
Esempio n. 3
0
void ScreenMain::Input(ALLEGRO_EVENT &event, float &xscale, float &yscale)
{
    if(global::play == true)
    {
        if(SCGame == nullptr)
        {
            SCGame = new ScreenGame();
            colider = new CollisionHandler();
            raycallback = new RayCastCallBack();
            SCGame->colider = colider;
            colider->refscreen = SCGame;
            SCGame->raycallback = raycallback;
            raycallback->refscreen = SCGame;
            SCGame->Set_mission(global::save->Get_mission_number());
            global::audio_player->Stop_sample_instance(&intro_music_instance);
        }

        SCGame->Input(event, xscale, yscale);

        if(global::play == false)
        {
            if(SCGame != nullptr)
            {
                global::save->Save();
                delete SCGame;
                delete colider;
                delete raycallback;
                SCGame = nullptr;
                colider = nullptr;
                raycallback = nullptr;
                global::audio_player->Play_sample_instance(&intro_music_instance,ALLEGRO_PLAYMODE_LOOP);
            }
        }
        else
        {
            return;
        }
    }

    if(is_any_button_clicked() == false)
    {
        if(SCAbout != nullptr)
        {
            delete SCAbout;
            SCAbout = nullptr;
        }
        if(SCPlay != nullptr)
        {
            delete SCPlay;
            SCPlay = nullptr;
        }

        for(int a = 0;a < (int)buttons.size();a++)
        {
            buttons[a]->Input(event, xscale, yscale);
        }

        zemak_button->Input(event, xscale, yscale) == 2;
    }

    if(buttons[EXIT]->is_button_clicked() == true)
    {
        global::loop = false;
    }
    else if(buttons[PLAY]->is_button_clicked() == true)
    {
        if(SCPlay == nullptr)
        {
            SCPlay = new ScreenPlay(buttons[PLAY]);
        }
        SCPlay->Input(event, xscale, yscale);
    }
    else if(buttons[ABOUT]->is_button_clicked() == true)
    {
        if(SCAbout == nullptr)
        {
            SCAbout = new ScreenAbout(buttons[ABOUT]);
        }
        SCAbout->Input(event, xscale, yscale);
    }

    return;
}