main(){ //declaration char array[M][N]={0}; FILE *fptr; char c1; //your char char file_name[20]; //name of file char dir; //direction int i,j; //iterator int x,y; //map size int a,b=0; //start location int c,d=0; //end location // declaration end //getting data printf("how many rows in your map\n"); // ask for the hight of the map scanf("%d",&x); printf("how many columns in your map\n"); // ask for the width of the map scanf("%d",&y); printf("Type in the name of the file containing the Field\n"); // ask for the file with the maze scanf("%s",file_name); //end getting data fptr=fopen(file_name,"r"); // save the maze to fptr for (i=0; i<x; i++){ // inputs the maze in to an array for (j=0; j<y; j++){ c1=fgetc(fptr); while ( !((c1 == '1')||(c1 =='0')) )c1=fgetc(fptr); array[i][j]=c1; } } //end maze set up fclose(fptr); printMaze(array,x,y); startEnd(array,&a,&b,&c,&d,x,y); dir=enter(a,b,x,y); traverse (array,a,b,c,d,dir); printMaze(array,x,y); }
void GameState::updateGameState() { // Do nothing if the game is not in playing state if(m_game_state == STATE_MENU) { //s->setBgVolume(0); s->playSound(SOUND_INTRO); } else if (m_game_state == STATE_SHOP) { //s->playSound(SOUND_INTRO); } else if(m_game_state == STATE_PLAYING) { // Update the player location sf::Vector2f delta; switch(m_player_direction) { case DIRECTION_LEFT: delta = sf::Vector2f(-5,0); m_velocity -= gravity/(rocket.aerodynamic/10); break; case DIRECTION_RIGHT: delta = sf::Vector2f(5,0); m_velocity -= gravity/(rocket.aerodynamic/10); break; default: delta = sf::Vector2f(0,0); break; } delta.y -= m_velocity; m_velocity -= gravity; // Apply delta to the player position sf::Vector2f new_location(getPlayerLocation() + delta); // Check if new position is inside the game area if(new_location.x < 0) { new_location.x = 0; } else if(new_location.x + ROBOT_WIDTH >= m_size_x) { new_location.x = m_size_x - ROBOT_WIDTH; } setPlayerLocation(new_location); // Update location if(new_location.y < 0 && m_velocity < 0) { setTotalDodgecoins(total_dodgecoins + m_dodgecoins_collected); m_dodgecoins_collected =0; setPlayerLocation(sf::Vector2f(m_size_x/2-ROBOT_WIDTH/2,m_size_y/2-ROBOT_HEIGHT/2)); // Reset Player Location std::cout << "totalcoins: " << total_dodgecoins <<std::endl; startShop(); } else if ((getPlayerLocation().y/100)*-1 >= 2500 && rocket.coolness >= 9000) // Aus Präsentationsgründen auf 500 gesetzt, normal 2000 { startEnd(); } // Bounding box of the player sf::FloatRect player_box(getPlayerLocation(),sf::Vector2f(ROBOT_WIDTH,ROBOT_HEIGHT)); //ADD COIN addDodgecoin(); //add meteor addMeteor(); std::vector<sf::Vector2f>::iterator s_it; s_it = m_dodgecoin_locations.begin(); // Check for each coin location ... while(s_it != m_dodgecoin_locations.end()) { // ... if the rocket is collecting the coin sf::FloatRect dodgecoin_box(*s_it,sf::Vector2f(COIN_WIDTH,COIN_HEIGHT)); if(dodgecoin_box.intersects(player_box)) { // Remove coin m_dodgecoin_locations.erase(s_it); m_dodgecoins_collected++; } else { // Advance iterator to next coin s_it++; } } s_it = m_meteor_locations.begin(); // Check for each meteor location ... while(s_it != m_meteor_locations.end()) { // ... if the rocket is colliding the meteor sf::FloatRect meteor_box(*s_it,sf::Vector2f(80,80)); if(meteor_box.intersects(player_box)) { // Remove meteor m_meteor_locations.erase(s_it); m_velocity -= 50*gravity; } else { // Advance iterator to next coin s_it++; } } } else if(m_game_state == STATE_MINI) { // Update the player location sf::Vector2f delta; switch(m_player_direction) { case DIRECTION_LEFT: delta = sf::Vector2f(-5,0); break; //std::cout << "leftmini" <<std::endl; case DIRECTION_RIGHT: delta = sf::Vector2f(5,0); break; //std::cout << "rightmini" <<std::endl; case DIRECTION_UP: delta = sf::Vector2f(0,0); break; case DIRECTION_DOWN: delta = sf::Vector2f(0,0); break; default: delta = sf::Vector2f(0,0); break; } // Apply delta to the player position sf::Vector2f new_location(getPlayerLocation() + delta); // Check if new position is inside the game area if(new_location.x >= 0 && new_location.x + ROBOT_WIDTH <= m_size_x) { setPlayerLocation(new_location); // Update location //std::cout << "neue position??" << std::endl; } if(new_location.x >=1200) { setTotalDodgecoins(total_dodgecoins + m_dodgecoins_collected); m_dodgecoins_collected =0; startShop(); } // Bounding box of the player sf::FloatRect player_box(getPlayerLocation(),sf::Vector2f(ROBOT_WIDTH,ROBOT_HEIGHT)); std::vector<sf::Vector2f>::iterator s_it; s_it = m_dodgecoin_locations.begin(); // Check for each coin location ... while(s_it != m_dodgecoin_locations.end()) { // ... if the nils is collecting the coin sf::FloatRect dodgecoin_box(*s_it,sf::Vector2f(COIN_WIDTH,COIN_HEIGHT)); if(dodgecoin_box.intersects(player_box)) { // Remove coin m_dodgecoin_locations.erase(s_it); m_dodgecoins_collected++; //std::cout << "coooooooooooooiiiiin" << std::endl; //setTotalDodgecoins(total_dodgecoins + m_dodgecoins_collected); std::cout << "totalcoins: " << total_dodgecoins <<std::endl; std::cout << "collectedcoins: " << m_dodgecoins_collected <<std::endl; } else { // Advance iterator to next coin s_it++; } } } else if(m_game_state == STATE_CREDITS) { } else if (m_game_state == STATE_END) { } else // Do nothing if the game is not in mini state { return; } //startEnd(); }