本文整理汇总了C++中TileMap类的典型用法代码示例。如果您正苦于以下问题:C++ TileMap类的具体用法?C++ TileMap怎么用?C++ TileMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TileMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: p
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();
}
示例2:
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;
}
示例3:
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;
}
示例4: file
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;
}
示例5: tokenize
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;
}
示例6: test_both
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;
}
示例7: beautify
// 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);
}
}
}
}
}
示例8: main
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;
}
示例9: checker
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;
}
示例10: props
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";
}
}
示例11: StringLines
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);
}
示例12: loadTileMap
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;
}
示例13:
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;
}
示例14:
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();
}
}
示例15: checkProjectileCollision
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;
}