Ejemplo n.º 1
0
void Map::Render(const SVector2& offset, OtherPlayers& otherPlayers) {
	// Used in bounding box checks later
	sOffset = offset;

	int tiles = mMapData.GetTileAmount();

	SGE::Graphics_DebugUsageBegin("Ground");
	// Render Ground
	for (int a = 0; a < tiles; ++a) {
		GroundTile* pTile = &mMapData.mLayer1[a];
		int type = pTile->GetType();
		if (type) {
			const SVector2& pos = pTile->GetPosition();
			mSprites[type].SetPosition(pos + offset);
			mSprites[type].Render();
		}
	}

	SGE::Graphics_DebugUsageEnd();
	SGE::Graphics_DebugUsageBegin("MaskItems");

	// Render Mask
	for (int a = 0; a < tiles; ++a) {
		Tile* pTile = &mMapData.mLayer2[a];
		int type = pTile->GetType();
		if (type) {
			const SVector2& pos = pTile->GetPosition();
			mSprites[type].SetPosition(pos + offset);
			mSprites[type].Render();
		}

		// Render Items
		if (mMapData.mLayer1[a].GetItemImageNumber() > 0 && GetItemActive(a)) {
			SVector2 pos = SVector2(mMapData.mLayer1[a].GetPosition().y,
					mMapData.mLayer1[a].GetPosition().x); // Bug
			int type = mMapData.mLayer1[a].GetItemImageNumber();
			if (type > 0 && type < mNumberOfItems) {
				mItemSprites[type].mSprite.SetPosition(pos + offset);
				mItemSprites[type].mSprite.Render();
			}
		}
	}

	SGE::Graphics_DebugUsageEnd();
	SGE::Graphics_DebugUsageBegin("NPCs");

	// Render NPCS
	for (int a = 0; a < mNumberOfNPCS; ++a) {
		mNPCS[a]->Render(offset);
	}

	SGE::Graphics_DebugUsageEnd();
	SGE::Graphics_DebugUsageBegin("Players");

	// Render Character
	mCharacter.Render(offset);

	// Render other players
	otherPlayers.Render(offset);

	SGE::Graphics_DebugUsageEnd();
	SGE::Graphics_DebugUsageBegin("Extras");

	// Render Extra
	for (int a = 0; a < tiles; ++a) {
		SVector2 pos = mMapData.mLayer3[a].GetPosition();
		int type = mMapData.mLayer3[a].GetType();
		mSprites[type].SetPosition(pos + offset);
		mSprites[type].Render();
	}

	SGE::Graphics_DebugUsageEnd();
	SGE::Graphics_DebugUsageBegin("Fringe");

	// Render Fringe
	for (int a = 0; a < tiles; ++a) {
		SVector2 pos = mMapData.mLayer4[a].GetPosition();
		int type = mMapData.mLayer4[a].GetType();
		mSprites[type].SetPosition(pos + offset);
		mSprites[type].Render();
	}

	SGE::Graphics_DebugUsageEnd();
	SGE::Graphics_DebugUsageBegin("WeatherPaths");

	mWeather.Render(offset);
	mPathFinding.Render(offset);

	SGE::Graphics_DebugUsageEnd();
}
Ejemplo n.º 2
0
    Map* Generator::CreateMap(Game& game, unsigned int width, unsigned int height, unsigned int tile_width, unsigned int tile_height)
    {
        Map* map = new Map(game, width, height, tile_width, tile_height);

        // Generate water tiles on the edge of the map
        noise::module::Perlin perlin;
        perlin.SetSeed(Random::UInt());
        perlin.SetNoiseQuality(noise::QUALITY_BEST);
        perlin.SetLacunarity(1.0f);
        Tile* tile;
        for (unsigned int x = 0; x != width; ++x)
        {
            double size = abs(perlin.GetValue(x * .02, 0, 0) * 16.0);
            for (unsigned int i = 0; i < size + 16; ++i)
            {
                tile = map->GetTile(x, i);
                if (tile)
                {
                    tile->SetType(TT_WATER);
                }
                tile = map->GetTile(x, height - i - 1);
                if (tile)
                {
                    tile->SetType(TT_WATER);
                }
            }
        }
        for (unsigned int y = 0; y != height; ++y)
        {
            double size = abs(perlin.GetValue(0, y * .02, 0) * 16.0);
            for (unsigned int i = 0; i < size + 16; ++i)
            {
                tile = map->GetTile(i, y);
                if (tile)
                {
                    tile->SetType(TT_WATER);
                }
                tile = map->GetTile(width - i - 1, y);
                if (tile)
                {
                    tile->SetType(TT_WATER);
                }
            }
        }

        // Generate forest or grass tiles on remaining tiles
        perlin.SetSeed(Random::UInt());
        perlin.SetNoiseQuality(noise::QUALITY_BEST);
        perlin.SetLacunarity(1.0f);
        for (unsigned int x = 1; x != width; ++x)
        {
            for (unsigned int y = 1; y != height; ++y)
            {
                tile = map->GetTile(x, y);
                if (tile->GetType() != TT_WATER)
                {
                    double value = perlin.GetValue(x * .02, y * .02, 0);
                    if (value <= -.3 || value >= .3)
                    {
                        tile->SetType(TT_FOREST);
                    }
                    else
                    {
                        tile->SetType(TT_GRASS);
                    }
                }
            }
        }

        // Remove unreachable tiles
        PostProcessMap(*map);

        return map;
    }