예제 #1
0
void setView_Scroll(sf::View &view, Character &character, gameMap &map)
{
    float height = view.getSize().y;
    float width  = view.getSize().x;
    float maxW = map.getWidth()*(map.getTile(0).getTileDims().x);
    float maxH = map.getHeight()*(map.getTile(0).getTileDims().y);
    float newX = 0;
    float newY = 0;

    if(character.getPosition().x < width/2)
    {
        newX = width/2;
    }else if(character.getPosition().x > maxW - width/2)
    {
        newX  = maxW - width/2;
    }else
    {
        newX = round(character.getPosition().x);
    }
        if(character.getPosition().y < height/2)
    {
        newY = height/2;
    }else if(character.getPosition().y > maxH - height/2)
    {
        newY  = maxH - height/2;
    }else
    {
        newY = round(character.getPosition().y);
    }
    view.setCenter(newX, newY);
}
예제 #2
0
void Game::HandleView(sf::View &view, sf::View &static_view, sf::RenderWindow &window){
	if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
		view.move(0, -16);
	if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
		view.move(-16, 0);
	if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
		view.move(0, 16);
	if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
		view.move(16, 0);
		
	window.setView(static_view);
	money_text.setString("Money: " + SSTR(values.Money()));
    window.draw(money_text);
    static bool help_toggled = true;
    static bool key_released = true;
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::H) and key_released == true){
    		help_toggled = !help_toggled;
    		key_released = false;
    }else if(!sf::Keyboard::isKeyPressed(sf::Keyboard::H))
    	key_released = true;
    if(help_toggled){
    	help_text.setString("building price: " + SSTR(values.BuildingPrice()) + "\nclaim & upgrade price = 10\nmoney cap = " + SSTR(values.MoneyCap()) + "\n\nc = claim\nr = build resource\nb = build bank\nu = improve\np = sell for 10\n\ntoggle help = h");
    	window.draw(help_text);
    }
}
예제 #3
0
void GameCompleteScreen::setup(sf::View view
							   , int sheepHerded)
{
	mBackground.setPosition(view.getCenter());

	sf::Vector2f textPos(view.getCenter());

	float fontSize = mTitleText.getCharacterSize();
	textPos.y -= fontSize;
	mTitleText.setPosition(textPos);
	textPos.y += fontSize;

	mSheepStatText.setString("Sheep Herded " + std::to_string(sheepHerded));
	sf::FloatRect bounds = mSheepStatText.getLocalBounds();
	mSheepStatText.setOrigin(bounds.width / 2.f
							, 0.f);

	fontSize = mSheepStatText.getCharacterSize();
	mSheepStatText.setPosition(textPos);
	textPos.y += fontSize;

	int inc = mMenuText.at(0).getCharacterSize();

	textPos.y += inc;

	for(sf::Text& text : mMenuText)
	{
		text.setPosition(textPos);
		textPos.y += inc;
	}
}
예제 #4
0
파일: Minimap.cpp 프로젝트: choltfo/RTSGame
void Minimap::DrawTheMinimap(sf::RenderWindow& window, Game& game, sf::View view)
{
	if (ShouldBeUpdated)
	{
		UpdateTheMinimap(game.map);
		ShouldBeUpdated = false;
	}

	MinimapSprite.setPosition(sf::Vector2f(window.getSize().x - 200.f, 50.f));
	window.draw(MinimapSprite);

	MinimapBackground.setPosition(sf::Vector2f(window.getSize().x - 200.f, 50.f));
	

	window.draw(MinimapBackground);
	
	for (int j = 0; j < game.MOBs.size(); j++)
	{
		AllyMobSprite.setPosition(sf::Vector2f(game.MOBs[j]->position.x * MINIMAP_WIDTH / MAP_DIM / TEX_DIM + window.getSize().x - 200.f - 4, game.MOBs[j]->position.y * MINIMAP_WIDTH / MAP_DIM / TEX_DIM + 50.f));
		window.draw(AllyMobSprite);
	}
	for (int j = 0; j < game.structures.size(); j++)
	{
		AllyPlantSprite.setPosition(sf::Vector2f(game.structures[j].position.x * MINIMAP_WIDTH / MAP_DIM + window.getSize().x - 200.f - 4, game.structures[j].position.y * MINIMAP_WIDTH / MAP_DIM + 50.f));
		window.draw(AllyPlantSprite);
	}

	sf::Vector2f ViewSize = view.getSize();
	sf::Vector2f ViewCornerPosition = view.getCenter() - ViewSize / 2.0f;
	MinimapFOVIndicator.setPosition(ViewCornerPosition.x * MINIMAP_WIDTH / MAP_DIM / TEX_DIM + window.getSize().x - 200.f, ViewCornerPosition.y * MINIMAP_WIDTH / MAP_DIM / TEX_DIM + 50.f);
	MinimapFOVIndicator.setSize(sf::Vector2f(ViewSize.x * MINIMAP_WIDTH / MAP_DIM / TEX_DIM, ViewSize.y * MINIMAP_WIDTH / MAP_DIM / TEX_DIM));
	window.draw(MinimapFOVIndicator);

}
예제 #5
0
RuntimeCamera::RuntimeCamera(sf::View & view) :
    originalWidth(view.getSize().x),
    originalHeight(view.getSize().y),
    angle(0),
    zoomFactor(1)
{
    sfmlView = view;
}
예제 #6
0
파일: hud.hpp 프로젝트: K0teu/Squares-War
 void rysuj_tekst( sf::RenderWindow & okno, sf::String _tresc, float x, float y )
 {
     double kamera_xHud = kamera.getCenter().x - kamera.getSize().x/2;
     double kamera_yHud = kamera.getCenter().y - kamera.getSize().y/2;
     tekst.setString( _tresc );
     tekst.setPosition( kamera_xHud + x, kamera_yHud + y );
     okno.draw( tekst );
 }
예제 #7
0
        sf::Vector2f getViewPosition(sf::View& view)
        {
            sf::Vector2f center = view.getCenter();

            sf::Vector2f half   = view.getSize() / 2.0f;

            return center - half;
        }
예제 #8
0
    void LightSystem::setView(const sf::View& view)
    {
        _renderTexture.create(view.getSize().x,view.getSize().y);
        _buffer.create(view.getSize().x,view.getSize().y);

        _sprite.setTexture(_renderTexture.getTexture(),true);
        _bufferSprite.setTexture(_buffer.getTexture(),true);
    }
예제 #9
0
파일: hud.hpp 프로젝트: K0teu/Squares-War
 void aktualizuj_hud()
 {
     aktualizuj_kamere();
     double kamera_xHud = kamera.getCenter().x - kamera.getSize().x/2;
     double kamera_yHud = kamera.getCenter().y - kamera.getSize().y/2;
     ustaw_pozycjePaskaHp( kamera_xHud+10 , kamera_yHud + 5 );
     ustaw_pozycjePaskaBonusu( kamera_xHud+30 , kamera_yHud + 440 );
     aktualizuj_timer( 1 );
 }
예제 #10
0
void Map::Drawbackground(sf::View& ViewRef, E_Ground Ground)
{
	int MinX, MaxX, MinY, MaxY;
	if (WCR.inMapMaker)
	{
		MinX = (int)((WCR.MMPtr->MapMakrView.getCenter().x - (WCR.MMPtr->MapMakrView.getSize().x / 2)) / CellSize);
		MaxX = (int)((WCR.MMPtr->MapMakrView.getCenter().x + (WCR.MMPtr->MapMakrView.getSize().x / 2)) / CellSize);
		MinY = (int)((WCR.MMPtr->MapMakrView.getCenter().y - (WCR.MMPtr->MapMakrView.getSize().y / 2)) / CellSize);
		MaxY = (int)((WCR.MMPtr->MapMakrView.getCenter().y + (WCR.MMPtr->MapMakrView.getSize().y / 2)) / CellSize);
	}
	else
	{
		MinX = (int)((ViewRef.getCenter().x - ViewRef.getSize().x / 2) / CellSize);
		MaxX = (int)((ViewRef.getCenter().x + ViewRef.getSize().x / 2) / CellSize);
		MinY = (int)((ViewRef.getCenter().y - ViewRef.getSize().y / 2) / CellSize);
		MaxY = (int)((ViewRef.getCenter().y + ViewRef.getSize().y / 2) / CellSize);
	}
	WCR.LimitVariable(0, MapWidth - 1, MinX);
	WCR.LimitVariable(0, MapWidth - 1, MaxX);
	WCR.LimitVariable(0, MapHeight - 1, MinY);
	WCR.LimitVariable(0, MapHeight - 1, MaxY);
	for (int LID = 0; LID < BackgroundMatrix.size(); LID++)
	{
		if (WCR.MMPtr->OnlyShowThisLayer->IsActive() && WCR.inMapMaker && OrderedBackgroundLayers[LID] != WCR.MMPtr->curTileLayer)
			continue;//Skip, not the layer we want.
		int BL_ = BackgroundLayers[OrderedBackgroundLayers[LID]];
		if (Ground == E_vForeground)
		{
			if (BL_ >= 0)
				continue;//Not up to yet
		}
		else if (Ground == E_vMiddleground)
		{
			if (BL_ < 0)
				break;//Gone past
			if (BL_ != 0)
				continue;//Go till found.
		}
		else if (Ground == E_vBackground)
		{
			if (BL_ < 1)
				break;//Gone past
		}
		
		BL_ = OrderedBackgroundLayers[LID];
		for (int i = MinX; i <= MaxX; i++)
			for (int ii = MinY; ii <= MaxY; ii++)
			{
				if (BackgroundMatrix[BL_][i][ii].tileID != -1)//Not empty space.
				{
					WCR.MMPtr->TileSets[BackgroundMatrix[BL_][i][ii].tileSetID].Tiles[BackgroundMatrix[BL_][i][ii].tileID].setPosition(i * CellSize, ii * CellSize);
					WCR.RenderRef.draw(WCR.MMPtr->TileSets[BackgroundMatrix[BL_][i][ii].tileSetID].Tiles[BackgroundMatrix[BL_][i][ii].tileID]);
				}
			}
	}
}
예제 #11
0
파일: Level.cpp 프로젝트: alienjon/Escape-
void Level::logic(sf::View& camera, unsigned int delta)
{
	// Perform actions.
	ActionInterface::logic(*this);

	// Remove all dead entities.
	for(list<Entity*>::iterator it = mDeadEntities.begin(); it != mDeadEntities.end(); it++)
		mRemoveEntity(*it);
	mDeadEntities.clear();

    // Perform all entity logic.
	for(list<Entity*>::iterator it = mEntities.begin(); it != mEntities.end(); it++)
		(*it)->logic(*this, delta);

    // If all items have been picked up, display a floating text and give a bonus.
    if(mPickups.empty() && !mPickupAward)
    {
    	addFloatingText("Level Cleared!", mPlayer.getPosition(), sf::Color::Yellow, 30);
    	distributeChangeScore(250);
    	mPickupAward = true;
    }

    // Perform floating text logic if the interval is passed.
    if(mFloatingTextTimer.getTime() >= FLOATINGTEXT_TIMER_INTERVAL)
    {
    	list<list<sf::Text>::iterator > removeList;
    	for(list<sf::Text>::iterator it = mFloatingTexts.begin(); it != mFloatingTexts.end(); ++it)
    	{
    		it->move(0, -FLOATINGTEXT_MOVE_STEP);
    		sf::Color c = it->getColor();
    		it->setColor(sf::Color(c.r, c.g, c.b, c.a - 3));
    		if(it->getColor().a == 0)
    			removeList.push_back(it);
    	}
    	for(list<list<sf::Text>::iterator >::iterator it = removeList.begin(); it != removeList.end(); ++it)
    		mFloatingTexts.erase(*it);
    	mFloatingTextTimer.start();
    }

	// Center the player on the screen.
	camera.setCenter(mPlayer.getX() + (mPlayer.getWidth() / 2), mPlayer.getY() + (mPlayer.getHeight() / 2));

	// Make sure that the camera doesn't go out of bounds.
	sf::Vector2f center = camera.getCenter(),
				 half(camera.getSize().x / 2, camera.getSize().y / 2);
	if(center.x - half.x < 0)
		center.x = half.x;
	if(center.x + half.x > mMap.getWidth())
		center.x = mMap.getWidth() - half.x;
	if(center.y - half.y < 0)
		center.y = half.y;
	if(center.y + half.y > mMap.getHeight())
		center.y = mMap.getHeight() - half.y;
	camera.setCenter(center);
}
예제 #12
0
파일: hud.hpp 프로젝트: K0teu/Squares-War
 void credits( sf::RenderWindow & okno )
 {
     sf::RectangleShape tlo_credits;
     tlo_credits.setFillColor( sf::Color::Black );
     tlo_credits.setPosition( kamera.getCenter().x - kamera.getSize().x/2,
                              kamera.getCenter().y - kamera.getSize().y/2 );
     tlo_credits.setSize( sf::Vector2f( 640, 480 ) );
     okno.draw( tlo_credits );
     rysuj_tekst( okno, "Square War Alpha 0.9", 320, 20 );
     rysuj_tekst( okno, "Autorzy:\nOlek Szatko\nMarcin Kula\nRafal Kot", 320, 240 );
 }
예제 #13
0
파일: sfUtil.cpp 프로젝트: Oberon00/jd
sf::FloatRect viewRect(sf::View const& view)
{
    sf::Vector2f const viewCenter(view.getCenter());
    sf::Vector2f const viewSize(view.getSize());
    sf::FloatRect const viewRect(
        viewCenter.x - viewSize.x / 2,
        viewCenter.y - viewSize.y / 2,
        viewSize.x,
        viewSize.y);
    return viewRect;
}
예제 #14
0
sf::FloatRect Helper::getViewBounds(const sf::View &view)
{
    sf::FloatRect rt;
    rt.left = view.getCenter().x - view.getSize().x/2;
    rt.top  = view.getCenter().y - view.getSize().y/2;
    rt.width  = view.getSize().x;
    rt.height = view.getSize().y;

//    std::cout << "View bounds" << rt.left << " " << rt.top << " " << rt.width << " " << rt.height << std::endl;

    return rt;
}
예제 #15
0
파일: Screen.cpp 프로젝트: G-GFFD/Cendric2
inline bool isInsideView(const sf::View& targetView, const sf::FloatRect& boundingBox)
{
	sf::FloatRect view(targetView.getCenter().x - targetView.getSize().x / 2.f,
		targetView.getCenter().y - targetView.getSize().y / 2.f,
		targetView.getSize().x,
		targetView.getSize().y);

	view.left -= VIEW_MARGIN;
	view.top -= VIEW_MARGIN;
	view.width += 2 * VIEW_MARGIN;
	view.height += 2 * VIEW_MARGIN;
	return view.intersects(boundingBox);
}
예제 #16
0
int main(int argc, char** argv)
{
	fcnt = 0;
	speed = 0.5;
	gen = 1;
	evolution_rate = 10;
	counter = 300;
	bestavg = 0;
	decline_counter = 0;
	srand(time(0));
	camera.setSize(800,600);
	camera.setCenter(AREA_W/2,AREA_H/2);
	sf::ContextSettings settings;
	settings.antialiasingLevel = 8;
	window = new sf::RenderWindow(sf::VideoMode(SCREEN_W,SCREEN_H),"Evolution 0.3",sf::Style::Default,settings);
	window->setFramerateLimit(60);
	window->setView(camera);
	bg.setOutlineColor(sf::Color::Cyan);
	bg.setOutlineThickness(4.f);
	bg.setFillColor(sf::Color(51,153,153));
	sf::CircleShape* tmp;
	tmp = new sf::CircleShape(15.f,5);
	tmp->setOutlineColor(sf::Color::Red);
	tmp->setFillColor(sf::Color(75,75,75));
	tmp->setOutlineThickness(2.f);
	tmp->setOrigin(tmp->getLocalBounds().width/2,tmp->getLocalBounds().height/2);
	fToken = tmp;
	sf::Font font;
	font.loadFromFile("revalia.ttf");
	text = new sf::Text();
	text->setFont(font);
	text->setCharacterSize(15.f);
	text->setColor(sf::Color::White);
	vpop = new VectorPopulation();
	vpop->setMutationScale(current_mutation_rate);
	for(int i = 0; i<CREATURE_CAP; i++) {
		creatures.push_back(std::shared_ptr<Creature>(new Creature(4,2,1,6)));
		creatures.back()->setPos(sf::Vector2f(10 + rand() % (AREA_W-20), 10 + rand() % (AREA_H-20)));
		creatures.back()->areaSize(AREA_W,AREA_H);
		creatures.back()->setSpeed(3);
	}
	for(int i = 0; i<FOOD_CAP; i++) {
		food.push_back(sf::Vector2f(20 + rand() % (AREA_W-40), 10 + rand() % (AREA_H-20)));
	}

	while(update()) {
		render();
	}
	return 0;
}
예제 #17
0
void BonusesPanelUpdate(BonusesPanel& panel, sf::View view) {
	float view_top = view.getCenter().y - view.getSize().y / 2.f;
	float view_left = view.getCenter().x - view.getSize().x / 2.f;
	panel.sprite.setPosition(view_left + PanelXPos, view_top + PanelYPos);
	sf::FloatRect panel_box = panel.sprite.getGlobalBounds();
	float cell_x = panel_box.left + PanelLeftBorderWidth;
	float cell_y = panel_box.top + PanelTopBorderHeight;
	float delimeter = 0;
	for (size_t i = 0; i < panel.items->size(); i++) {
		if (i != 0) {
			delimeter = CellDelimeterHeight;
		}
		panel.items[0][i]->visual->sprite.setPosition(cell_x, cell_y + (CellHeight * i) + delimeter);
	}
}
예제 #18
0
void Interface::update(sf::View v)
{
	//Positions the text relative to the view:
	_text[CLOCK].setPosition(
		((v.getCenter().x - (v.getSize().x / 2)) + 5),  //X
		((v.getCenter().y - (v.getSize().y / 2)) + 5)); //Y

	_text[CLOCK_BESTTIME].setPosition(
		(_text[CLOCK].getPosition().x), //X
		(_text[CLOCK].getPosition().y + (_text[CLOCK].getGlobalBounds().height + 2))); //Y	

	_text[FPS].setPosition(
		((v.getCenter().x + (v.getSize().x / 2)) - (_text[FPS].getGlobalBounds().width + 5)),   //X
		((v.getCenter().y + (v.getSize().y / 2)) - (_text[FPS].getGlobalBounds().height + 5))); //Y
}
예제 #19
0
파일: hud.hpp 프로젝트: K0teu/Squares-War
        void aktualizuj_kamere()
        {
            kamera.setCenter( gracz->zwroc_wsp().x, gracz->zwroc_wsp().y);
//            if( gracz->dmg_krytyczny ){
//                ::przyblizenie = 0.9;
//                gracz->dmg_krytyczny = false;
//            }

//            if( przyblizenie < 1 )
//                przyblizenie += 0.00000000000001;
//            if( przyblizenie > 1 )
//                przyblizenie = 1;

            kamera.zoom( przyblizenie );
        }
예제 #20
0
sf::View Spaceinium::getViewportBox(sf::View view, int windowWidth,
		int windowHeight) {

	float windowRatio = windowWidth / (float) windowHeight;
	float viewRatio = 1.77777777778;
	float sizeX = 1;
	float sizeY = 1;
	float posX = 0;
	float posY = 0;

	bool horizontalSpacing = true;
	if (windowRatio < viewRatio)
		horizontalSpacing = false;

	if (horizontalSpacing) {
		sizeX = viewRatio / windowRatio;
		posX = (1 - sizeX) / 2.0;
	}

	else {
		sizeY = windowRatio / viewRatio;
		posY = (1 - sizeY) / 2.0;
	}

	view.setViewport(sf::FloatRect(posX, posY, sizeX, sizeY));

	return view;
}
예제 #21
0
void updateView(sf::View& view, sf::Time& deltaTime) {
	float dx = 0;
	float dy = 0;

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
		dx -= 1;
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
		dx += 1;
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) || sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
		dy -= 1;
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) || sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
		dy += 1;
	}

	float moveSpeed = 1000;
	float timeSeconds = deltaTime.asSeconds();

	float dd = dx * dx + dy * dy;
	if (dd != 0) {
		dd = sqrt(dd);
		dx /= dd;
		dy /= dd;
	}

	dx *= moveSpeed;
	dy *= moveSpeed;

	view.move(dx * timeSeconds, dy * timeSeconds);
}
예제 #22
0
void Level::update(double delta, sf::Event& evt, sf::View& v)
{

	if(ltype == Menu)
	{
		//if spacebar is pressed in menu, start game
		if(evt.type == sf::Event::KeyPressed)
			if(evt.key.code == sf::Keyboard::Space)
				setLevel(Stage1);
	} else {
		//step an iteration of box2d world
		b2world->Step(delta/1000, 8, 3);

		//set view
		//remember to change from first dynamic entity to the player position
		
		v.setCenter(player->anim.xpos+20, player->anim.ypos+30);

		//iterate through dentity list and update
		auto itr = dentitylist.begin();
		for(itr; itr != dentitylist.end(); ++itr)
		{
			(*itr)->update(delta);
		}
	
		//update player
		player->Player::update(evt, delta);

		//update enemies
	}
}
/* ----------------------------------------------------------------------
 * Author: Julian
 * Date: 25 March 2014
 * Description: Renders the light manager
 * ----------------------------------------------------------------------
 */
void LightManager::render(const sf::View& camera)
{
	// Set the view of the camera
	sf::Vector2f cameraPos(camera.getCenter() - sf::Vector2f(context.window->getSize() / 2u));
	context.window->setView(camera);

	// Clear the window to see light only
	//context.window->clear(sf::Color::White);

	// Clear the light texture
	lightTexture.clear();

	// Render all the lights
	for(auto&& light : lightList)
		light.render(camera, lightTexture);

	// Render the dusk color over the light texture
	sf::RectangleShape shape(sf::Vector2f(context.window->getSize()));
	shape.setFillColor(duskColor);
	lightTexture.draw(shape);

	// Render the light texture on the rest of the window with BlendMultiply!
	lightTexture.display();
	sf::Sprite sprite(lightTexture.getTexture());
	sprite.setPosition(cameraPos);
	context.window->draw(sprite, sf::BlendMultiply);
}
예제 #24
0
void draw(){
  _window.Clear();
  
  {
    sf::Rect<float> frect = sf::Rect<float>(0,0,window_width,window_height);
    _camera.SetFromRect(frect);
  }
  
  _window.Draw(_backgroundSprite);
  
  
  // draw the range shade
  _rangeSprite.SetPosition(current_pose.x + window_width/2, window_height/2 - current_pose.y);
  _window.Draw(_rangeSprite);
  
  // draw the landmarks
  for(unsigned int i=0; i<landmarks.size(); i++){
    _landmarkSprite.SetPosition(landmarks[i].x + window_width/2, window_height/2 - landmarks[i].y);
    _window.Draw(_landmarkSprite);
  }

  // draw the robot
  _robotSprite.SetPosition(current_pose.x + window_width/2, window_height/2 - current_pose.y);
  _robotSprite.SetRotation(current_pose.theta * 180 / M_PI);
  _window.Draw(_robotSprite);
  
  // draw the "other" robot
  _fakeRobotSprite.SetPosition(fake_current_pose.x + window_width/2, window_height/2 - fake_current_pose.y);
  _fakeRobotSprite.SetRotation(fake_current_pose.theta * 180 / M_PI);
  _window.Draw(_fakeRobotSprite);
  
  // display everything
  _window.Display();
}
예제 #25
0
void set_up(sf::RenderWindow& window, sf::View& view, sf::Text& winner, std::list<Cycle*>& player)
{
	sf::Vector2u size = window.getSize();
	if (size.x * 3 < size.y * 4)
	{
		view.setSize(v2f(800, (800.f * size.y) / size.x));
		window.setView(view);
	}
	else if (size.x * 3 > size.y * 4)
	{
		view.setSize(v2f((600.f * size.x) / size.y, 600.f));
		window.setView(view);
	}
	for (auto p : player)
		p->set_text_pos(view.getCenter());
	winner.setPosition(view.getCenter());
}
예제 #26
0
void Renderer::setView(sf::View const& view)
{
    m_renderer->setView(view);
    m_screenRect = m_renderer->getViewport(view);
    auto center = view.getCenter();
    m_screenRect.left = center.x - m_screenRect.width / 2.f;
    m_screenRect.top = center.y - m_screenRect.height / 2.f;
}
예제 #27
0
 sf::Color LightSystem::getLightMapPixel(const sf::View& view, unsigned int x, unsigned int y)
 {
     sf::Image lightMap = getLightMap();
     x -= view.getViewport().left;
     y -= view.getViewport().top;
     if(x>=0&&y>=0&&x<lightMap.getSize().x&&y<lightMap.getSize().y) return lightMap.getPixel(x,y);
     else return sf::Color::Black;
 }
예제 #28
0
	// Function to setup the OpenGL view according to the passed parameter
	void SetupOpenGL2DView(const sf::View& view)
	{
		sf::Vector2f size = view.GetSize();
		sf::Vector2f center = view.GetCenter();
		sf::Vector2f position = center - size / 2.f;
	
		// Edit the OpenGL projection matrix
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
	
		// Setup translation (according to left-upper corner) and scale
		glOrtho(0., size.x, size.y, 0., -1., 1.);
		glTranslatef(-position.x, -position.y, 0.f);
	
		// Setup rotation 
		glTranslatef(center.x, center.y, 0.f);
		glRotatef(view.GetRotation(), 0.f, 0.f, -1.f);
		glTranslatef(-center.x, -center.y, 0.f);
	}
예제 #29
0
void RocketSFMLRenderer::Resize()
{
	MyWindow->SetActive(true);
	//MyWindow->SaveGLStates();

	static sf::View View;
	//View.SetFromRect(sf::FloatRect(0, (float)MyWindow->GetWidth(), (float)MyWindow->GetHeight(), 0));
	View.SetViewport(sf::FloatRect(0, (float)MyWindow->GetWidth(), (float)MyWindow->GetHeight(), 0));
	MyWindow->SetView(View);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, MyWindow->GetWidth(), MyWindow->GetHeight(), 0, -1, 1);
	glMatrixMode(GL_MODELVIEW);

	glViewport(0, 0, MyWindow->GetWidth(), MyWindow->GetHeight());

	//MyWindow->RestoreGLStates();
};
예제 #30
0
void Player::progress(float frame, sf::View &view1){

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
        view1.move(-SPEED*frame, 0);
        player.move(-SPEED*frame, 0);
    }
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
        view1.move(SPEED*frame, 0);
        player.move(SPEED*frame, 0);
    }
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
        view1.move(0, -SPEED*frame);
        player.move(0, -SPEED*frame);
    }
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
        view1.move(0, SPEED*frame);
        player.move(0, SPEED*frame);
    }
}