void GameState::readyToLaunch()
{
	m_game_state = STATE_READY_TO_LAUNCH;
	setPlayerMovementDirection (DIRECTION_NONE);
	s->playSound(SOUND_INTRO);
	std::cout<<"ready steady go \n";
	//setPlayerLocation(sf::Vector2f(640, 700));

	setPlayerLocation(sf::Vector2f(640, 700));
	//setPlayerLocation(sf::Vector2f(m_size_x/2-ROBOT_WIDTH/2,m_size_y/2-ROBOT_HEIGHT/2)); 
}
Example #2
0
void MetaWindow::configurePlayerMenu(){
  QMenu *playerMenu = menuBar()->addMenu(tr("&Player"));

  setLocationAction = new QAction(tr("Set &Location"), this);
  setLocationAction->setShortcut(tr("Ctrl+L"));
  playerMenu->addAction(setLocationAction);

  setPasswordAction = new QAction(tr("Set Password"), this);
  playerMenu->addAction(setPasswordAction);

  removePasswordAction = new QAction(tr("Remove Password"), this);
  playerMenu->addAction(removePasswordAction);
  removePasswordAction->setEnabled(dataStore->hasPlayerPassword());

  connect(setLocationAction, SIGNAL(triggered()), this, SLOT(setPlayerLocation()));
  connect(setPasswordAction, SIGNAL(triggered()), this, SLOT(setPlayerPassword()));
  connect(removePasswordAction, SIGNAL(triggered()), this, SLOT(removePlayerPassword()));
}
//start Minigame
void GameState::startMini()
{
	m_game_state = STATE_MINI;
	//setTotalDodgecoins(total_dodgecoins + m_dodgecoins_collected);
	m_dodgecoins_collected = 0;
	//m_dodgecoin_locations.clear();

	//std::cout << "start mini" <<std::endl;
	setPlayerMovementDirection (DIRECTION_NONE);
	setPlayerLocation(sf::Vector2f (50,700));
	
	//ADD COIN
		for (int i=0; i<10; i++)
		{
			sf::Vector2f newcoin;
			m_dodgecoin_locations.push_back(sf::Vector2f(rand()%1280,getPlayerLocation().y));
		}
	
}
GameState::GameState(int x, int y)
{
	// Initial game state
	m_game_state = STATE_MENU;

	// Size of the game area
	m_size_x = x;
	m_size_y = y;
	
	//schwerkraft
	gravity = 0.01;
	
	total_dodgecoins = 0;
	m_dodgecoins_collected = 0;
	
	//hole Soundhandler
	s = SoundHandler::getSoundHandler();
	// Set initial player movement and location
	setPlayerMovementDirection(DIRECTION_NONE);
	setPlayerLocation(sf::Vector2f(x/2-ROBOT_WIDTH/2,y/2-ROBOT_HEIGHT/2));     // ORIGINAL
	
	//setPlayerLocation(sf::Vector2f(x/2-ROBOT_WIDTH/2,700));					// BROKEN EXPERIMENTAL
	
	
	// Initialize random seed
	srand (static_cast <unsigned> (time(0)));
	
	loadUpgrades();
	
	rocket = Rocket(upgradeList);
	m_dodgecoin_locations.clear();
	
	
	rocket.updateStats();
	
	//load buttons
	button_back = Button(sf::Vector2f(100,700),sf::Vector2f(130,47),"Back","assets/menu_button.png");
	button_play = Button(sf::Vector2f(100,200),sf::Vector2f(130,47),"Play","assets/menu_button.png");
	button_credits = Button(sf::Vector2f(100,350),sf::Vector2f(130,47),"Credits","assets/menu_button.png");
	button_help = Button(sf::Vector2f(100,500),sf::Vector2f(130,47),"Help","assets/menu_button.png");
	button_quit = Button(sf::Vector2f(100,650),sf::Vector2f(130,47),"Quit","assets/menu_button.png");
	button_takeOff = Button(sf::Vector2f(1000,700),sf::Vector2f(130,47),"Launch","assets/menu_button.png");
}
Example #5
0
void doCursor()
{
	char name[MAX_VALUE_LENGTH];
	int x, y;

	cursor.x = input.mouseX;
	cursor.y = input.mouseY;

	if (cursor.type == TILES || cursor.snapToGrid == 1)
	{
		cursor.x /= TILE_SIZE;
		cursor.y /= TILE_SIZE;

		cursor.x *= TILE_SIZE;
		cursor.y *= TILE_SIZE;
	}

	if (cursor.y >= SCREEN_HEIGHT - TILE_SIZE)
	{
		cursor.y = SCREEN_HEIGHT - TILE_SIZE * 2;
	}

	if (input.left == 1)
	{
		mapStartXNext(-TILE_SIZE);
	}

	else if (input.right == 1)
	{
		mapStartXNext(TILE_SIZE);
	}

	if (input.up == 1)
	{
		mapStartYNext(-TILE_SIZE);
	}

	else if (input.down == 1)
	{
		mapStartYNext(TILE_SIZE);
	}

	if (input.snap == 1)
	{
		cursor.snapToGrid = 1 - cursor.snapToGrid;

		input.snap = 0;
	}

	if (input.activate == 1)
	{
		cursor.entity.face = (cursor.entity.face == RIGHT ? LEFT : RIGHT);

		input.activate = 0;
	}

	if (input.block == 1)
	{
		if (cursor.type == TILES)
		{
			x = (getMapStartX() + cursor.x) / TILE_SIZE;
			y = (getMapStartY() + cursor.y) / TILE_SIZE;

			while (mapTileAt(x, y) == BLANK_TILE && x >= 0)
			{
				setTileAt(x, y, cursor.tileID);

				x--;
			}

			x = (getMapStartX() + cursor.x) / TILE_SIZE;

			x++;

			while (mapTileAt(x, y) == BLANK_TILE && x < MAX_MAP_X)
			{
				setTileAt(x, y, cursor.tileID);

				x++;
			}
		}
	}

	if (input.add == 1)
	{
		if (cursor.type == TILES)
		{
			setTileAt((getMapStartX() + cursor.x) / TILE_SIZE, (getMapStartY() + cursor.y) / TILE_SIZE, cursor.tileID);
		}

		else
		{
			/* Entities can only be placed in blank spaces */

			if (isValidOnMap(&cursor.entity) == 1 && isSpaceEmpty(&cursor.entity) == NULL)
			{
				if (cursor.entityType == 0)
				{
					setPlayerLocation(getMapStartX() + cursor.x, getMapStartY() + cursor.y);
				}

				else
				{
					if (strcmpignorecase(cursor.entity.name, "lift/lift_target") == 0)
					{
						snprintf(name, sizeof(name), "NEW_TARGET_%03d", targetID);

						addTarget(getMapStartX() + cursor.x, getMapStartY() + cursor.y, name);

						targetID++;
					}

					else
					{
						cursor.entity.startX = getMapStartX() + cursor.x;
						cursor.entity.startY = getMapStartY() + cursor.y;

						cursor.entity.endX = getMapStartX() + cursor.x;
						cursor.entity.endY = getMapStartY() + cursor.y;

						addEntity(cursor.entity, getMapStartX() + cursor.x, getMapStartY() + cursor.y);
					}
				}
			}

			input.add = 0;
		}
	}

	else if (input.remove == 1)
	{
		if (cursor.type == TILES)
		{
			setTileAt((getMapStartX() + cursor.x) / TILE_SIZE, (getMapStartY() + cursor.y) / TILE_SIZE, BLANK_TILE);
		}

		else
		{
			self = isSpaceEmpty(&cursor.entity);

			if (self != NULL)
			{
				self->inUse = FALSE;
			}
		}
	}

	if (input.cut == 1)
	{
		if (cursor.type != TILES)
		{
			self = isSpaceEmpty(&cursor.entity);

			if (self != NULL)
			{
				cursor.entity = *self;

				self->inUse = FALSE;
			}
		}

		input.cut = 0;
	}

	if (input.previous == 1)
	{
		if (cursor.type == TILES)
		{
			cursor.tileID = prevTile(cursor.tileID);
		}

		else
		{
			cursor.entityType--;

			if (cursor.entityType < 0)
			{
				cursor.entityType = entityNamesLength - 1;
			}

			memset(&cursor.entity, 0, sizeof(Entity));

			cursor.entity.draw = &drawLoopingAnimationToMap;

			cursor.entity.weight = 0;

			cursor.entity.originalWeight = 0;

			cursor.entity.inUse = TRUE;

			loadProperties(entityNames[cursor.entityType], &cursor.entity);

			cursor.entity.active = TRUE;

			cursor.entity.alpha = 255;

			if (cursor.entity.weight == 0)
			{
				cursor.entity.weight = 1;

				cursor.entity.originalWeight = 1;
			}
		}

		input.previous = 0;
	}

	else if (input.next == 1)
	{
		if (cursor.type == TILES)
		{
			cursor.tileID = nextTile(cursor.tileID);
		}

		else
		{
			cursor.entityType++;

			if (cursor.entityType >= entityNamesLength)
			{
				cursor.entityType = 0;
			}

			memset(&cursor.entity, 0, sizeof(Entity));

			cursor.entity.draw = &drawLoopingAnimationToMap;

			cursor.entity.weight = 0;

			cursor.entity.originalWeight = 1;

			cursor.entity.inUse = TRUE;

			loadProperties(entityNames[cursor.entityType], &cursor.entity);

			cursor.entity.active = TRUE;

			cursor.entity.alpha = 255;

			if (cursor.entity.weight == 0)
			{
				cursor.entity.weight = 1;

				cursor.entity.originalWeight = 1;
			}
		}

		input.next = 0;
	}

	if (input.save == 1)
	{
		if (saveMap() == TRUE)
		{
			setStatusPanelMessage("Saved");
		}

		else
		{
			setStatusPanelMessage("Saving Failed");
		}

		input.save = 0;
	}
	/*
	if (input.load == 1)
	{
		loadMap(map.filename);

		printf("Loaded\n");

		input.load = 0;
	}
	*/
	if (input.left == 1 || input.right == 1 || input.up == 1 || input.down == 1)
	{
		SDL_Delay(30);
	}

	if (input.toggle == 1)
	{
		if (cursor.type == TILES)
		{
			cursor.type = ENTITIES;
		}

		else
		{
			cursor.type = TILES;
		}

		input.toggle = 0;
	}

	centerMapOnEntity(NULL);
}
Example #6
0
void MetaWindow::onPlayerLocationSetError(const QString& errMessage){
  QMessageBox::critical(this, tr("Error Setting Location"), errMessage);
  setPlayerLocation();
}
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();
	
}