void
Player::update_walk_stand()
{
  if (controller.get_axis_state(Y_AXIS) > 0) {
    TileMap* tilemap = Sector::current()->get_tilemap2();
    if (tilemap)
      {
        Point p(int(pos.x)/32, (int(pos.y)/32 + 1));
        unsigned int col = tilemap->get_pixel(p.x, p.y);

        if ((col & TILE_STAIRS) && (get_direction() == WEST && (col & TILE_LEFT) ||
                                    get_direction() == EAST && (col & TILE_RIGHT)))
          {
            delete contact;
            contact = new StairContact(tilemap, p);

            std::cout << "Stair mode" << std::endl;
            state = STAIRS_DOWN;
            //c_object->get_check_domains() & (~CollisionObject::DOMAIN_TILEMAP));
            Sector::current()->get_collision_engine()->remove(c_object);
            z_pos = -10.0f;
            return;
          }
        else
          {
            set_ducking();
            return;
          }
      }
  } else if (controller.get_axis_state(Y_AXIS) < 0) {
    TileMap* tilemap = Sector::current()->get_tilemap2();
    if (tilemap)
      {
        Point p(int(pos.x)/32 + ((get_direction() == WEST) ? -1 : +1), (int(pos.y)/32));
        unsigned int col = tilemap->get_pixel(p.x, p.y);

        if ((col & TILE_STAIRS) && (get_direction() == EAST && (col & TILE_LEFT) ||
                                    get_direction() == WEST && (col & TILE_RIGHT)))
          {
            delete contact;
            contact = new StairContact(tilemap, p);

            state = STAIRS_UP;
            //c_object->get_check_domains() & (~CollisionObject::DOMAIN_TILEMAP));
            Sector::current()->get_collision_engine()->remove(c_object);
            z_pos = -10.0f;
            return;
          }
      }    
  }

  if(state == STAND)
    update_stand();
  else
    update_walk();
}
Example #2
0
float
Sector::get_width() const
{
  float width = 0;
  for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
    TileMap* solids = *i;
    if ((solids->get_width() * 32 + solids->get_x_offset()) > width) width = (solids->get_width() * 32 + solids->get_x_offset());
  }
  return width;
}
Example #3
0
float
Sector::get_height() const
{
  float height = 0;
  for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
    TileMap* solids = *i;
    if ((solids->get_height() * 32 + solids->get_y_offset()) > height) height = (solids->get_height() * 32 + solids->get_y_offset());
  }
  return height;
}
Example #4
0
float
Sector::get_width() const
{
  float width = 0;
  for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
    TileMap* solids = *i;
    width = std::max(width, solids->get_bbox().get_right());
  }

  return width;
}
Example #5
0
bool
Sector::before_object_add(GameObject* object)
{
  Bullet* bullet = dynamic_cast<Bullet*> (object);
  if(bullet != NULL) {
    bullets.push_back(bullet);
  }

  MovingObject* movingobject = dynamic_cast<MovingObject*> (object);
  if(movingobject != NULL) {
    moving_objects.push_back(movingobject);
  }

  Portable* portable = dynamic_cast<Portable*> (object);
  if(portable != NULL) {
    portables.push_back(portable);
  }

  TileMap* tilemap = dynamic_cast<TileMap*> (object);
  if(tilemap != NULL && tilemap->is_solid()) {
    solid_tilemaps.push_back(tilemap);
  }

  Camera* camera = dynamic_cast<Camera*> (object);
  if(camera != NULL) {
    if(this->camera != 0) {
      log_warning << "Multiple cameras added. Ignoring" << std::endl;
      return false;
    }
    this->camera = camera;
  }

  Player* player = dynamic_cast<Player*> (object);
  if(player != NULL) {
    if(this->player != 0) {
      log_warning << "Multiple players added. Ignoring" << std::endl;
      return false;
    }
    this->player = player;
  }

  UsesPhysic *physic_object = dynamic_cast<UsesPhysic *>(object);
  if(physic_object)
  {
    physic_object->physic.set_gravity(gravity);
  }


  if(_current == this) {
    try_expose(object);
  }

  return true;
}
Example #6
0
TileMap *
TileMap::createCSV( std::string fileName )
{
    std::fstream file( fileName, std::ios::in );
    if(! file.good() ) return nullptr;
    file.close();

    TileMap *tileMap = new TileMap;
    tileMap->fromCSV( fileName );
    return tileMap;
}
Example #7
0
bool
Sector::inside(const Rect& rect) const
{
  for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
    TileMap* solids = *i;
    bool horizontally = ((rect.p2.x >= 0 + solids->get_x_offset()) && (rect.p1.x <= solids->get_width() * 32 + solids->get_x_offset()));
    bool vertically = (rect.p1.y <= solids->get_height() * 32 + solids->get_y_offset());
    if (horizontally && vertically) return true;
  }
  return false;
}
Example #8
0
TileMap *RoomLoader::loadTileMap(const std::string& filename)
{
	std::cout << "Loading tilemap " + filename + "...";
    std::vector<std::string> data = tokenize(loadFile(filename), "\n", true);

	int width = 0;
	int height = 0;
	int row;
    int col;

	for (row = 0; row < (int)data.size(); row++)
	{
		if (row == 0)
            width = data[row].size();
		height++;
	}
	height = (height - 1) / 2;

	TileMap* tileMap = new TileMap(width, height);
	tileMap->clear(0,0);

	// Load solidities 
	for (row = 0; row < height; row++)
	{
		for (col = 0; col < width; col++)
		{
			char c = data.at(row).at(col);
			if (c == '.')
			{
				tileMap->setFlags(col, row, 0);
			}
			else if (c == '#')
			{
				tileMap->setFlags(col, row, TileMap::FLAG_SOLID);
			} 
		}
	}

	// Load tiles
	for (row = height; row < height*2; row++)
	{
		for (col = 0; col < width; col++)
		{
			char c = data.at(row).at(col);
			int tile = c - ((c >= 'a')? 'a' - 10 : '0');
			tileMap->setTile(col, row - height, tile);
		}
	}

	//std::cout << tileMap->toString() << std::endl;

    std::cout << " Done!" << std::endl;
	return tileMap;
}
Example #9
0
int test_both(const std::string& map, const std::string& anim_name)
{
	TMXLoader loader_anim(anim_name);
	std::vector<Animation*> anim = loader_anim.ExtractAsAnimation(); 
	for(int i=0; i<anim.size();i++)
	{
		anim[i]->SetFrameTime(0.07);
	}
	AnimatedSprite MyCharacter(anim[2], true, true);
	MyCharacter.SetPosition(308,224);
	
	TMXLoader loader_map(map);
	TileMap* tilemap = loader_map.ExtractAsMap();
	sf::RenderWindow App(sf::VideoMode(640,480), "TMX_Renderer");
	sf::View map_view = App.GetDefaultView();
	sf::View anim_view = App.GetDefaultView();
	anim_view.Zoom(2.0);

	const sf::Input& Input = App.GetInput();
	float speed = 120.0;
	App.SetFramerateLimit(60);
	while (App.IsOpened())
	{
		sf::Event Event;
		while (App.GetEvent(Event))
		{
			if (Event.Type == sf::Event::Closed)
				App.Close();
			if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Left ))	MyCharacter.SetAnim(anim[3]);
			if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Right))	MyCharacter.SetAnim(anim[1]);
			if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Up   ))	MyCharacter.SetAnim(anim[0]);
			if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Down ))	MyCharacter.SetAnim(anim[2]);
			
		}
		
		if(Input.IsKeyDown(sf::Key::Left ))	map_view.Move(-App.GetFrameTime()*speed, 0.0);
		if(Input.IsKeyDown(sf::Key::Right))	map_view.Move( App.GetFrameTime()*speed, 0.0);
		if(Input.IsKeyDown(sf::Key::Up   ))	map_view.Move( 0.0, -App.GetFrameTime()*speed);
		if(Input.IsKeyDown(sf::Key::Down ))	map_view.Move( 0.0, App.GetFrameTime()*speed);
		MyCharacter.update(App.GetFrameTime());
		
		
		App.Clear();
		App.SetView(map_view);
		tilemap->renderMap(App,map_view.GetRect());
		App.SetView(anim_view);
		App.Draw(MyCharacter);
		
		App.Display();
	}
	return 1;
	
}
Example #10
0
float
Sector::get_height() const
{
  float height = 0;
  for(auto i = solid_tilemaps.begin();
      i != solid_tilemaps.end(); i++) {
    TileMap* solids = *i;
    height = std::max(height, solids->get_bbox().get_bottom());
  }

  return height;
}
Example #11
0
// Once the Map is parsed, we can automaticaly choose the right tiles
void Mapper::beautify(TileMap& tiles)
{
    for (size_t y=0; y <tiles.size(); y++)
    {
        for (size_t x=0; x < tiles[y].size(); x++)
        {
            if (tiles[y][x])
            {
                if ((y >= 1 && !tiles[y-1][x]) || y == 0)
                {
                    tiles[y][x]->addSide(TileSide::TOP);
                }

                if ((y < tiles.size()-1 && !tiles[y+1][x]) || y == tiles.size()-1)
                {
                    tiles[y][x]->addSide(TileSide::BOTTOM);
                }

                if ((x >= 1 && !tiles[y][x-1]) || x == 0)
                {
                    tiles[y][x]->addSide(TileSide::LEFT);
                }

                if ((x < tiles[y].size()-1 && !tiles[y][x+1]) || x == tiles[y].size()-1)
                {
                    tiles[y][x]->addSide(TileSide::RIGHT);
                }

                if ((x >= 1 && y >= 1 && !tiles[y-1][x-1]) || (x == 0 && y == 0))
                {
                    tiles[y][x]->addSide(TileSide::TOP_LEFT);
                }

                if ((x < tiles[y].size()-1 && y >= 1 && !tiles[y-1][x+1]) || (x == tiles[y].size()-1 && y == 0))
                {
                    tiles[y][x]->addSide(TileSide::TOP_RIGHT);
                }

                if ((x >= 1 && y < tiles.size()-1 && !tiles[y+1][x-1]) || (x == 0 && y == tiles.size()-1))
                {
                    tiles[y][x]->addSide(TileSide::BOTTOM_LEFT);
                }

                if ((x < tiles[y].size()-1 && y < tiles.size()-1 && !tiles[y+1][x+1]) || (x == tiles[y].size()-1 && y == tiles.size()-1))
                {
                    tiles[y][x]->addSide(TileSide::BOTTOM_RIGHT);
                }
            }
        }
    }
}
Example #12
0
int main() {
	// SFML window init
	sf::Vector2u res{ 1024, 768 };
	sf::RenderWindow window{ sf::VideoMode(res.x, res.y), "SFML Window" };
	window.setFramerateLimit(60);
	
	sf::Vector2u tileSize{ 16, 16 };
	std::string tileSet{ "square16_8.png" }; 

	Galaxy g;
	TileMap map;
	
	if (!map.load(tileSet, tileSize, g.numStarSystems, g.numStarSystems, g)) 
		return -1;
	
	sf::View gameView{ sf::Vector2f(4000, 4000), sf::Vector2f(res.x, res.y) };
	sf::View minimapView{ sf::Vector2f(4000, 4000), sf::Vector2f(4000, 4000) };
	
	// the game view (full window)
	gameView.setViewport(sf::FloatRect(0, 0, 1, 1));

	// mini-map (upper-right corner)
	minimapView.setViewport(sf::FloatRect(0.75f, 0, 0.25f, 0.25f));
	
	sf::RectangleShape miniback; // We want to draw a rectangle behind the minimap
	miniback.setPosition(0, 0);
	miniback.setSize(sf::Vector2f(8000, 8000));
	miniback.setFillColor(sf::Color::Black);

	// SFML Event loop
	while (window.isOpen()) {
		sf::Event event;
		while (window.pollEvent(event)) {
			if (event.type == sf::Event::Closed)
				window.close();
		}
		
		// Game loop goes here
		window.clear();
		window.setView(gameView);
		window.draw(map);
		
		window.setView(minimapView);
		window.draw(miniback);
		window.draw(map);
		
		window.display();
	}
	
	return 0;
}
Example #13
0
int TileMapBinder::shift(lua_State* L)
{
	StackChecker checker(L, "TileMapBinder::shift", 0);
	
	Binder binder(L);
	TileMap* tilemap = static_cast<TileMap*>(binder.getInstance("TileMap", 1));	

	int dx = luaL_checkinteger(L, 2);
	int dy = luaL_checkinteger(L, 3);

	tilemap->shift(dx, dy);

	return 0;
}
Example #14
0
bool
Sector::inside(const Rectf& rect) const
{
  for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
    TileMap* solids = *i;

    Rectf bbox = solids->get_bbox();
    bbox.p1.y = -INFINITY; // pretend the tilemap extends infinitely far upwards

    if (bbox.contains(rect))
      return true;
  }
  return false;
}
void
Sector::add_object(const std::string& name, const lisp::Lisp* lisp)
{
  lisp::Properties props(lisp);

  if(name == "tilemap") {
    TileMap* tilemap = new TileMap(props);
    add(tilemap);
    if (tilemap->get_name() == "interactive")
      interactive_tilemap = tilemap;
    else if (tilemap->get_name() == "interactivebackground")
      interactivebackground_tilemap = tilemap;
  } else if(name == "background") {
    // TODO
  } else if (name == "background-gradient") {
    add(new BackgroundGradient(props));
  } else if(name == "trigger") {
    add(new Trigger(props));
  } else if(name == "box") {
    add(new Box(props));
  } else if(name == "shockwave") {
    add(new Shockwave(props));
  } else if(name == "elevator") {
    add(new Elevator(props));
  } else if(name == "character") {    
    add(new Character(props));
  } else if(name == "spider-mine") {
    add(new SpiderMine(props));
  } else if(name == "hedgehog") {
    add(new Hedgehog(props));
  } else if(name == "test-object") {
    add(new TestObject(props));
  } else if (name == "nightvision") {
    add(new Nightvision(props));
  } else if (name == "particle-system") {
    add(new ParticleSystem(props));
  } else if(name == "scriptable-object") {    
    add(new ScriptableObject(props));
  } else if (name == "vrdummy") {
    add(new VRDummy(props));
  } else if (name == "swarm") {
    add(new Swarm(props));
  } else if (name == "laserpointer") {
    add(new LaserPointer());
  } else if (name == "liquid") {
    add(new Liquid(props));
  } else {
    std::cout << "Skipping unknown Object: " << name << "\n";
  }
}
Example #16
0
Map *ParseMap(const std::string &data) {
    auto lines = StringLines(data);

    TileMap tiles;
    for(auto &line : lines) {
        TileLine tileLine;
        for(auto &ch : StringChars(line)) {
            tileLine.push_back(CharToTile(ch));
        }
        tiles.push_back(tileLine);
    }

    return new Map(tiles);
}
Example #17
0
Room *RoomLoader::loadRoom(const std::string& filename)
{
	TileMap* tileMap = loadTileMap(filename);

	std::cout << "Loading room " + filename + "...";
    std::vector<std::string> data = tokenize(loadFile(filename), "\n", true);

	std::vector<std::string> tileSetInfo = tokenize(data[data.size()-1], " ");

	if (tileSetInfo.size() == 0)
	{
		throw DB_EXCEPTION("Tilset info is missing in file " + filename);
	}

	std::string tileSetFileName = "graphics/" + tileSetInfo[0];
	int numTiles = fromString<int>(tileSetInfo[1]);

	Room* room = new Room(tileMap, new Animation(tileSetFileName, numTiles));	

	int width = 0;
	int height = 0;
	int row;
    int col;

	// Load entities 
	int x = 0;
	int y = 0;
	for (row = 0; row < tileMap->getHeight(); row++)
	{
		for (col = 0; col < tileMap->getWidth(); col++)
		{
			char c = data[row].at(col);
			// Ignore solidities.
			if (c != '.' && c != '#')
			{
				Entity* entity = createEntity(c, x * TileMap::TILE_SIZE, y * TileMap::TILE_SIZE, Random::get());
				room->addEntity(entity);
			}
	
			x++;
		}
		x = 0;
		y++;
	}

    std::cout << " Done!" << std::endl;

	return room;
}
bool 
CoordArg::load( BitBuffer& buf, TileMap& tileMap,
                const TileFeatureArg* /*prevArg*/ ) 
{
   // XXX: Doesn't use relative coordinates yet.
   buf.alignToByte();
   int16 diffLat = buf.readNextBAShort();
   int16 diffLon = buf.readNextBAShort();
   int32 lat = diffLat * tileMap.getMC2Scale() + 
      tileMap.getReferenceCoord().getLat();
   int32 lon = diffLon * tileMap.getMC2Scale() + 
      tileMap.getReferenceCoord().getLon();
   m_coord.setCoord( lat, lon );
   return true;
}
Example #19
0
void
TileCell::Draw(Bitmap* bitmap, GFX::rect *rect, bool advanceFrame, bool full)
{
	MapOverlay* overlayZero = fOverlays[0];
	if (overlayZero == NULL)
		return;

	TileMap* tileMapZero = overlayZero->TileMapForTileCell(fNumber);
	if (tileMapZero == NULL) {
		std::cerr << "Tilemap Zero is NULL!" << std::endl;
		return;
	}
	const int8 mask = tileMapZero->Mask();
	int maxOverlay = full ? fNumOverlays : 1;
	for (int i = maxOverlay - 1; i >= 0; i--) {
		if (!ShouldDrawOverlay(i, mask))
			continue;
	    MapOverlay *overlay = fOverlays[i];
		TileMap *map = overlay->TileMapForTileCell(i == 0 ? fNumber : 0);
		if (map == NULL)
			continue;

		int16 index = map->TileIndex(advanceFrame);
		if (fDoor != NULL && !fDoor->Opened()) {
			int16 secondaryIndex = map->SecondaryTileIndex();
			if (secondaryIndex != -1)
				index = secondaryIndex;
			else
				std::cerr << "TileCell::Draw(): secondary index is -1. BUG?." << std::endl;
		}

		TISResource *tis = gResManager->GetTIS(overlay->TileSet());
		Bitmap *cell = tis->TileAt(index);
		assert(cell != NULL);

		gResManager->ReleaseResource(tis);

		GFX::Color *color = NULL;
		if (i == 0 && mask != 0) {
			color = &sTransparentColor;
			//color = &cell->format->palette->colors[255];
		}

		_DrawOverlay(bitmap, cell, *rect, color);

		cell->Release();
	}
}
Example #20
0
Collision Projectile::checkProjectileCollision(TileMap &map)
{
	if (!this->tileObject)
	{
		// It's possible the projectile reached the end of it's lifetime this frame
		// so ignore stuff without a tile
		return {};
	}

	sp<TileObject> ignoredObject = nullptr;
	if (ownerInvulnerableTicks > 0)
	{
		if (firerVehicle)
		{
			ignoredObject = firerVehicle->tileObject;
		}
		else if (firerUnit)
		{
			ignoredObject = firerUnit->tileObject;
		}
	}
	Collision c = map.findCollision(this->previousPosition, this->position, {}, ignoredObject);
	if (!c)
		return {};

	c.projectile = shared_from_this();
	return c;
}
bool 
CoordArg::save( BitBuffer& buf, const TileMap& tileMap,
                const TileFeatureArg* prevArg ) const 
{
   // XXX: Doesn't use relative coordinates yet.
   int16 lat = ( m_coord.getLat() - 
         tileMap.getReferenceCoord().getLat() ) / 
      tileMap.getMC2Scale();
   int16 lon = ( m_coord.getLon() - 
         tileMap.getReferenceCoord().getLon() ) / 
      tileMap.getMC2Scale();
   buf.alignToByte();
   buf.writeNextBAShort( lat );
   buf.writeNextBAShort( lon );
   return true;
}
/// Snap to tilemap coords and remove duplicates.
static bool
snapToCoord( coordVectVect_t& polygons,
             const TileMap& tilemap )
{
   bool changedAnything = false;
   for ( uint32 i = 0; i < polygons.size(); ++i ) {
      vector<MC2Coordinate>& coords = polygons[ i ];

      for ( uint32 j = 0; j < coords.size(); ++j ) {
         TileMapCoord currCoord = coords[ j ];
         tilemap.snapCoordToPixel( currCoord );
         if ( currCoord != coords[ j ] ) {
            coords[ j ] = currCoord;
            changedAnything = true;
         }
      }
      // Remove consequtive identical coordinates.
      uint32 size = coords.size();
      coords.resize( std::distance( coords.begin(), 
                        std::unique( coords.begin(), coords.end() ) ) );
      if ( coords.size() != size ) {
         changedAnything = true;
      }
   }

   return changedAnything;
}
Example #23
0
void Game::run()
{
	quit = false;

	DisplayWindowDescription desc;
	desc.set_title("ClanLib TileMap Example");
	desc.set_size(Size(640, 480), true);
	desc.set_allow_resize(false);

	DisplayWindow window(desc);

	Slot slot_quit = window.sig_window_close().connect(this, &Game::on_window_close);
	Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &Game::on_input_up);

	Canvas canvas(window);

	clan::XMLResourceDocument xml_resource_document("resources.xml");
	ResourceManager resources = clan::XMLResourceManager::create(xml_resource_document);

	TileMap map;
	map.load(canvas, "tavern", resources, xml_resource_document);

	// Run until someone presses escape, or closes the window
	while (!quit)
	{
		int x = window.get_ic().get_mouse().get_x() - canvas.get_width();
		int y = window.get_ic().get_mouse().get_y() - canvas.get_height();

		// ** Enable these 3 lines to display the example magnified **
		//Mat4f matrix = Mat4f::scale( 2.0f, 2.0f, 1.0f);
		//x /= 2; y /= 2;
		//canvas.set_modelview(matrix);

		map.set_scroll(x, y);

		canvas.clear(Colorf::black);

		map.draw(canvas);


		// Flip the display, showing on the screen what we have drawed since last call to flip()
		window.flip(1);

		// This call processes user input and other events
		KeepAlive::process(0);
	}
}
Example #24
0
void
Sector::collision_tilemap(collision::Constraints* constraints,
                          const Vector& movement, const Rectf& dest,
                          MovingObject& object) const
{
  // calculate rectangle where the object will move
  float x1 = dest.get_left();
  float x2 = dest.get_right();
  float y1 = dest.get_top();
  float y2 = dest.get_bottom();

  for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
    TileMap* solids = *i;

    // test with all tiles in this rectangle
    Rect test_tiles = solids->get_tiles_overlapping(Rectf(x1, y1, x2, y2));

    for(int x = test_tiles.left; x < test_tiles.right; ++x) {
      for(int y = test_tiles.top; y < test_tiles.bottom; ++y) {
        const Tile* tile = solids->get_tile(x, y);
        if(!tile)
          continue;
        // skip non-solid tiles
        if(!tile->is_solid ())
          continue;
        Rectf tile_bbox = solids->get_tile_bbox(x, y);

        /* If the tile is a unisolid tile, the "is_solid()" function above
         * didn't do a thorough check. Calculate the position and (relative)
         * movement of the object and determine whether or not the tile is
         * solid with regard to those parameters. */
        if(tile->is_unisolid ()) {
          Vector relative_movement = movement
            - solids->get_movement(/* actual = */ true);

          if (!tile->is_solid (tile_bbox, object.get_bbox(), relative_movement))
            continue;
        } /* if (tile->is_unisolid ()) */

        if(tile->is_slope ()) { // slope tile
          AATriangle triangle;
          int slope_data = tile->getData();
          if (solids->get_drawing_effect() & VERTICAL_FLIP)
            slope_data = AATriangle::vertical_flip(slope_data);
          triangle = AATriangle(tile_bbox, slope_data);

          collision::rectangle_aatriangle(constraints, dest, triangle,
              solids->get_movement(/* actual = */ false));
        } else { // normal rectangular tile
          check_collisions(constraints, movement, dest, tile_bbox, NULL, NULL,
              solids->get_movement(/* actual = */ false));
        }
      }
    }
  }
}
Example #25
0
void G_update(double elapsed_time)
{
	input.update();
	I_updateProgramInput(&input);
	I_updateGameInput();

	game_time += elapsed_time;

	currentFrame++;
	theta += 0.5f;

	tilemap_back.update();
	tilemap_front.update();

	camera.update(world_constraints);

}
Example #26
0
void RoomGenerator::placeDoor(Room *room, const std::string &targetDungeon, int targetLevel, bool down, Random &random)
{
	TileMap *tm = room->getTileMap();

	while(true)
	{
		int x = random.getInt(tm->getWidth());
		int y = random.getInt(tm->getHeight());
		
		bool ok = false;

		while(true)
		{
			if (y < 0 || y >= tm->getHeight())
			{
				break;
			}

			if (tm->isSolid(x, y + 1))
			{
				y++;
			}
			else if (!tm->isSolid(x, y))
			{
				y--;
			}
			else if (tm->isSolid(x - 1, y) && tm->isSolid(x + 1, y))
			{
				ok = tm->isSolid(x, y - 1);
				break;
			}
			else
			{
				break;
			}
		}

		if (ok)
		{
			tm->setFlags(x, y, 0);
			room->addEntity(new Door(x * TileMap::TILE_SIZE, y * TileMap::TILE_SIZE, down, targetDungeon, targetLevel, false));
			break;
		}
	}
}
Example #27
0
sf::VertexArray GenerateVertexArray(TileSet &tileSet, TileMap &tileMap)
{
    sf::VertexArray vertexArray(sf::Quads);
    int tileWidth = tileSet.tileSize.x;
    int tileHeight = tileSet.tileSize.y;

    if(tileSet.IsDirty())
        return vertexArray;

    for(int layer = 0; layer < 3; layer++)
    {
        for(int col = 0; col < tileMap.GetColumnsCount(); col++)
        {
            for(int row = 0; row < tileMap.GetRowsCount(); row++)
            {
                TileTextureCoords coords;
                if(tileMap.GetTile(layer, col, row) != -1)
                {
                    coords = tileSet.GetTileTextureCoords(tileMap.GetTile(layer, col, row));
                }
                else
                {
                    coords = tileSet.GetTileTextureCoords(0);
                }

                {
                    sf::Vertex vertex(sf::Vector2f(col * tileWidth, row * tileHeight), coords.topLeft);
                    if(tileMap.GetTile(layer, col, row) == -1)
                        vertex.color.a = 0;
                    vertexArray.append(vertex);
                }
                {
                    sf::Vertex vertex(sf::Vector2f(col * tileWidth, (row + 1) * tileHeight), coords.bottomLeft);
                    if(tileMap.GetTile(layer, col, row) == -1)
                        vertex.color.a = 0;
                    vertexArray.append(vertex);
                }
                {
                    sf::Vertex vertex(sf::Vector2f((col + 1) * tileWidth, (row + 1) * tileHeight), coords.bottomRight);
                    if(tileMap.GetTile(layer, col, row) == -1)
                        vertex.color.a = 0;
                    vertexArray.append(vertex);
                }
                {
                    sf::Vertex vertex(sf::Vector2f((col + 1) * tileWidth, row * tileHeight), coords.topRight);
                    if(tileMap.GetTile(layer, col, row) == -1)
                        vertex.color.a = 0;
                    vertexArray.append(vertex);
                }
            }
        }
    }

    return vertexArray;
}
Example #28
0
void R_draw(HDC hDC)
{
	glGetUniformLocation(NULL,NULL);
	rt_back.Clear(0.2941f, 0.2941f, 0.2941f, 1.0f);
	rt_scene.Clear(0.3921f, 0.3921f, 0.3921f, 1.0f);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);

	glBindFramebuffer(GL_FRAMEBUFFER, rt_scene.fbo);
	glViewport(0, 0, rt_scene.width, rt_scene.height);
	camera.setOrthoMatrix();

	if(bdrawbglayer01)
		tilemap_back.draw(&camera);
	if(bdrawbglayer02)
		tilemap_front.draw(&camera);
	if(bdrawbglayer03 && tilemap_back.has_c_Map)
		DrawCollisionMap();

	R_drawWorldDebug();

	glViewport(0, 0, client_rect.w, client_rect.h);
	R_setScreenOrtho();
	s_srcRect = ScreenRect(lmenuw/client_rect.w,0,1.0 - ((lmenuw + rmenuw)/client_rect.w),1);
	s_dstRect = ScreenRect(lmenuw, 0, client_rect.w - (lmenuw + rmenuw), client_rect.h);
	DrawQuadDS(rt_back, rt_scene,&s_dstRect,&s_srcRect, NULL);

	glViewport(0, 0, client_rect.w, client_rect.h);
	glBindFramebuffer(GL_FRAMEBUFFER, debug_rendertarget.fbo);
	glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	R_setScreenOrtho();

	DrawLeftPanel();
	DrawRightPanel();	
	DrawClientBorder();

	R_setPostProcessingOrtho();
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	DrawFullscreenQuad(rt_back, debug_rendertarget, NULL);

	glFlush();
	bdoublebuffer ? SwapBuffers( hDC ) : glDrawBuffer(GL_FRONT);
}
void 
CoordArg::setCoord( int32 lat, int32 lon, const TileMap& tileMap ) 
{
   TileMapCoord coord( lat, lon );
   // Snap the coordinate to a pixel in the tile map.
   tileMap.snapCoordToPixel( coord );
   
   m_coord = coord;
}
Example #30
0
Tile* Map::getTile(unsigned short _x, unsigned short _y, unsigned char _z)
{
  if (_z < MAP_LAYER)
  {
    // _x & 0x3F  is like _x % 64
	// _x & 0x1F  is like _x % 32
    TileMap *tm = &tileMaps[_x & 0x1F][_y & 0x1F][_z];

    // search in the stl map for the requested tile
    TileMap::iterator it = tm->find((_x << 16) | _y);

    // ... found
    if (it != tm->end())
      return it->second;
  }
	
	 // or not
  return NULL;
}