示例#1
0
void DFTimer::check () {
	if (!isRun)
		return;
	uint32_t divTime = millis () - nowTime;
	if (isFirst ? (divTime > startTime) : (divTime > delayTime)) {
		isFirst = false;
		nowTime = millis (); 
		if (args)
			timeHandler (args);
		else 
			timeHandlern ();
	}
}
示例#2
0
文件: Arc_2.0.c 项目: linuxq/Arc_2.0
static void applyConfig() {
	time_t t = time(NULL);
	setDate(localtime(&t));
	step = 100;
	timeHandler(NULL);
}
示例#3
0
void Environment::Update()
{


    goldText->Draw("Gold: " + std::to_string((int)resources));
    populationText->Draw("Population: " + std::to_string(humanPop)+"/"+std::to_string(humanMaxPop));
    timeText->Draw(timeHandler((int)((SDL_GetTicks()/1000))-startTime));

    if(broke){
        if(SDL_GetTicks() < brokeTime+2000){
            insufficientFunds->Draw("You don't have " + std::to_string(brokeCost) + " gold!");
        }else{
            broke = false;
        }
    }

    if(overpopulated){
        if(SDL_GetTicks() < brokeTime+2000){
            noHousing->Draw("You need more houses!");
        }else{
            overpopulated = false;
        }
    }
    
    if(alreadyCreating){
        if(SDL_GetTicks() < brokeTime+2000){
            busyBuilding->Draw("This building is already creating!");
        }else{
            alreadyCreating = false;
        }
    }

    if(showMenu){
        if(selectedBuilding->selected){
            optionsMenu->UpdateType(selectedBuilding->getMenuType());
        }else if(selectedCharacter->selected){
            optionsMenu->UpdateType(selectedCharacter->getMenuType());
        }else{
            optionsMenu->UpdateType(1);
        }
        optionsMenu->Draw();
        optionsMenu->Update();
    }

    if(selectedBuilding->menuType == 4 && selectedBuilding->isAlive()){ //town center selected
        if(optionsMenu->buttonPressed){
            if (selectedBuilding->getTeam() == 1) { //check if human towncenter
                if(optionsMenu->getWhatToMake() == 3){ //if villager selected
                    //make villager next to towncenter
                    if(resources>=optionsMenu->getOpCost() && humanPop < humanMaxPop && humanPop < maxMaxPop  && selectedBuilding->creating == false){ //if enough resources and population room

                        resources = resources - optionsMenu->getOpCost(); //remove resources
                        selectedBuilding->startCreating(1); //initiate creation of unit (10 sec)
                    }else if(resources<optionsMenu->getOpCost()){
                        alertInsufficientFunds();
                    }else if(humanPop >= humanMaxPop){
                        alertNoHousing();
                    }else if(selectedBuilding->creating){
                        alertCreating();
                    }
                    optionsMenu->buttonPressed = false;
                }
            } else if (team == 2) { //orc towncenter
                if(optionsMenu->getWhatToMake() == 4){ //if orc villager selected
                    //make orc villager next to towncenter
                    if(orcResources>=optionsMenu->getOpCost()  && orcPop < orcMaxPop && selectedBuilding->creating == false){
                        orcResources = orcResources - optionsMenu->getOpCost();
                        selectedBuilding->startCreating(2);
                    }else if(resources<optionsMenu->getOpCost()){
                        alertInsufficientFunds();
                    }else if(humanPop >= humanMaxPop){
                        alertNoHousing();
                    }else if(selectedBuilding->creating){
                        alertCreating();
                    }
                    optionsMenu->buttonPressed = false;
                }
            }
        }
    }

    if(selectedBuilding->menuType == 5 && selectedBuilding->isAlive() && selectedBuilding->isConstructed()){ //barracks selected
        if(optionsMenu->buttonPressed){
            if (selectedBuilding->getTeam() == 1) { //check if human barracks
                if(optionsMenu->getWhatToMake() == 5){
                    //make militia next to barracks
                    if(resources>=optionsMenu->getOpCost() && humanPop < humanMaxPop && humanPop < maxMaxPop && selectedBuilding->creating == false){

                        resources = resources - optionsMenu->getOpCost();
                        selectedBuilding->startCreating(1);
                    }else if(resources < optionsMenu->getOpCost()){
                        alertInsufficientFunds();
                    }else if(humanPop >= humanMaxPop){
                        alertNoHousing();
                    }else if(selectedBuilding->creating){
                        alertCreating();
                    }
                    optionsMenu->buttonPressed = false;
                }else if(optionsMenu->getWhatToMake() == 7){
                    //make champion next to barracks
                    if(resources >= optionsMenu->getOpCost() && humanPop < humanMaxPop && selectedBuilding->creating == false){
                        resources = resources - optionsMenu->getOpCost();
                        selectedBuilding->startCreating(3);
                    }else if(resources < optionsMenu->getOpCost()){
                        alertInsufficientFunds();
                    }else if(humanPop >= humanMaxPop){
                        alertNoHousing();
                    }else if(selectedBuilding->creating){
                        alertCreating();
                    }
                    optionsMenu->buttonPressed = false;
                }
            } else if (team == 2) { //orc barracks
                if(optionsMenu->getWhatToMake() == 6){
                    //make orc militia next to barracks

                    if(orcResources>=optionsMenu->getOpCost() && orcPop < orcMaxPop && selectedBuilding->creating == false){
                        orcResources = orcResources - optionsMenu->getOpCost();
                        selectedBuilding->startCreating(2);
                    }else{
                        alertInsufficientFunds();
                    }
                    optionsMenu->buttonPressed = false;
                }else if(optionsMenu->getWhatToMake() == 8){
                    //make champion next to barracks
                    if(orcResources>=optionsMenu->getOpCost()  && orcPop < orcMaxPop && selectedBuilding->creating == false){
                        orcResources = orcResources - optionsMenu->getOpCost();
                        selectedBuilding->startCreating(4);
                    }else{
                        alertInsufficientFunds();
                    }
                    optionsMenu->buttonPressed = false;
                }
            }
        }
    }

    for (std::list<Character*>::iterator i = characters.begin(); i != characters.end(); ++i)
    {
        if ((*i)->isAlive())
        {
            (*i)->Update();
            if ((*i)->getTeam() == 2) { //pass each orc unit to AI to determine its next action
                ai->updateCharacter((*i));
            }
        }
    }

    for (std::vector<Building*>::iterator i = buildings.begin(); i != buildings.end(); ++i)
    {
        if ((*i)->isAlive())
        {
            (*i)->Update();
            if ((*i)->getTeam() == 2) { //pass each orc building to AI to determine its next action
                ai->updateBuilding((*i));
            }
        }
    }

    for (std::vector<Gold*>::iterator i = goldMines.begin(); i != goldMines.end(); ++i)
    {
        if ((*i)->isAlive())
        {
            (*i)->Update();
        }
    }

    if (sdl_setup->GetEv()->type == SDL_MOUSEBUTTONDOWN)
    {
        if (sdl_setup->GetEv()->button.button == SDL_BUTTON_LEFT)
        {

            if(showMenu == false || *MouseY <= optionsMenu->getY()){
            for(std::vector<Building*>::iterator i = buildings.begin(); i != buildings.end(); ++i){
                if(*MouseX >= ((*i)->getStructureX()) && *MouseX <= ((*i)->getStructureX()+(*i)->getStructureW()) && *MouseY >= ((*i)->getStructureY()) && *MouseY <= ((*i)->getStructureY()+(*i)->getStructureH()))
                {
                    selectedBuilding->unSelect(); //unselect previously selected
                    (*i)->setSelected();
                    selectedBuilding = (*i); //reassign selected building for future deselection

                    break; //end loop once building found
                }
                selectedBuilding->unSelect(); //no building found, unselect previous building
            }

            for(std::vector<Gold*>::iterator i = goldMines.begin(); i != goldMines.end(); ++i){
                if(*MouseX >= ((*i)->getGoldX()) && *MouseX <= ((*i)->getGoldX()+(*i)->getGoldW()) && *MouseY >= ((*i)->getGoldY()) && *MouseY <= ((*i)->getGoldY()+(*i)->getGoldH()))
                {
                    selectedGold->unSelect(); //unselect previously selected
                    (*i)->setSelected();
                    selectedGold = (*i); //reassign selected gold mine for future deselection
                    break; //end loop once gold found
                }
                selectedGold->unSelect(); //no gold found, unselect previous gold
            }

            for (std::list<Character*>::iterator i = characters.begin(); i != characters.end(); ++i) //character selection takes priority over buildings and gold mines
            {
                if(*MouseX >= ((*i)->getCharacterX()-15) && *MouseX <= ((*i)->getCharacterX()+(*i)->getCharacterW()-15) && *MouseY >= ((*i)->getCharacterY()-20) && *MouseY <= ((*i)->getCharacterY()+(*i)->getCharacterH()-20) && (*i)->isAlive())
                {
                    selectedCharacter->unSelect(); //unselect previously selected
                    selectedBuilding->unSelect();
                    selectedGold->unSelect();
                    (*i)->setSelected();
                    selectedCharacter = (*i); //reassign selected character for future deselection

                    break; //prevent selection of multiple characters in same area
                }
                selectedCharacter->unSelect(); //unselect previously selected
            }

            if(optionsMenu->getWhatToMake() == 1 && !buildingConstructionCollision(*MouseX-50, *MouseY-50) && *MouseX < 550){ //check if valid build zone (no collisions and not in enemy territory)
                if (selectedCharacter->getTeam() == 1) {//check villager team
                    if(resources >= optionsMenu->getOpCost()){
                        buildings.push_back(new House(sdl_setup, constructionImage, *MouseX-50, *MouseY-50, 50, 50, 1, this)); //initially display construction zone
                        resources = resources - optionsMenu->getOpCost();
                    }else{
                        alertInsufficientFunds();
                    }
                } else {
                    if(orcResources >= optionsMenu->getOpCost()){
                        buildings.push_back(new House(sdl_setup, constructionImage, *MouseX-50, *MouseY-50, 50, 50, 2, this));
                        orcResources = orcResources - optionsMenu->getOpCost();
                    }else{
                        alertInsufficientFunds();
                    }
                }
                selectedCharacter->setFollowPoint(*MouseX, *MouseY); //move villager to construction zone

            }else if(optionsMenu->getWhatToMake() == 2 && !buildingConstructionCollision(*MouseX-50, *MouseY-50) && *MouseX < 550){
                if (selectedCharacter->getTeam() == 1) {//check villager team
                    if(resources >= optionsMenu->getOpCost()){
                        buildings.push_back(new Barracks(sdl_setup, constructionImage, *MouseX-50, *MouseY-50, 75, 75, 1, this));
                        resources = resources - optionsMenu->getOpCost();
                    }
                    else{
                        alertInsufficientFunds();
                    }
                } else {
                    if(orcResources >= optionsMenu->getOpCost()){
                        buildings.push_back(new Barracks(sdl_setup, constructionImage, *MouseX-50, *MouseY-50, 75, 75, 2, this));
                        orcResources = orcResources - optionsMenu->getOpCost();
                    }
                    else{
                        alertInsufficientFunds();
                    }
                }
                selectedCharacter->setFollowPoint(*MouseX, *MouseY); //move character to construction zone
            }
        }
    }
}
    if(sdl_setup->GetEv()->type == SDL_KEYDOWN){ //toggle showing of menu
       if(sdl_setup->GetEv()->key.keysym.sym == SDLK_SPACE){
            if(showMenu){
                showMenu = false;
            }else{
                showMenu = true;
            }
       }
    }
    if(sdl_setup->GetEv()->type == SDL_KEYDOWN){
       if(sdl_setup->GetEv()->key.keysym.sym == SDLK_F8){
            endGame(2);
       }
    }
    if(sdl_setup->GetEv()->type == SDL_KEYDOWN){
       if(sdl_setup->GetEv()->key.keysym.sym == SDLK_INSERT){
            resources += 100;
       }
    }
}
示例#4
0
文件: Arc_2.0.c 项目: linuxq/Arc_2.0
static void tapHandler(AccelAxisType axis, int32_t direction) {
	if (step) return;
	
	timeHandler(NULL);
}