void Figure::fixRotation(){ //move to left if out of bounds on right if (dTile%boardWidthTiles!=0) while (outOfBoundsX(0)) move(-1); //move up if out of bounds on the bottom while (outOfBoundsY(0)) move(boardWidthTiles); bool collision = true; int buff = 0; while (collision){ collision = willCollide(0); //react to collision down if (collision) move(boardWidthTiles); else return; //react to collision right collision = willCollide(0); if (collision) move(-1); else return; ++buff; if (buff > 4) break; } }
int main(int argc, int* argv) { init(); double render[XRES][YRES] = {0}; color colorArray[XRES][YRES] = {0}; color blank = {0, 0, 0}; int i; for(i = 0; i < NUMSPHERES; i++) { int xpx = 0; int ypx = 0; double x, y; for(y = 0; y < 1.0; y+=1.0/YRES) { for(x = 0; x < 1.5; x+=1.5/XRES) { triple temp = {x, y, 0}; triple result = willCollide(sphereArray[i], temp); if(!isNull(result) && (render[xpx][ypx] == 0.0 || magnitude(result) < render[xpx][ypx])) { render[xpx][ypx] = magnitude(result); double luminosity = calcShading(result, i); color tempColor = {0}; tempColor.r = sphereArray[i].c.r*(.4 + (.6*luminosity)); tempColor.g = sphereArray[i].c.g*(.4 + (.6*luminosity)); tempColor.b = sphereArray[i].c.b*(.4 + (.6*luminosity)); colorArray[xpx][ypx] = tempColor; } xpx++; } xpx = 0; ypx++; } } int x,y; FILE* fout = fopen( "img.ppm" , "w" ) ; // fprintf( fout , "P3\n" ) ; fprintf( fout , "%d %d\n" , XRES , YRES ) ; fprintf( fout , "255\n" ) ; // for( y = YRES-1 ; y >=0 ; y-- ) { for( x = 0 ; x < XRES ; x++ ) { fprintf( fout , "%d %d %d\n" , colorArray[x][y].r , colorArray[x][y].g , colorArray[x][y].b ) ; } } close( fout ) ; // return 0 ; }
void Figure::toSide(int increment){ if (outOfBoundsX(increment)) return; if (willCollide(increment)) return; move(increment); //dTile += increment; //dx += increment*0.1f; }
void Figure::down(bool isCollapising){ //bool collision = willCollide(-boardWidthTiles); //bool bounds = outOfBoundsY(-boardWidthTiles); if (willCollide(-boardWidthTiles) || outOfBoundsY(-boardWidthTiles)){ if (!isCollapising) Game::getInstance().timeForNewFigure = true; occupyTiles(); return; } move(-boardWidthTiles); }
int main(int argc, char* argv[]) { numspheres = 0; if(argc == 2) { filepath = argv[1]; countLines(filepath); sphereArray = calloc(numspheres + 4, sizeof(sphere)); readFile(filepath); } else sphereArray = calloc(4, sizeof(sphere)); init(); //makeBoundingBox(); double render[XRES][YRES] = {0}; color colorArray[XRES][YRES] = {0}; color blank = {0, 0, 0}; int i; for(i = 0; i < numspheres + 4; i++) { int xpx = 0; int ypx = 0; double x, y; for(y = 0; y < 1.0; y+=1.0/YRES) { for(x = 0; x < 1.5; x+=1.5/XRES) { triple temp = {x, y, 0}; triple result = willCollide(sphereArray[i], temp); if(!isNull(result) && (render[xpx][ypx] == 0.0 || magnitude(result) < render[xpx][ypx])) { render[xpx][ypx] = magnitude(result); double luminosity = calcShading(result, i); color reflectance = calcReflectance(result, i); color tempColor = {0}; if(i == numspheres && (((int)floor(result.x*5)%2==0&&(int)floor(result.z*5)%2!=0)||((int)floor(result.x*5)%2!=0&&(int)floor(result.z*5)%2==0))) { tempColor.r = (255-(.6*sphereArray[i].c.r+.4*reflectance.r))*(.4 + (.6*luminosity)); tempColor.g = (255-(.6*sphereArray[i].c.g+.4*reflectance.g))*(.4 + (.6*luminosity)); tempColor.b = (255-(.6*sphereArray[i].c.b+.4*reflectance.b))*(.4 + (.6*luminosity)); } else { tempColor.r = (.6*sphereArray[i].c.r+.4*reflectance.r)*(.4 + (.6*luminosity)); tempColor.g = (.6*sphereArray[i].c.g+.4*reflectance.g)*(.4 + (.6*luminosity)); tempColor.b = (.6*sphereArray[i].c.b+.4*reflectance.b)*(.4 + (.6*luminosity)); } colorArray[xpx][ypx] = tempColor; } xpx++; } xpx = 0; ypx++; } } int x,y; FILE* fout = fopen( "img.ppm" , "w" ) ; // fprintf( fout , "P3\n" ) ; fprintf( fout , "%d %d\n" , XRES , YRES ) ; fprintf( fout , "255\n" ) ; // for( y = YRES-1 ; y >=0 ; y-- ) { for( x = 0 ; x < XRES ; x++ ) { fprintf( fout , "%d %d %d\n" , colorArray[x][y].r , colorArray[x][y].g , colorArray[x][y].b ) ; } } close( fout ) ; // return 0 ; }
void CHLDMBot :: modThink () { m_fIdealMoveSpeed = CClassInterface::getMaxSpeed(m_pEdict); // update hitbox hull //m_pEdict->GetCollideable()->GetCollisionOrigin(); if ( !CBotGlobals::entityIsValid(m_NearestPhysObj) ) m_NearestPhysObj = NULL; if ( !CBotGlobals::entityIsValid(m_FailedPhysObj) ) m_FailedPhysObj = NULL; //if ( m_pWeapons ) // m_pWeapons->update(); //if ( m_fFixWeaponTime < engine->Time() ) //{ m_pCurrentWeapon = CClassInterface::getCurrentWeapon(m_pEdict); // m_fFixWeaponTime = engine->Time() + 1.0f; //} if ( m_pCurrentWeapon ) CClassInterface::getWeaponClip(m_pCurrentWeapon,&m_iClip1,&m_iClip2); if ( CClassInterface::onLadder(m_pEdict) != NULL ) { setMoveLookPriority(MOVELOOK_OVERRIDE); setLookAtTask(LOOK_WAYPOINT); m_pButtons->holdButton(IN_FORWARD,0,1,0); setMoveLookPriority(MOVELOOK_MODTHINK); } if ( (m_fCurrentDanger >= 20.0f) && (CClassInterface::auxPower(m_pEdict) > 90.f ) && (m_flSprintTime < engine->Time())) { m_pButtons->holdButton(IN_SPEED,0,1,0); } else if (( m_fCurrentDanger < 1 ) || (CClassInterface::auxPower(m_pEdict) < 5.0f )) { m_flSprintTime = engine->Time() + randomFloat(5.0f,20.0f); } if ( m_fLastSeeEnemy && ((m_fLastSeeEnemy + 5.0)<engine->Time()) ) { CBotWeapon *pWeapon = getCurrentWeapon(); if ( pWeapon && (pWeapon->getClip1(this)==0) && (pWeapon->getAmmo(this) > 0 ) ) { m_fLastSeeEnemy = 0; m_pButtons->tap(IN_RELOAD); } } if ( m_NearestPhysObj.get() ) { bool bCarry = false; edict_t *pEntity = m_NearestPhysObj.get(); if ( m_pCurrentWeapon && !strcmp("weapon_physcannon",m_pCurrentWeapon->GetClassName()) ) { m_pCarryingObject = CClassInterface::gravityGunObject(m_pCurrentWeapon); bCarry = (CClassInterface::gravityGunObject(m_pCurrentWeapon) == m_NearestPhysObj.get()); } if ( !bCarry && (distanceFrom(pEntity) < rcbot_jump_obst_dist.GetFloat()) ) { bool bCanJump = false; float fTime = 0; if ( willCollide(pEntity,&bCanJump,&fTime) ) { if ( bCanJump && (fTime < 1.5f) ) // one second to jump { if ( randomInt(0,1) ) jump(); } } } } }