void PipeImage::rotate(bool clockwise) { if (!rotatable) return; if (clockwise) setSides(bottom, top, left, right); else setSides(top, bottom, right, left); }
void HexagonGame::newGame(const string& mId, bool mFirstPlay, float mDifficultyMult) { initFlashEffect(); firstPlay = mFirstPlay; setLevelData(assets.getLevelData(mId), mFirstPlay); difficultyMult = mDifficultyMult; // Audio cleanup assets.stopSounds(); stopLevelMusic(); assets.playSound("go.ogg"); playLevelMusic(); if(Config::getMusicSpeedDMSync()) { auto current(assets.getMusicPlayer().getCurrent()); if(current != nullptr) current->setPitch(pow(difficultyMult, 0.12f)); } // Events cleanup messageText.setString(""); eventTimeline.clear(); eventTimeline.reset(); messageTimeline.clear(); messageTimeline.reset(); // Manager cleanup manager.clear(); factory.createPlayer(); // Timeline cleanup timeline.clear(); timeline.reset(); effectTimelineManager.clear(); mustChangeSides = false; // FPSWatcher reset fpsWatcher.reset(); if(Config::getOfficial()) fpsWatcher.enable(); // LUA context and game status cleanup status = HexagonGameStatus{}; if(!mFirstPlay) runLuaFunction<void>("onUnload"); lua = Lua::LuaContext{}; initLua(); runLuaFile(levelData->luaScriptPath); runLuaFunction<void>("onInit"); runLuaFunction<void>("onLoad"); restartId = mId; restartFirstTime = false; setSides(levelStatus.sides); // Reset zoom overlayCamera.setView({{Config::getWidth() / 2.f, Config::getHeight() / 2.f}, Vec2f(Config::getWidth(), Config::getHeight())}); backgroundCamera.setView({ssvs::zeroVec2f, {Config::getWidth() * Config::getZoomFactor(), Config::getHeight() * Config::getZoomFactor()}}); backgroundCamera.setRotation(0); // 3D Cameras cleanup depthCameras.clear(); auto depth(styleData._3dDepth); if(depth > Config::get3DMaxDepth()) depth = Config::get3DMaxDepth(); for(auto i(0u); i < depth; ++i) depthCameras.push_back({window, {}}); }
void HexagonGame::sideChange(int mSideNumber) { runLuaFunction<void>("onIncrement"); levelStatus.speedMult += levelStatus.speedInc; levelStatus.delayMult += levelStatus.delayInc; if(levelStatus.rndSideChangesEnabled) setSides(mSideNumber); mustChangeSides = false; }
void HexagonGame::sideChange(int mSideNumber) { runLuaFunction<void>("onIncrement"); setSpeedMultiplier(levelData.getSpeedMultiplier() + levelData.getSpeedIncrement()); setDelayMultiplier(levelData.getDelayMultiplier() + levelData.getDelayIncrement()); if(status.randomSideChangesEnabled) setSides(mSideNumber); mustChangeSides = false; }
void HexagonGame::randomSideChange() { if(manager.getComponentPtrsById("wall").size() > 0) { timeline.add(new Wait(10)); timeline.add(new Do([&] { randomSideChange(); })); return; } setSides(getRnd(levelData.getSidesMin(), levelData.getSidesMax() + 1)); }
void HexagonGame::newGame(string mId, bool mFirstPlay) { clearMessages(); setLevelData(getLevelData(mId), mFirstPlay); stopAllSounds(); playSound("play"); pm->resetAdj(); stopLevelMusic(); playLevelMusic(); rotationDirection = getRnd(0, 100) > 50 ? true : false; scripts.clear(); timeStop = 0; randomSideChangesEnabled = true; incrementEnabled = true; maxPulse = 85; minPulse = 75; pulseSpeedBackwards = 1; pulseSpeed = 1; hasDied = false; mustRestart = false; currentTime = 0; incrementTime = 0; setSides(levelData.getSides()); radius = minPulse; manager.clear(); createPlayer(manager, this, centerPos); scriptsTimeline = Timeline{}; messagesTimeline = Timeline{}; timeline = Timeline{}; }
void phdWarper::setAsString(string & _setup) { vector<string> items = ofSplitString(_setup, ";", true, true); if(items.size() > 17 && items[0] == "W") { setSides(ofToInt(items[1])); double x1, y1, x2, y2, x3, y3, x4, y4; x1 = ofToFloat(items[2]); y1 = ofToFloat(items[3]); x2 = ofToFloat(items[4]); y2 = ofToFloat(items[5]); x3 = ofToFloat(items[6]); y3 = ofToFloat(items[7]); x4 = ofToFloat(items[8]); y4 = ofToFloat(items[9]); setSrcQuad(x1,y1,x2,y2,x3,y3,x4,y4); x1 = ofToFloat(items[10]); y1 = ofToFloat(items[11]); x2 = ofToFloat(items[12]); y2 = ofToFloat(items[13]); x3 = ofToFloat(items[14]); y3 = ofToFloat(items[15]); x4 = ofToFloat(items[16]); y4 = ofToFloat(items[17]); setDstQuad(x1,y1,x2,y2,x3,y3,x4,y4); } }
/* * sets the normals and dists field of poly (defining the its sides). * if poly is not convex, then set the normals and dists of the triangles (must be set * beforehand) * also vertices must be sorted clockwise. */ void setSides(Poly *poly) { Vertex *v1, *v2; float norm; int i; if(poly == NULL) { return; } if(poly->num_triangles > 0) { for(i=0; i<poly->num_triangles; i++) { setSides(poly->triangles+i); } return; } poly->normals=(Vector*)calloc(poly->num_verts, sizeof(Vector)); poly->dists=(float*)calloc(poly->num_verts, sizeof(float)); for(i=0; i<poly->num_verts; i++) { v1=poly->verts+i; v2=poly->verts+((i+1)%poly->num_verts); norm=sqrt((v2->x-v1->x)*(v2->x-v1->x)+(v2->y-v1->y)*(v2->y-v1->y)); poly->normals[i].x=(v1->y-v2->y)/norm; poly->normals[i].y=(v2->x-v1->x)/norm; poly->dists[i]=poly->normals[i].x*v1->x+poly->normals[i].y*v1->y; } }
void phdWarper::setup(double _w, double _h, int _sides) { setSize(_w, _h); setSides(_sides); setSrcQuad( 0, 0, width, 0, width, height, 0, height); setDstQuad( 0, 0, width, 0, width, height, 0, height); }
void HexagonGame::newGame(const string& mId, bool mFirstPlay, float mDifficultyMult) { firstPlay = mFirstPlay; setLevelData(getLevelData(mId), mFirstPlay); difficultyMult = mDifficultyMult; // Audio cleanup stopAllSounds(); playSound("go.ogg"); stopLevelMusic(); playLevelMusic(); // Events cleanup clearMessage(); for(auto eventPtr : eventPtrs) delete eventPtr; eventPtrs.clear(); while(!eventPtrQueue.empty()) { delete eventPtrQueue.front(); eventPtrQueue.pop(); } eventPtrQueue = queue<EventData*>{}; // Game status cleanup status = HexagonGameStatus{}; restartId = mId; restartFirstTime = false; setSides(levelData.getSides()); // Manager cleanup manager.clear(); factory.createPlayer(); // Timeline cleanup timeline.clear(); timeline.reset(); messageTimeline.clear(); messageTimeline.reset(); effectTimelineManager.clear(); // FPSWatcher reset fpsWatcher.reset(); if(getOfficial()) fpsWatcher.enable(); // LUA context cleanup if(!mFirstPlay) runLuaFunction<void>("onUnload"); lua = Lua::LuaContext{}; initLua(); runLuaFile(levelData.getValueString("lua_file")); runLuaFunction<void>("onLoad"); // Random rotation direction if(getRnd(0, 100) > 50) setRotationSpeed(getRotationSpeed() * -1); // Reset zoom overlayCamera.setView({{getWidth() / 2.f, getHeight() / 2.f}, sf::Vector2f(getWidth(), getHeight())}); backgroundCamera.setView({{0, 0}, {getWidth() * getZoomFactor(), getHeight() * getZoomFactor()}}); backgroundCamera.setRotation(0); // 3D Cameras cleanup depthCameras.clear(); unsigned int depth{styleData.get3DDepth()}; if(depth > get3DMaxDepth()) depth = get3DMaxDepth(); for(unsigned int i{0}; i < depth; ++i) depthCameras.push_back({window, {}}); }
Filter* getFilter(int (*transform)(void*, Point*, Point*), void *params, int dim_x, int dim_y, Point pt0) { Filter *tg; Point *t_grid; //transformed grid Poly *cell_poly, *poly; Vertex *v; char *is_transformed; int dim; float min_x, max_x, min_y, max_y; float area; int i, j, k; int ii, jj; int index; int last, allocated; if(params==NULL) return NULL; tg=(Filter*)calloc(1, sizeof(Filter)); tg->dim_x=dim_x; tg->dim_y=dim_y; tg->x0=pt0.x; tg->y0=pt0.y; tg->dx=tg->dy=1; dim=tg->dim_x*tg->dim_y; tg->num_pts=(int*)calloc(dim, sizeof(int)); tg->pts=(Point**)calloc(dim, sizeof(Point*)); tg->coefs=(float**)calloc(dim, sizeof(float*)); // compute the transformed grid (used to get the polygons corresponding to the cells. t_grid=(Point*)calloc((tg->dim_x+1)*(tg->dim_y+1), sizeof(Point)); is_transformed=(char*)calloc((tg->dim_x+1)*(tg->dim_y+1), sizeof(char)); for(k=0, j=0; j<=tg->dim_y; j++) { for(i=0; i<=tg->dim_x; i++, k++) { t_grid[k].x=tg->x0+i*tg->dx-tg->dx/2; t_grid[k].y=tg->y0+j*tg->dy-tg->dy/2; is_transformed[k]=(char)transform(params, t_grid+k, t_grid+k); if(is_transformed[k]==-1) return NULL; //should never happen! } } //for each cell, get the corresponding polygon, transform it, get all the overlapping cells, //(number of overlaping cells=numPoints[k]) and compute percentage of area inside each of these // cells cell_poly=generatePoly(4); cell_poly->verts[0].x=0; cell_poly->verts[0].y=1; cell_poly->verts[1].x=1; cell_poly->verts[1].y=1; cell_poly->verts[2].x=1; cell_poly->verts[2].y=0; cell_poly->verts[3].x=0; cell_poly->verts[3].y=0; setSides(cell_poly); // verts won't be used from now on, just normals and dists. only update dists for(index=0, k=0, j=0; j<tg->dim_y; j++, index++) { for(i=0; i<tg->dim_x; i++, k++, index++) { if(!(is_transformed[index] && is_transformed[index+1] && is_transformed[index+tg->dim_x+1] && is_transformed[index+tg->dim_x+2])) continue; if(!is_transformed[index] || !is_transformed[index+1] || !is_transformed[index+tg->dim_x+1] || !is_transformed[index+tg->dim_x+2]) { // cell contains border of transformation area. // TODO: handle this case continue; } poly=generatePoly(4); v=poly->verts; v[0].x=t_grid[index+tg->dim_x+1].x; v[0].y=t_grid[index+tg->dim_x+1].y; v[1].x=t_grid[index+tg->dim_x+2].x; v[1].y=t_grid[index+tg->dim_x+2].y; v[2].x=t_grid[index+1].x; v[2].y=t_grid[index+1].y; v[3].x=t_grid[index].x; v[3].y=t_grid[index].y; if(convexify4(poly)==-1) { deletePoly(poly, 1); continue; } setSides(poly); computeArea(poly); min_x=max_x=v[0].x; min_y=max_y=v[0].y; for(ii=1; ii<4; ii++) { if(v[ii].x<min_x) min_x=v[ii].x; else if(v[ii].x>max_x) max_x=v[ii].x; if(v[ii].y<min_y) min_y=v[ii].y; else if(v[ii].y>max_y) max_y=v[ii].y; } min_x=floorf(min_x); max_x=ceilf(max_x); min_y=floorf(min_y); max_y=ceilf(max_y); allocated=0; if((max_x-min_x) > 100 ||(max_y-min_y) > 100) { tg->num_pts[k]=1; tg->coefs[k]=(float*)calloc(1, sizeof(float)); tg->pts[k]=(Point*)calloc(1, sizeof(Point)); tg->coefs[k][0]=1; tg->pts[k][0].x=floor((max_x-min_x)/2); //TODO: fix that! tg->pts[k][0].y=floor((max_y-min_y)/2); deletePoly(poly, 1); continue; } for(jj=(int)min_y; jj<(int)max_y; jj++) { for(ii=(int)min_x; ii<(int)max_x; ii++) { cell_poly->dists[0]=jj+1; cell_poly->dists[1]=ii+1; cell_poly->dists[2]=-jj; cell_poly->dists[3]=-ii; area=intersectionArea(poly, cell_poly); if(area<SMALL) continue; last=tg->num_pts[k]++; if(tg->num_pts[k]>allocated) { allocated+=32; tg->coefs[k]=(float*)realloc(tg->coefs[k], allocated*sizeof(float)); tg->pts[k]=(Point*)realloc(tg->pts[k], allocated*sizeof(Point)); } tg->coefs[k][last]=area/poly->area; tg->pts[k][last].x=ii; tg->pts[k][last].y=jj; } } tg->coefs[k]=(float*)realloc(tg->coefs[k], tg->num_pts[k]*sizeof(float)); tg->pts[k]=(Point*)realloc(tg->pts[k], tg->num_pts[k]*sizeof(Point)); deletePoly(poly, 1); } //for(i) } //for(j) free(t_grid); free(is_transformed); return tg; }