static void handle_key_down( SDL_keysym* keysym ) { switch( keysym->sym ) { case SDLK_ESCAPE: quit_tutorial( 0 ); break; case SDLK_SPACE: s.expand(); s.expand(); s.expand(); s.expand(); s.expand(); s.expand(); s.expand(); s.expand(); s.expand(); s.expand(); break; default: break; } }
//******************************************************************************************** // void checkIfAtMoonMenu() // This method is used to start the game at your home base of the moon // This can be changed. //******************************************************************************************** int checkIfAtMoonMenu(ship &s,planet &j,planet &e,planet &m,planet &g,planet &M,planet &S,planet &n,planet &p,planet &c) { int input = 0; system("cls"); cout << "Welcome to the Moon, your home base " << "Planet Description goes here?? Maybe?." << endl << endl; cout << ":::Space News::: " << endl; cout << "Planet " << "Iron" << "\t" << "Price" << "\t" << "Sugar" << "\t" << "Price" << "\t" << "Rice" << "\t" << "Price" << endl; // cout << "Jupiter " << << "\t" << j.getIronQuantityDesired() << "\t" << j.getSugar() << "\t" << j.getSugarPrice() << "\t" << j.getRice() << "\t" << j.getRicePrice() << endl; // cout << "Earth " << << "\t" << e.getIronQuantityDesired() << "\t" << e.getSugar() << "\t" << e.getSugarPrice() << "\t" << e.getRice() << "\t" << e.getRicePrice() << endl; // cout << "Ganymede " << g.getIronQuantity() << "\t" << g.getIronQuantityDesired() << "\t" << g.getSugar() << "\t" << g.getSugarPrice() << "\t" << g.getRice() << "\t" << g.getRicePrice() << endl; // cout << "Mars " << m.getIronQuantity() << "\t" << m.getIronQuantityDesired() << "\t" << m.getSugar() << "\t" << m.getSugarPrice() << "\t" << m.getRice() << "\t" << m.getRicePrice() << endl; // cout << "Saturn " << S.getIronQuantity() << "\t" << S.getIronQuantityDesired() << "\t" << S.getSugar() << "\t" << S.getSugarPrice() << "\t" << S.getRice() << "\t" << S.getRicePrice() << endl; // cout << "Neptune " << n.getIronQuantity() << "\t" << n.getIronQuantityDesired() << "\t" << n.getSugar() << "\t" << n.getSugarPrice() << "\t" << n.getRice() << "\t" << n.getRicePrice() << endl; // cout << "Pluto " << p.getIronQuantity() << "\t" << p.getIronQuantityDesired() << "\t" << p.getSugar() << "\t" << p.getSugarPrice() << "\t" << p.getRice() << "\t" << p.getRicePrice() << endl; // cout << "Ceres " << c.getIronQuantity() << "\t" << c.getIronQuantityDesired() << "\t" << c.getSugar() << "\t" << c.getSugarPrice() << "\t" << c.getRice() << "\t" << c.getRicePrice() << endl; //cout << "Jupiter" << j.getIronQuantity() << "\t" << j.getIronQuantityDesiredQuantity() << "\t" << j.getSugar() << "\t" << j.getSugarPrice() << "\t" << j.getRice() << "\t" << j.getRicePrice() << endl; cout << endl; // cout << "\nRice: " << p.getRice() << endl; //cout << "\nFuel: " << p.getFuel() << endl; cout << "1. Check Mail Box: -- Not Functional... " << endl; cout << "2. Repair Ship: -- Not Functional... " << endl; cout << "3. Upgrade Ship: -- Not Functional... " << endl; cout << "4. Pick Up Passengers: -- Not Functional... " << endl; cout << "5. Talk to people listen to space news... -- not functional... " << endl; cout << "6. Leave Space Station... -- This works!" << endl; cout << endl; cout << "You have " << "Rice - " << s.getRice() << " Iron - " << s.getIron() << " Sugar - " << s.getSugar() << endl; cout << "SpaceBucks - " << s.getFunds() << " Fuel - " << s.getFuel() << " Cargo Max - " << s.getCARGO_MAX() << endl; cout << "What do you want to do?"; cin >> input; return input; }
//******************************************************************************************** // int checkIfAtPlanetMenu() // This method is used when you get to a planet to generate the buy and sell option // as of right now the planet.getPlanetName() is giving errors so it is left blank //******************************************************************************************** int checkIfAtPlanetMenu(ship &s,planet &p) { int input = 0; system("cls"); cout << "Welcome to --Fix Planet Name--... " << "Planet Description goes here?? Maybe?." << endl << endl; cout << "\nIron: " << p.getIronQuantity() << endl; cout << "\nSugar: " << p.getSugarQuantity() << endl; cout << "\nRice: " << p.getRiceQuantity() << endl; cout << "\nFuel: " << p.getFuel() << endl; cout << "1. Buy Iron: " << endl; cout << "2. Buy Sugar: " << endl; cout << "3. Buy Rice: " << endl; cout << "4. Sell Iron: " << endl; cout << "5. Sell Sugar: " << endl; cout << "6. Sell Rice: " << endl; cout << "7. Buy Fuel: " << endl; cout << "8. Exit planet" << endl; cout << "You have " << "Rice - " << s.getRice() << " Iron - " << s.getIron() << " Sugar - " << s.getSugar() << endl; cout << "SpaceBucks - " << s.getFunds() << " Fuel - " << s.getFuel() << " Cargo Max - " << s.getCARGO_MAX() << endl; cout << "What do you want to do?"; cin >> input; return input; }
void gun_shell::check_collision_voxel(ship& s, const vector3f& oldrelpos, const vector3f& newrelpos) { // positions are relative to bbox of s. matrix4f obj2voxel = s.get_model().get_base_mesh_transformation().inverse(); vector3f oldvoxpos = obj2voxel * oldrelpos, newvoxpos = obj2voxel * newrelpos; vector3f diffvoxpos = newvoxpos - oldvoxpos; // now iterate in 8 steps between oldvoxpos to newvoxpos, // transform both to voxel coordinates (0...N) // and determine voxel number by pos. // if coordinate is invalid, no hit, otherwise check voxel state (volume > 0.25 or similar) // if the voxel is filled. vector3f voxel_size_rcp = s.get_model().get_voxel_size().rcp(); const vector3i& vres = s.get_model().get_voxel_resolution(); vector3i vidxmax = vres - vector3i(1, 1, 1); vector3f voxel_pos_trans = vector3f(vres) * 0.5f; int lastvn = -1; log_debug("check collision voxel"); for (unsigned k = 0; k <= 10; ++k) { float kf = k/10.0f; vector3f voxpos = oldvoxpos + diffvoxpos * kf; vector3i v = vector3i(voxpos.coeff_mul(voxel_size_rcp) + voxel_pos_trans); v = v.max(vector3i(0,0,0)).min(vidxmax); int vn = (v.z * vres.y + v.y)*vres.x + v.x; if (vn != lastvn) { lastvn = vn; log_debug("voxel hit k="<<k<<" voxpos="<<voxpos<<" v="<<v<<" vn="<<vn); const model::voxel* vox = s.get_model().get_voxel_by_pos(v); if (vox) { // we hit a part of the object! log_debug("..... Object hit! ....."); // first compute exact real word position of impact vector3 impactpos = s.get_pos() + s.get_orientation().rotate(s.get_model(). get_base_mesh_transformation() * voxpos); // move gun shell pos to hit position to // let the explosion be at right position position = impactpos; log_debug("Hit object at real world pos " << impactpos); log_debug("that is relative: " << s.get_pos()-impactpos); // now damage the ship if (s.damage(impactpos, int(damage_amount))) { // fixme, crude gm.ship_sunk(&s); } else { s.ignite(); } #if 0 //spawn some location marker object for testing //at exact impact position gm.spawn_particle(new marker_particle(impactpos)); #endif gm.add_event(new event_shell_explosion(get_pos())); kill(); // grenade is used and dead return; // no more checks } } } }
static void draw_screen( void ) { static ship s; /* Clear the color and depth buffers. */ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glError(); /* We don't want to modify the projection matrix. */ glMatrixMode( GL_MODELVIEW ); glError(); glLoadIdentity( ); glError(); /* Move down the z-axis. */ glTranslatef( 0.0, 0.0, -15.0 ); glError(); glPushMatrix(); glError(); /* Rotate. */ //glRotatef( 100 * tim_x.read(), 1.0, 0.0, 0.0 ); //glRotatef( 100 * tim_y.read(), 0.0, 1.0, 0.0 ); // glRotatef( 100 * tim_c.read(), 0.0, 0.0, 1.0 ); glTranslatef( 5 * tim_x.read(), 5 * tim_y.read(), 0 ); glError(); glBegin( GL_LINES ); #define BRICK_CNT 40//actually sqrt(brick count) for( int x=-BRICK_CNT;x<BRICK_CNT;++x ) { for( int y=-BRICK_CNT;y<BRICK_CNT;++y) { draw_rect(x,y,1,1,y==0,true); } } glEnd(); glError(); glPopMatrix(); glError(); glRotatef( 100 * tim_x.read(), 1.0, 0.0, 0.0 ); glRotatef( 100 * tim_y.read(), 0.0, 1.0, 0.0 ); s.draw(); /* * Swap the buffers. This this tells the driver to * render the next frame from the contents of the * back-buffer, and to set all rendering operations * to occur on what was the front-buffer. */ SDL_GL_SwapBuffers( ); }
//*********************************************************************************** // int parseStringX() // This is a simple function to parse and return the coodinates you want to goto // // //********************************************************************************** void parseMovement(string strX,string strY,ship &s) { int x; int y; double hypot=0.0; x = atoi(strX.c_str()); y = atoi(strY.c_str()); if (x == 0) { s.setX(s.getX()); } if (y == 0) { s.setY(s.getY()); } if (x <= POSITIVE_XLIMIT && x >= NEGATIVE_XLIMIT && y <= POSITIVE_YLIMIT && y >= NEGATIVE_YLIMIT) { // calculate data for hypotenuese (sp?) and get units for fuel subtraction double xc = x-s.getX(); double yc = y-s.getY(); double xcsq = xc*xc; double yxsq = yc*yc; double hypot = abs(sqrt(xcsq+yxsq)); // error checking for input outfile.open("errorLog.txt", ios::app); outfile << "The time is: " << asctime(localtm) << " " << "Hypotenoose: " << hypot << endl; outfile.close(); // ------ s.setX(x); // s.setY(y); s.setFuel(s.getFuel()-hypot); } } // end of method
void SpriteCharacterGame::GetKeys(ship a_ship) { Vector3 A(1, 0, 0); Vector3 B(0, -1, 0); Vector3 C(0, 0, 1); Vector3 D(0, 0, -1); if(HELP_Keypresses(SDL_SCANCODE_W)) a_ship.Moveship(A); if(HELP_Keypresses(SDL_SCANCODE_S)) a_ship.Moveship(B); if(HELP_Keypresses(SDL_SCANCODE_A)) a_ship.Moveship(C); if(HELP_Keypresses(SDL_SCANCODE_D)) a_ship.Moveship(D); if(HELP_Keypresses(SDL_SCANCODE_SPACE)); if(HELP_Keypresses(SDL_SCANCODE_ESCAPE)); }
/** * Initialize observer hud stuff */ void hud_observer_init(ship *shipp, ai_info *aip) { // setup the pseduo ship and ai memcpy(&Hud_obs_ai, aip, sizeof(ai_info)); // (we used to do a memcpy here, but that doesn't work any longer, so let's just assign the values we need) Hud_obs_ship.clear(); strcpy_s(Hud_obs_ship.ship_name, shipp->ship_name); Hud_obs_ship.team = shipp->team; Hud_obs_ship.ai_index = shipp->ai_index; Hud_obs_ship.flags = shipp->flags; Hud_obs_ship.flags2 = shipp->flags2; Hud_obs_ship.ship_info_index = shipp->ship_info_index; Hud_obs_ship.objnum = shipp->objnum; Hud_obs_ship.wingnum = shipp->wingnum; Hud_obs_ship.alt_type_index = shipp->alt_type_index; Hud_obs_ship.callsign_index = shipp->callsign_index; memcpy(&Hud_obs_ship.np_updates, shipp->np_updates, MAX_PLAYERS * sizeof(np_update)); Hud_obs_ship.ship_max_hull_strength = shipp->ship_max_hull_strength; Hud_obs_ship.ship_max_shield_strength = shipp->ship_max_shield_strength; memcpy(&Hud_obs_ship.weapons, &shipp->weapons, sizeof(ship_weapon)); HUD_config.is_observer = 1; HUD_config.show_flags = HUD_observer_default_flags; HUD_config.show_flags2 = HUD_observer_default_flags2; HUD_config.popup_flags = 0x0; HUD_config.popup_flags2 = 0x0; // shutdown any playing static animations hud_init_target_static(); }
void gun_shell::check_collision_precise(ship& s, const vector3& oldrelpos, const vector3& newrelpos) { // transform positions to s' local bbox space quaternion qco = s.get_orientation().conj(); vector3f oldrelbbox = vector3f(qco.rotate(oldrelpos)); vector3f newrelbbox = vector3f(qco.rotate(newrelpos)); // now the model::get_min/get_max values can be used to compute the axis aligned bbox float tmin = 0.0f, tmax = 1.0f; // clip the line oldrelbbox->newrelbbox with the bbox vector3f d = newrelbbox - oldrelbbox; const vector3f& b = oldrelbbox; vector3f bmin = s.get_model().get_min(); vector3f bmax = s.get_model().get_max(); if (fabs(d.x) > 1e-5) { float t0 = (bmin.x - b.x) / d.x; float t1 = (bmax.x - b.x) / d.x; float ta = std::min(t0, t1); float tb = std::max(t0, t1); tmax = std::min(tmax, tb); tmin = std::max(tmin, ta); } if (fabs(d.y) > 1e-5) { float t0 = (bmin.y - b.y) / d.y; float t1 = (bmax.y - b.y) / d.y; float ta = std::min(t0, t1); float tb = std::max(t0, t1); tmax = std::min(tmax, tb); tmin = std::max(tmin, ta); } if (fabs(d.z) > 1e-5) { float t0 = (bmin.z - b.z) / d.z; float t1 = (bmax.z - b.z) / d.z; float ta = std::min(t0, t1); float tb = std::max(t0, t1); tmax = std::min(tmax, tb); tmin = std::max(tmin, ta); } if (tmin <= tmax) { //log_debug("shell hit object?!"); vector3f d = newrelbbox - oldrelbbox; check_collision_voxel(s, oldrelbbox + d * tmin, oldrelbbox + d * tmax); if (alive_stat == dead) return; // no more checks after hit } }
bool ship::hasConflictWith(ship s) { point p; if(isVertical) { for(int i = origin.y; i < (origin.y + length); i++) { p.x = origin.x; p.y = i; if(s.containsPoint(p)) { return true; } } }else if(!isVertical) { for(int i = origin.x; i < (origin.x + length); i++) { p.x = i; p.y = origin.y; if(s.containsPoint(p)) { return true; } } } return false; }
//*********************************************************************************** // void drawHUD() // This is a simple function to draw out the text description of where you are // // //********************************************************************************** int drawHUD(int mx, int my, ship &s) { string asciiPos; string stringX; string stringY; int eight=8; int input=0; cout << "The Moon (m), your home base is located at: "; //SetConsoleTextAttribute(hOut, FOREGROUND_GREEN); cout << mx << ", " << my << " - You are located at: " << s.getX() << ", " << s.getY(); //SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); cout << "\nStatus - Fuel: " << s.getFuel() << " Spacebucks: " << s.getFunds() << endl; cout << "Cargo Hold: Rice: " << s.getRice() << " IRON: " << s.getIron() << " SUGAR: " << s.getSugar() << endl; //cout << "What do you want to do? (1 +x 2 -x 3 +y 4 -y -- 8 is quit) "; cout << "Where do you want to move? (XX,YY -- 8 is quit) "; cin >> asciiPos; // error cehcking for input outfile.open("inputLog.txt", ios::app); outfile << "The time is: " << asctime(localtm) << " " << "asciiPos: " << asciiPos << endl; outfile.close(); // --------------- if (asciiPos == "8"){ exit(0); } stringX=asciiPos.substr(0,2); stringY=asciiPos.substr(3,5); parseMovement(stringX,stringY,s); //parseStringY(stringY,s.getY()); if (atoi(asciiPos.c_str()) == eight) { input=8; } else { // Input is coming in a format of XX,YY a five char string // it is beingsplit assuming that the input is two chars comma and two more // each value is being assigned to the x,y value - which is strange because I think // the x,y value is opposite anyway. =P // s.setX(atoi(stringX.c_str())); // must cast the string into an integer so that you can repostion your ship //s.setY(atoi(stringY.c_str())); // ditto } return input; }
static void draw_screen( void ) { /* Clear the color and depth buffers. */ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glError(); /* We don't want to modify the projection matrix. */ glMatrixMode( GL_MODELVIEW ); glError(); glLoadIdentity( ); glError(); /* Move down the z-axis. */ glTranslatef( 0.0, 0.0, -15.0 ); glError(); s.draw(); /* * Swap the buffers. This this tells the driver to * render the next frame from the contents of the * back-buffer, and to set all rendering operations * to occur on what was the front-buffer. */ SDL_GL_SwapBuffers( ); }
//finally here. Whew that's a lot of functions int main(int argc,char* args[]) { srand(time(NULL)); //spin the wheel! int i; //loop counter int frame=0; //total frames past if(init()==false) return 1; if(prepAssets()==false) return 1; if(Mix_PlayMusic(muBGM,-1)==-1) return 1; //read and store the string of appropriate language FILE *pLang; char strLang[25]; //language string if((pLang=fopen("text/en.WhyCantIHoldAllTheseFileExtensions","r"))!=NULL) { if(fgets(strLang,25,pLang)==NULL) return 1; } fclose(pLang); sfMenuPrompt=TTF_RenderText_Blended(fnMenu,strLang,clMenu); //read and store current highscore FILE *pHighScoreR; char strHighScore[10]; if((pHighScoreR=fopen("text/highscore.WhyCantIHoldAllTheseFileExtensions","r"))!=NULL) { if(fgets(strHighScore,10,pHighScoreR)==NULL) return 1; } fclose(pHighScoreR); sfHighScore=TTF_RenderText_Shaded(fnHighScore,strHighScore,clHighScore,clDefault); iHighScore=atoi(strHighScore); //string contents as an int //menu runs here while(quitMenu==false) { //display menu printb(0,0,sfMenu,sfScreen); printb((SCREEN_WIDTH-sfMenuPrompt->w)/2,315,sfMenuPrompt,sfScreen); //menu-only key controls while(SDL_PollEvent(&event)) { if(event.type==SDL_KEYDOWN) { switch(event.key.keysym.sym) { case SDLK_RETURN: quitMenu=true; break; case SDLK_ESCAPE: quitMenu=true; quitGame=true; quitOver=true; quitAll=true; break; default: ; } } //if the window gets X'd if(event.type==SDL_QUIT) { quitMenu=true; //quit the menu quitGame=true; //skip the game quitOver=true; quitAll=true; } } //refresh the screen if(SDL_Flip(sfScreen)==-1) return 1; } //game is starting! set up everything! tmTime.start(); tmFPS.start(); tmFPSUpd.start(); tmDelta.start(); tmMusic.start(); //REPLAY LOOP while(quitAll==false) { randBullets(); //game runs here while(quitGame==false) { //once wave time is up: level up and restart wave timer //setup phase is active if(waveZero==true&&tmTime.getTicks()>10000) { iWave++; nextWave(); tmTime.start(); waveZero=false; newBGM(); tmScore.start(); tmTimeAlive.start(); } //setup phase is off else if(tmTime.getTicks()>WAVE_LENGTH) { iWave++; nextWave(); tmTime.start(); } //change music after 90 seconds if(tmMusic.getTicks()>90000) { newBGM(); tmMusic.start(); } //score acceleration if(tmTimeAlive.getTicks()>30000) iScoreAccel=13; else if(tmTimeAlive.getTicks()>15000) iScoreAccel=6; else if(tmTimeAlive.getTicks()>7500) iScoreAccel=3; else if(tmTimeAlive.getTicks()>0) iScoreAccel=1; //score timing if(tmScore.getTicks()>250) { iScore+=iScoreAccel; tmScore.start(); } //1up timing if(tmTimeAlive.getTicks()>45000) { tmTimeAlive.start(); iLife++; //don't let player have too many lives //if 1up is allowed, play sound if(iLife>5)iLife=5; else if(Mix_PlayChannel(-1,chGain,0)==-1) return 1; } //while there's science to do while(SDL_PollEvent(&event)) { //ship controls myship.handleInput(); //other controls if(event.type==SDL_KEYDOWN) { switch(event.key.keysym.sym) { case SDLK_ESCAPE: quitGame=true; quitOver=true; quitAll=true; break; case SDLK_x: if(useBomb()==false) return 1; break; default: ; } } //if the window gets X'd if(event.type == SDL_QUIT) { quitGame = true; quitOver=true; quitAll=true; } } //update screen data myship.move(tmDelta.getTicks()); //update ship's position tmDelta.start(); //restart change of time timer printb(0,0,sfBG,sfScreen); //print background myship.show(); //print position to screen if(diedRecently==true) printb(120,0,sfDeathOverlay,sfScreen,NULL); if(bombedRecently==true) printb(120,0,sfBombFlash,sfScreen,NULL); if(waveZero==true) { //reset bullets to original when looping game printb(0,0,sfHowTo,sfScreen,NULL); iMaxBul=-1; } for(i=0; i<=iMaxBul; i++) { //player has died: do all relevant tracking if(isCol(myship.hitbox,b[i].hitbox)) { iLife--; iBomb=3; iScore-=50; if(iLife==0) quitGame=true; diedRecently=true; b[i].hitbox.x=rand()%420-120; b[i].hitbox.y=0; tmDeathOverlay.start(); tmTimeAlive.start(); if(Mix_PlayChannel(-1,chDeath,0)==-1) return 1; } if(b[i].hitbox.x>515) b[i].hitbox.x=120; if(b[i].hitbox.x<120) b[i].hitbox.x=515; //compensate for bullet width if(b[i].hitbox.y>480) { //because collision is counted from sScore of the picture b[i].hitbox.y=0; //so bulletwidth had to be subtracted b[i].xVel=rand()%5-2; //bullet can travel left or right b[i].yVel=rand()%4+1; //can only travel down } b[i].hitbox.y+=b[i].yVel; b[i].hitbox.x+=b[i].xVel; printb(b[i].hitbox.x,b[i].hitbox.y,sfBullet,sfScreen,NULL); } //expiry dates for death and bomb notifications if(tmDeathOverlay.getTicks()>500) diedRecently=false; if(tmBombFlash.getTicks()>250) bombedRecently=false; //display all stats renderHUD(); printb(7,50,sfHighScore,sfScreen,NULL); //refresh the screen if(SDL_Flip(sfScreen)==-1) return 1; //limit the frame rate if(tmFPS.getTicks()<1000/FRAMES_PER_SECOND) { SDL_Delay((1000/FRAMES_PER_SECOND)-tmFPS.getTicks()); tmFPS.start(); } frame++; //one frame has passed //update this once per second if(tmFPSUpd.getTicks()>1000) { std::stringstream newCaption; newCaption<<frame/(tmFPS.getTicks()/1000.f)<<" fps"; SDL_WM_SetCaption(newCaption.str().c_str(),NULL); tmFPSUpd.start(); //restart for the next one-second wait } } //store new high score, if there is one if(iScore>iHighScore) { FILE *pHighScoreW; if((pHighScoreW=fopen("text/highscore.WhyCantIHoldAllTheseFileExtensions","w"))!=NULL) { if(fprintf(pHighScoreW,"%d",iScore)==0) return 1; } fclose(pHighScoreW); newHighScore=true; } //stop playing music Mix_HaltMusic(); //game over runs here while(quitOver==false) { //some key events while(SDL_PollEvent(&event)) { if(event.type==SDL_KEYDOWN) { switch(event.key.keysym.sym) { case SDLK_RETURN: quitOver=true; break; case SDLK_ESCAPE: quitOver=true; quitAll=true; break; default: ; } } //if the window gets X'd if(event.type == SDL_QUIT) { quitOver=true; quitAll=true; } } //end surfaces std::stringstream finalScore; finalScore<<iScore; sfScore=TTF_RenderText_Blended(fnFinalScore,finalScore.str().c_str(),clMenu); //display restart prompt FILE *pRestart; char strRestart[30]; if((pRestart=fopen("text/enr.WhyCantIHoldAllTheseFileExtensions","r"))!=NULL) { if(fgets(strRestart,30,pRestart)==NULL) return 1; } fclose(pRestart); sfRestart=TTF_RenderText_Blended(fnMenu,strRestart,clScore); //print everything printb(0,0,sfOverBG,sfScreen,NULL); printb((SCREEN_WIDTH-sfRestart->w)/2,385,sfRestart,sfScreen,NULL); printb((SCREEN_WIDTH-sfScore->w)/2,240,sfScore,sfScreen,NULL); if(newHighScore==true) printb(430,280,sfNewHigh,sfScreen,NULL); //refresh the screen if(SDL_Flip(sfScreen)==-1) return 1; SDL_WM_SetCaption("Shutengu!!",NULL); } //reset loop conditions to allow replaying resetGame(); } //user has now quit cleanUp(); return 0; }
// added by Soren Haurburg //void Planet::Shop(int &money, int &fuel, Commodity &shipIron, Commodity &shipSugar, Commodity &shipRice, int CARGO_MAX) void planet::Shop(ship &s) { // HANDLE hStdout; // hStdout = GetStdHandle(STD_OUTPUT_HANDLE); // SetConsoleActiveScreenBuffer(hStdout); char pressedKey = '0'; while(pressedKey != 'E' && pressedKey != 'e') { system("cls"); // SetConsoleTextAttribute(hStdout, FOREGROUND_GREEN | FOREGROUND_RED); cout << "\n\t\t\tWelcome to " << *planetName << endl; int n=0; for (n=0;n < 24; n++) { printf("\n"); } // SetConsoleTextAttribute(hStdout, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE); cout << "\tYou have the follwing..." << endl; cout << "\t\tIron: " << s.getIron() << "Sugar: " << s.getSugar() << "Rice: " << s.getRice() << endl; cout << "\t\tMoney: " << s.getFunds() << "Fuel: " << s.getFuel() << "Cargo Space left: " << s.getCARGO_MAX()-(s.getIron()+s.getRice()+s.getSugar()) << endl; cout << "\n\tHere are your available actions on planet " << /*planetName*/ "Jupiter" << ":" << endl; if (ironDesiredQuantity>ironQuantity) { cout << "\n\t\t\t1. "<< *planetName << "will Buy Iron for: " << ((ironDesiredQuantity/ironQuantity) * ironQuantity) << endl; } else { cout << "\t\t\t5. " << *planetName << "will sell Iron for: " << ((ironQuantity/ironDesiredQuantity) * ironQuantity) << endl; } /*cout << "\n\t\t\t1. Buy Iron for: " << Iron.getBuyValue() << endl; cout << "\t\t\t2. Buy Sugar for: " << Sugar.getBuyValue() << endl; cout << "\t\t\t3. Buy Rice for: " << Rice.getBuyValue() << endl; cout << "\t\t\t4. Buy Fuel for: " << fuelPrice << endl; cout << "\t\t\t5. Sell Iron for: " << Iron.getSellValue() << endl; cout << "\t\t\t6. Sell Sugar for: " << Sugar.getSellValue() << endl; cout << "\t\t\t7. Sell Rice for: " << Rice.getSellValue() << endl; cout << "\t\t\tU. Buy Upgrades" << endl; */ cout << "\t\t\tE. Exit " << "Planet Name Here"; cin >> pressedKey; switch(pressedKey) { case '1': buyCommodity(s, "Iron"); break; case '2': // buyCommodity(s, Sugar); break; case '3': // buyCommodity(s, Rice); break; case '4': // buyFuel(s); break; case '5': sellCommodity(s, "Iron"); break; case '6': // sellCommodity(s, Sugar); break; case '7': // sellCommodity(s, Rice); break; case 'U': // upgradeShip(s); break; case 'u': // upgradeShip(s); break; case 'E': //leaving planet break; case 'e': //leaving planet break; default: cout << "Please pick one of the available options. " << endl; break; }// end of switch } }
//*********************************************************************************** // void checkIfAtPlanet() // This fucntion checks to see if you have arrived at a planet, then it'd put you // in the store. // //********************************************************************************** void checkIfAtPlanet(ship &s,planet &jupiter,planet &earth,planet &mars,planet &ganymede,planet &moon,planet &saturn,planet &neptune,planet &pluto,planet &ceres) { short input = 0; //********************************************************************************** // 1. Jupiter //********************************************************************************** if (s.getX()==jupiter.getX() && s.getY()==jupiter.getY()) { jupiter.Shop(s); } // end of jupiter if //********************************************************************************** // 2. Earth //********************************************************************************** if (s.getX()==earth.getX() && s.getY()==earth.getY()) { earth.Shop(s); } // end of earth if //********************************************************************************** // 3. Mars //********************************************************************************** if (s.getX()==mars.getX() && s.getY()==mars.getY()) { mars.Shop(s); } // end of mars if //********************************************************************************** // 4. Ganymede //********************************************************************************** if (s.getX()==ganymede.getX() && s.getY()==ganymede.getY()) { ganymede.Shop(s); } //********************************************************************************** // 5. Saturn //********************************************************************************** if (s.getX()==saturn.getX() && s.getY()==saturn.getY()) { saturn.Shop(s); } //********************************************************************************** // 6. Pluto //********************************************************************************** if (s.getX()==pluto.getX() && s.getY()==pluto.getY()) { pluto.Shop(s); } //********************************************************************************** // 7. Ceres //********************************************************************************** if (s.getX()==ceres.getX() && s.getY()==ceres.getY()) { ceres.Shop(s); } //********************************************************************************** // 8. Neptune //********************************************************************************** if (s.getX()==neptune.getX() && s.getY()==neptune.getY()) { neptune.Shop(s); } //********************************************************************************** // 9. Moon -- different from planet //********************************************************************************** if (s.getX()==moon.getX() && s.getY()==moon.getY()) { do { // begin do loop input = checkIfAtMoonMenu(s,jupiter,earth,mars,ganymede,moon,saturn,neptune,pluto,ceres); cout << "1. Check Mail Box: -- Not Functional... " << endl; cout << "2. Repair Ship: -- Not Functional... " << endl; cout << "3. Upgrade Ship: -- Not Functional... " << endl; cout << "4. Pick Up Passengers: -- Not Functional... " << endl; cout << "5. Talk to people listen to space news... -- not functional... " << endl; switch(input) { case 1: system("cls"); //checkMailBox(); cout << "N/A" << endl; break; case 2: system("cls"); //repairShip(); cout << "N/A" << endl; break; case 3: system("cls"); //upgradeShip(); cout << "N/A" << endl; break; case 4: system("cls"); //pickUpPassengers(); cout << "N/A" << endl; break; case 5: system("cls"); //talkToPeople(); cout << "N/A" << endl; break; case 6: system("cls"); cout << "Take Care out there in space..." << endl; break; default: cout << "You can only choose option 1-5 are not programmed, nothing else is programmed... " << endl; break; }// end of switch } // end of do while (input == 1 || input == 2 || input == 3 || input == 4 || input == 5); s.setX(s.getX()+1); s.setY(s.getY()+1); } s.setX(s.getX()+1); } // end of method