Exemple #1
0
/**
 * FUNCTION Map::loadmap(std::string path)
 * Loads a map from a file and creates all surfaces
 * and sets the right settings for all tiles on the map
 *
 * Every map tile is then stored in a vector (mapdata) that
 * is later used when rendering the map to screen
 */
void Map::loadmap(std::string path) {
	MovableObject* stall = new MovableObject();
	stall->setx(190);
	stall->sety(100);
	stall->settexture("graphics/stall.png");
	stall->setmovable(true);
	stall->setcollisionable(true);
	stall->setsurface(draw_engine->load_image(stall->gettexture()));

	int tiles_per_row = (DrawEngine::get_screen_width() / 128);
	int y = -33;
	int x_off = 0;
	int counter = 0;

	// create grass
	for (int i = 0; i < 300; i++) {
		WorldObject* grass = new WorldObject();
		grass->setx(x_off + ((counter - 1) * 128));
		grass->sety(y);
		grass->settexture("graphics/grass3.png");
		grass->setmovable(false);
		grass->setcollisionable(false);

		SDL_Surface* surf_grass = draw_engine->load_image(grass->gettexture());
		grass->setsurface(surf_grass);

		mapdata.push_back(grass);

		if ((counter >= tiles_per_row && x_off == 0) || (counter
				>= (tiles_per_row) + 1)) {
			y += 32;
			x_off = (x_off == 0) ? -(64 * 1) : 0;
			counter = 0;
		}

		counter++;
	}

	this->setwidth(tiles_per_row);
	this->setheight(y);

	mapdata.push_back(stall);
}