Esempio n. 1
0
RuntimeCamera::RuntimeCamera(sf::View & view) :
    originalWidth(view.getSize().x),
    originalHeight(view.getSize().y),
    angle(0),
    zoomFactor(1)
{
    sfmlView = view;
}
Esempio n. 2
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);
    }
Esempio n. 3
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]);
				}
			}
	}
}
Esempio n. 4
0
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);
}
Esempio n. 5
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;
}
Esempio n. 6
0
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);
}
Esempio n. 7
0
void drawInViewSprites(sf::RenderWindow &window, sf::View &view,gameMap &map, std::vector< std::vector < sf::Sprite > > &sprites )
{
    int leftX = floor((view.getCenter().x - view.getSize().x/2)/(map.getTile(0).getTileDims().x));
    int rightX = ceil((view.getCenter().x + view.getSize().x/2)/(map.getTile(0).getTileDims().x));
    int upY = floor((view.getCenter().y - view.getSize().y/2)/(map.getTile(0).getTileDims().y));
    int downY = ceil((view.getCenter().y + view.getSize().y/2)/(map.getTile(0).getTileDims().y));
for(int y = upY; y<downY; y++)
{
    for(int x = leftX; x<rightX; x++)
    {
        window.draw(sprites[y][x]);
    }
}
}
Esempio n. 8
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
}
Esempio n. 9
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);
	}
}
Esempio n. 10
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);
}
Esempio n. 11
0
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);

}
Esempio n. 12
0
        sf::Vector2f getViewPosition(sf::View& view)
        {
            sf::Vector2f center = view.getCenter();

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

            return center - half;
        }
Esempio n. 13
0
 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 );
 }
Esempio n. 14
0
 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 );
 }
Esempio n. 15
0
 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 );
 }
Esempio n. 16
0
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;
}
Esempio n. 17
0
RuntimeCamera::RuntimeCamera(gd::Camera & camera, const sf::View & defaultView) :
    originalWidth(defaultView.getSize().x),
    originalHeight(defaultView.getSize().y),
    angle(0),
    zoomFactor(1)
{
    sfmlView = defaultView;
    if ( !camera.UseDefaultViewport() ) {
        sfmlView.setViewport(sf::FloatRect(camera.GetViewportX1(),
                                           camera.GetViewportY1(),
                                           camera.GetViewportX2()-camera.GetViewportX1(),
                                           camera.GetViewportY2()-camera.GetViewportY1()));
    }


    if ( !camera.UseDefaultSize() ) {
        originalWidth = camera.GetWidth();
        originalHeight = camera.GetHeight();
        sfmlView.setSize(sf::Vector2f(originalWidth, originalHeight));
    }
}
Esempio n. 18
0
void gridLine(sf::View view, float xSep, float ySep, sf::Color c, std::vector<sf::Vertex> &Line) {
	float Left = view.getCenter().x - view.getSize().x / 2;
	float Right = view.getCenter().x + view.getSize().x / 2;
	float Top = view.getCenter().y - view.getSize().y / 2;
	float Bottom = view.getCenter().y + view.getSize().y / 2;
	int noOfLinesX = Right / xSep - (Left - fmod(Left, xSep)) / xSep + 1;
	int noOfLinesY = Bottom / ySep - (Top - fmod(Top, ySep)) / ySep + 1;
	float x = Left - fmod(Left, xSep);
	for(int i = 0; i < noOfLinesX; i++) {
		Line.emplace_back(sf::Vector2f(x, Top), c);
		Line.emplace_back(sf::Vector2f(x, Bottom), c);
		x += xSep;
	}
	x = Top - fmod(Top, ySep);
	for(int i = 0; i < noOfLinesY; i++) {
		Line.emplace_back(sf::Vector2f(Left, x), c);
		Line.emplace_back(sf::Vector2f(Right, x), c);
		x += ySep;
	}
//	window.draw(&Line[0], Line.size(), sf::Lines);
}
Esempio n. 19
0
void Tilemap::update(const sf::View& view, int margin)
{
	sf::IntRect newView((view.getCenter().x - (view.getSize().x / 2.f)) / tilesize,
						(view.getCenter().y - (view.getSize().y / 2.f)) / tilesize,
						(view.getSize().x) / tilesize,
						(view.getSize().y) / tilesize); // @TODO Handle rotations & all the shizzle because SFML.

	sf::IntRect maprect(0, 0, wid, hei);

	newView = clip(newView, maprect);

	const sf::Vector2i topleft(newView.left, newView.top),
			           bottomright(newView.left + newView.width, newView.top + newView.height);
	if (wasTilemapChanged || !vboview.contains(topleft) || !vboview.contains(bottomright)) // if a VBO update is required
	{
		vboview = sf::IntRect(newView.left - margin,
				              newView.top - margin,
				              newView.width + (margin * 2),
				              newView.height + (margin * 2));
		vboview = clip(vboview, maprect);

		vbo = buildVertexArray(vboview);
	}
}
Esempio n. 20
0
void MeshScene::SetView(const sf::View& view)
{
	//we only want to do this if the aspect ratio has changed
	//to avoid unnecessary calls to tan
	const float aspect = view.getSize().x / view.getSize().y;
	if (m_camera->GetAspectRatio() != aspect)//potentially rendered moot by float comparison...
	{
		m_camera->SetAspectRatio(aspect);
		const float angle = std::tan(m_camera->GetFOV() / 2.f * 0.0174532925f);
		m_cameraZ = (static_cast<float>(view.getSize().y) / 2.f) / angle;
		m_cameraZ *= -m_sceneScale;
	}
	//set position
	m_camera->SetPosition(-view.getCenter().x * m_sceneScale,
						view.getCenter().y * m_sceneScale,
						m_cameraZ);

	//update viewport
	sf::Vector2u winSize = m_renderWindow.getSize();
	GLuint x = static_cast<GLuint>(view.getViewport().left * static_cast<float>(winSize.x));
	GLuint y = static_cast<GLuint>((1.f - view.getViewport().top) * static_cast<float>(winSize.y));
	GLuint w = static_cast<GLuint>(view.getViewport().width * static_cast<float>(winSize.x));
	GLuint h = static_cast<GLuint>(view.getViewport().height * static_cast<float>(winSize.y));

	//invert position
	y -= h;
	glViewport(x, y, w, h);

	//update directional light
	if (m_useDirectionalLight)
	{
		glm::vec3 pos = m_camera->GetPosition();
		m_directionalLight->SetPosition(-pos.x + lightPosOffset.x, -pos.y + lightPosOffset.y, directionalLightNear);
		m_directionalLight->SetTarget(-pos.x + lightTargetOffset.x, -pos.y + lightTargetOffset.y, directionalLightFar);
	}
}
Esempio n. 21
0
void Wall::setType(Wall::Type type, const sf::View &view) {
    float width = abs(view.getSize().x),
            height = abs(view.getSize().y),
            x = view.getCenter().x,
            y = view.getCenter().y;

    if (type == Left) {
        setPosition(-0.5, y);
        setSize(1, height);
    } else if (type == Right) {
        setPosition(width + 0.5, y);
        setSize(1, height);
    } else if (type == Top){
        setPosition(x, height + 0.25);
        setSize(width, 0.5);
    } else if (type == Bottom) {
        setPosition(x, -0.25);
        setSize(width, 0.5);
    } else {
        _type = None;
        return ;
    }
    _type = type;
}
Esempio n. 22
0
void EffectsHandler::Update(float elapsed, sf::View &view, sf::RenderWindow &rw)
{
    if (effectsList.empty())
    {
        return;
    }
    
    for (std::list<Effect>::iterator it = effectsList.begin(); it != effectsList.end(); it++)
    {
        switch (*it)
        {
            case ZoomIn:
                if (view.getSize().x > rw.getSize().x/2)
                {
                    view.setSize(view.getSize().x-(ZOOM_SPEED_X*elapsed), view.getSize().y-(ZOOM_SPEED_Y*elapsed));
                    view.setCenter(view.getCenter().x, view.getCenter().y-(ZOOM_POS_ABOVE_MIDDLE*elapsed));
                }
                else effectsList.erase(it++);
                break;
                
            case ZoomOut:
                if (view.getSize().x <= rw.getDefaultView().getSize().x &&
                    view.getSize().y <= rw.getDefaultView().getSize().y)	//seems silly to take &window just for getdefaultview.
                {
                    view.setSize(view.getSize().x+(ZOOM_SPEED_X*elapsed), view.getSize().y+(ZOOM_SPEED_Y*elapsed));
                    view.setCenter(view.getCenter().x, view.getCenter().y+(ZOOM_POS_ABOVE_MIDDLE*elapsed));
                }
                else
                {
                    effectsList.erase(it++);
                    view = rw.getDefaultView();
                }
                break;
                
            case Pause:
                totalelapsed += elapsed;
                if (totalelapsed > 1.0f)
                {
                    effectsList.erase(it++);
                    totalelapsed = 0;
                }
                break;
                
            default:
                break;
        }
    }
}
Esempio n. 23
0
bool entity_inView(Entity& entity, sf::View & view)
{
	return createRect(entity.objectEntity->GetPosition(), entity.objectEntity->GetSize()).intersects((createRect(view.getCenter() - view.getSize() / 1.5f, view.getSize() * 1.5f)));
}
Esempio n. 24
0
bool entity_ojectInView(tmx::MapObject& object, sf::View& view)
{
	return createRect(object.GetPosition(), object.GetSize()).intersects((createRect(view.getCenter() - view.getSize() / 1.5f, view.getSize() * 1.5f)));
}
Esempio n. 25
0
	int render(Phys* phys)
	{
        window->clear(sf::Color::Black);
		
		sf::Vector2f viewmove(0, 0);
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) viewmove.x -= base_camera_move;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) viewmove.x += base_camera_move;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) viewmove.y += base_camera_move;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) viewmove.y -= base_camera_move;
		viewmove *= (phys->dt * view->getSize().x / scrw);
		viewmove = sv2rotate(viewmove, -view->getRotation());
		view->move(viewmove);
		
		view->zoom(pow(1.2, -mouse_wheel));
		mouse_wheel = 0;

		float viewrotate = 0;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::LBracket)) viewrotate += base_camera_rotate;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::RBracket)) viewrotate -= base_camera_rotate;
		viewrotate *= phys->dt;
		view->rotate(viewrotate);
		
		window->setView(*view);
		
		
		
		for (std::vector<Ship*>::iterator its = phys->ship_list.begin(); its != phys->ship_list.end(); ++its)
		{
			sf::ConvexShape& shape = (*its)->shape;
			cpVect pos = cpBodyGetPosition((*its)->body);
			cpFloat angle = cpBodyGetAngle((*its)->body);
			shape.setPosition(pos.x, pos.y);
			shape.setRotation(180 / PI * angle);
			window->draw(shape);
		}		
		for (std::vector<Shell*>::iterator its = phys->shell_list.begin(); its != phys->shell_list.end(); ++its)
		{
			sf::ConvexShape& shape = (*its)->shape;
			cpVect pos = cpBodyGetPosition((*its)->body);
			cpFloat angle = cpBodyGetAngle((*its)->body);
			shape.setPosition(pos.x, pos.y);
			shape.setRotation(180 / PI * angle);
			window->draw(shape);
		}
		
		char* str = new char[30];
		float acc = 0;
		for (int i = 0; i < frame_time_count; i++) acc += phys->last_frame_deltas[i];
		acc /= frame_time_count;
		sprintf(str, "%.1f", 1./acc);
		drawtext(str, 0.02, 0.98, 10);	
		
		int sc = (*phys->ship_list.begin())->score;
		sprintf(str, "%d", sc);
		drawtext(str, 0.98, 0.98, 10);
		
		delete str;
		
		
        window->display();
		
		return 0;
	}
Esempio n. 26
0
sf::IntRect viewGetRect(sf::View &view) {
    sf::Vector2i center = (sf::Vector2i) view.getCenter();
    sf::Vector2i size = (sf::Vector2i) view.getSize();
    return sf::IntRect(center - size / 2, size);
}
Esempio n. 27
0
void LevelLoader::render(sf::RenderWindow &window, sf::View view)
{
    sf::Texture errtexture;
    errtexture.loadFromFile("error.png");
    sf::Sprite errsprite;
    errsprite.setTexture(errtexture);
    for(int i = 0; i < width; i++) {
        for(int j = 0; j < height; j++) {
            if(map_t[i][j].getX() < view.getCenter().x + view.getSize().x/2 && map_t[i][j].getX() + tilesize > view.getCenter().x - view.getSize().x/2 && map_t[i][j].getY() < view.getCenter().y + view.getSize().y/2 && map_t[i][j].getY() + tilesize > view.getCenter().y - view.getSize().y/2) {
                int tempInt = 0;
                if(map_t[i][j].ID == 1) {
                    map_t[i][j].setSprite(sprites[tempInt]);
                    map_t[i][j].setPosition(i * tilesize, j * tilesize);
                }
                tempInt++;
                if(map_t[i][j].ID == 2) {
                    map_t[i][j].setSprite(sprites[tempInt]);
                    map_t[i][j].setPosition(i * tilesize, j * tilesize);
                }
                tempInt++;
                if(map_t[i][j].ID == 3) {
                    map_t[i][j].setSprite(sprites[tempInt]);
                    map_t[i][j].setPosition(i * tilesize, j * tilesize);
                }
                tempInt++;
                if(map_t[i][j].ID == 4) {
                    map_t[i][j].setSprite(sprites[tempInt]);
                    map_t[i][j].setPosition(i * tilesize, j * tilesize);
                }
                tempInt++;
                if(map_t[i][j].ID == 5) {
                    map_t[i][j].setSprite(sprites[tempInt]);
                    map_t[i][j].setPosition(i * tilesize, j * tilesize);
                }
                tempInt++;
                if(map_t[i][j].ID == 6) {
                    map_t[i][j].setSprite(sprites[tempInt]);
                    map_t[i][j].setPosition(i * tilesize, j * tilesize);
                }
                tempInt++;
                if(map_t[i][j].ID == 7) {
                    map_t[i][j].setSprite(sprites[tempInt]);
                    map_t[i][j].setPosition(i * tilesize, j * tilesize);
                }
                tempInt++;
                if(map_t[i][j].ID == 8) {
                    map_t[i][j].setSprite(sprites[tempInt]);
                    map_t[i][j].setPosition(i * tilesize, j * tilesize);
                }
                tempInt++;
                if(map_t[i][j].ID == 9) {
                    map_t[i][j].setSprite(sprites[tempInt]);
                    map_t[i][j].setPosition(i * tilesize, j * tilesize);
                }
                if(map_t[i][j].ID == 0) {
                    map_t[i][j].setSprite(errsprite);
                    map_t[i][j].setPosition(i * tilesize, j * tilesize);
                }
                window.draw(map_t[i][j].getSprite());
            }
        }
    }
}
Esempio n. 28
0
void Map::DrawMap(sf::View& ViewRef)
{
	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);
	//sf::Drawable* DrawPtr;
	for (int i = MinX; i <= MaxX; i++)
		for (int ii = MinY; ii <= MaxY; ii++)
		{
			if (MapMatrix[i][ii].tileID != -1)//Not empty space.
			{
				if (!(WCR.inMapMaker && WCR.MMPtr->HideObjectSprites->IsActive()))
				{
					WCR.MMPtr->TileSets[MapMatrix[i][ii].tileSetID].Tiles[MapMatrix[i][ii].tileID].setPosition(i * CellSize, ii * CellSize);
					WCR.RenderRef.draw(WCR.MMPtr->TileSets[MapMatrix[i][ii].tileSetID].Tiles[MapMatrix[i][ii].tileID]);
				}
				if (WCR.inMapMaker)
					if (WCR.MMPtr->viewObjectTypes)
					{
						sf::RectangleShape DrawRect;
						DrawRect.setSize(sf::Vector2f(32, 32));						
						switch (MapMatrix[i][ii].objectType)
						{
						case 0:DrawRect.setFillColor(sf::Color::White); break;//Invis
						case 1:DrawRect.setFillColor(sf::Color::Blue); break;//Solid
						case 2:DrawRect.setFillColor(sf::Color::Green); break;//Bouncy
						case 3:DrawRect.setFillColor(sf::Color::Red); break;//Death
						case 4:DrawRect.setFillColor(sf::Color::Yellow); break;//Next Level
						case 5:DrawRect.setFillColor(sf::Color::Cyan); break;//Ice
						}
						DrawRect.setFillColor(sf::Color(DrawRect.getFillColor().r, DrawRect.getFillColor().g, DrawRect.getFillColor().b, 100));
						DrawRect.setPosition(i * CellSize, ii * CellSize);
						WCR.RenderRef.draw(DrawRect);
						if (MapMatrix[i][ii].pixelPerfect)
						{
							sf::CircleShape DrawCirc;
							DrawCirc.setRadius(8);
							DrawCirc.setPosition(i * CellSize + 8, ii * CellSize + 8);
							sf::Color MyCol_ = sf::Color::Black;
							MyCol_.a = 100;
							DrawCirc.setFillColor(MyCol_);

							WCR.RenderRef.draw(DrawCirc);
						}
					}
			}
		}
}