void Logstalgia::initRequestBalls() { for(RequestBall* r: balls) { removeBall(r); } balls.clear(); }
void Logstalgia::initRequestBalls() { for(auto it = balls.begin(); it != balls.end(); it++) { removeBall(*it); } balls.clear(); }
void display(void){ adjustCamera(); glClear(GL_COLOR_BUFFER_BIT); giveTexture(); glPushMatrix(); glTranslatef(demonX,demonY,0); giveTextureDemon(); glPopMatrix(); glPushMatrix(); { //translating to the left-bottom corner of our boundary if(jumped){ moveCannon(); } glTranslatef(cannonBaseX ,cannonBaseY,0); glColor3f(BLACK); drawObstacles(); //tranlating to the cannon's bottom glRotatef(rot_angle , 0 , 0 , 1); drawCannon(); drawPiston(); //draw Cannon Ball curBall->drawUnreleased(); } glPopMatrix(); displayScoreboard(); updateDemon(); //drawDemon(); manageTurtles(); //for every released ball... for(int i=0;i<balls.size();i++){ balls[i]->drawReleased(); //cout << balls[i]->ballX << " " << balls[i]->ballY << " " << balls[i]->ballVelX << " " << balls[i]->ballVelY << endl; if(balls[i]->stoped()){ removeBall(i); } } ballTurtle(); ballDemon(); turtleCannon(); glFlush(); glutSwapBuffers(); }
void checkCollisions(void) { int i,j; for (i=0;i<Length(shots);i++) { shot s = shots[i]; if (s.inPlay) //s is a struct that maintains attributes of balls, inplay is an integer in struct tower that contains 0 & 1 and maintains if minion is in range of that tower { for (j=0;j<Length(waves[waveNumber-1].m);j++) { if (waves[waveNumber-1].m[j].inPlay) { point origin = s.p; point target = waves[waveNumber-1].m[j].translation; point tScale = waves[waveNumber-1].m[j].scale; double distance = sqrt((origin.x-target.x)*(origin.x-target.x)+ (origin.z-target.z)*(origin.z-target.z)); if (distance < 5*tScale.x) { int health = calculateDamageToMinion(waveNumber-1,j,i); removeBall(i); if (health <= 0) removeMinion(waveNumber-1,j); printf("\nshot i :%d\n",i); printf("shot loc x:%f\n",origin.x); printf("shot loc y:%f\n",origin.y); printf("shot loc z:%f\n",origin.z); printf("minion j :%d\n",j); printf("minion loc x:%f\n",target.x); printf("minion loc y:%f\n",target.y); printf("minion loc z:%f\n",target.z); printf("minion scale:%f\n",tScale.x); printf("distance :%f\n",distance); break; } } } } } }
void Logstalgia::reset() { end_reached = false; highscore = 0; for(std::map<std::string, Paddle*>::iterator it= paddles.begin(); it!=paddles.end();it++) { delete it->second; } paddles.clear(); if(gPaddleMode <= PADDLE_SINGLE) { vec2f paddle_pos = vec2f(paddle_x - 20, rand() % display.height); Paddle* paddle = new Paddle(paddle_pos, paddle_colour, ""); paddles[""] = paddle; } for(std::list<RequestBall*>::iterator it = balls.begin(); it != balls.end(); it++) { removeBall(*it); } balls.clear(); ipSummarizer->recalc_display(); for(size_t i=0;i<summGroups.size();i++) { summGroups[i]->recalc_display(); } queued_entries.clear(); // reset settings elapsed_time = 0; starttime = 0; lasttime = 0; }
void Logstalgia::logic(float t, float dt) { float sdt = dt * settings.simulation_speed; //increment clock elapsed_time += sdt; currtime = starttime + (long)(elapsed_time); if(settings.stop_time && currtime > settings.stop_time) { currtime = settings.stop_time; } if(mousehide_timeout>0.0f) { mousehide_timeout -= dt; if(mousehide_timeout<0.0f) { SDL_ShowCursor(false); } } infowindow.hide(); if(end_reached && balls.empty()) { appFinished = true; return; } //if paused, dont move anything, only check what is under mouse if(paused) { for(auto& it: paddles) { Paddle* paddle = it.second; if(paddle->mouseOver(infowindow, mousepos)) { break; } } for(RequestBall* ball : balls) { if(ball->mouseOver(infowindow, mousepos)) { break; } } if(!ipSummarizer->mouseOver(infowindow,mousepos)) { for(Summarizer* s: summarizers) { if(s->mouseOver(infowindow, mousepos)) break; } } return; } //next will fast forward clock to the time of the next entry, //if the next entry is in the future if(next || (!settings.disable_auto_skip && balls.empty())) { if(!queued_entries.empty()) { LogEntry* le = queued_entries.front(); long entrytime = le->timestamp; if(entrytime > currtime) { elapsed_time = entrytime - starttime; currtime = starttime + (long)(elapsed_time); } } next = false; } //recalc spawn speed each second by if(currtime != lasttime) { //dont bother reading the log if we dont need to if(queued_entries.empty() || queued_entries.back()->timestamp <= currtime) { readLog(); } profile_start("determine new entries"); int items_to_spawn=0; for(LogEntry* le : queued_entries) { if(le->timestamp > currtime) break; items_to_spawn++; addStrings(le); } profile_stop(); //debugLog("items to spawn %d\n", items_to_spawn); if(items_to_spawn > 0) { profile_start("add new strings"); //re-summarize ipSummarizer->summarize(); for(Summarizer* s : summarizers) { s->summarize(); } profile_stop(); profile_start("add new entries"); float item_offset = 1.0 / (float) (items_to_spawn); int item_no = 0; while(!queued_entries.empty()) { LogEntry* le = queued_entries.front(); if(le->timestamp > currtime) break; float pos_offset = item_offset * (float) item_no++; float start_offset = std::min(1.0f, pos_offset); addBall(le, start_offset); queued_entries.pop_front(); } } //update date if(total_entries>0) { char datestr[256]; char timestr[256]; struct tm* timeinfo = localtime ( &currtime ); strftime(datestr, 256, "%A, %B %d, %Y", timeinfo); strftime(timestr, 256, "%X", timeinfo); displaydate = datestr; displaytime = timestr; } else { displaydate = ""; displaytime = ""; } lasttime=currtime; profile_stop(); } else { //do small reads per frame if we havent buffered the next second if(queued_entries.empty() || queued_entries.back()->timestamp <= currtime+1) { readLog(50); } } std::list<Paddle*> inactivePaddles; //update paddles for(auto& it: paddles) { std::string paddle_token = it.first; Paddle* paddle = it.second; if(settings.paddle_mode > PADDLE_SINGLE && !paddle->moving() && !paddle->visible()) { bool token_match = false; //are there any requests that will match this paddle? for(RequestBall* ball : balls) { if( (settings.paddle_mode == PADDLE_VHOST && ball->le->vhost == paddle_token) || (settings.paddle_mode == PADDLE_PID && ball->le->pid == paddle_token)) { token_match = true; break; } } //mark this paddle for deletion, continue if(!token_match) { inactivePaddles.push_back(paddle); continue; } } // find nearest ball to this paddle if( (retarget || !paddle->getTarget())) { RequestBall* ball = findNearest(paddle, paddle_token); if(ball != 0) { paddle->setTarget(ball); } else if(!paddle->moving()) { paddle->setTarget(0); } } paddle->logic(sdt); } retarget = false; profile_start("check ball status"); // NOTE: special handling for this iterator as items are being removed for(auto it = balls.begin(); it != balls.end();) { RequestBall* ball = *it; highscore += ball->logic(sdt); if(ball->isFinished()) { it = balls.erase(it); removeBall(ball); } else { it++; } } profile_stop(); profile_start("ipSummarizer logic"); ipSummarizer->logic(dt); profile_stop(); profile_start("updateGroups logic"); updateGroups(dt); profile_stop(); screen_blank_elapsed += dt; if(screen_blank_elapsed-screen_blank_interval > screen_blank_period) screen_blank_elapsed = 0.0f; //update font alpha font_alpha = 1.0f; if(screen_blank_elapsed>screen_blank_interval) { font_alpha = std::min(1.0f, (float) fabs(1.0f - (screen_blank_elapsed-screen_blank_interval)/(screen_blank_period*0.5))); font_alpha *= font_alpha; } }
void BallMap::checkAndRemoveChain() { BallSprite *ball; // 1. reset ingnore flag for (int i = 0; i < m_size.height * m_size.width; i++) { ball = m_matrix[i]; if (!ball) { continue; } ball->setIgnoreCheck(false); } // 2. check chain std::list<BallSprite *> longerList; for (int i = 0; i < m_size.height * m_size.width; i++) { ball = m_matrix[i]; if (!ball) { continue; } if (ball->getIsNeedRemove()) { continue;// 已标记过的跳过检查 } if (ball->getIgnoreCheck()) { // continue;// 新变化的特殊寿司,不消除 } // start count chain std::list<BallSprite *> colChainList; getColChain(ball, colChainList); if (colChainList.size() >= 3) { longerList.merge(colChainList); } std::list<BallSprite *> rowChainList; getRowChain(ball, rowChainList); if (rowChainList.size() >= 3) { longerList.merge(rowChainList); } if (longerList.size() < 3) { m_isNeedCheckSelf = false; TwoBallPos towBall = this->selfCheckHaveMore(); if (isPointEqual(towBall.srcPos, towBall.destPos)) { this->removeAllBall(true); } continue;// 小于3个不消除 } std::list<BallSprite *>::iterator itList; // longerList.sort(); //sort the list // longerList.erase( unique( longerList.begin(), longerList.end() ), longerList.end());//Remove duplicate list values for (itList = longerList.begin(); itList != longerList.end(); itList++) { ball = dynamic_cast<BallSprite*>(*itList); if (!ball) { continue; } markRemove(ball); } // 如何是自由掉落产生的4消, 取最后一个变化为特殊寿司 if (longerList.size() > 3) { ball->setIgnoreCheck(true); ball->setIsNeedRemove(false); ball->setDisplayMode(DISPLAY_MODE_FOUR); } } if (longerList.size() >= 3) { m_readyRemoveList = longerList; } // 3.消除标记了的寿司 removeBall(); }