本文整理汇总了C++中Tilemap类的典型用法代码示例。如果您正苦于以下问题:C++ Tilemap类的具体用法?C++ Tilemap怎么用?C++ Tilemap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tilemap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: win
int App::main(const std::vector<std::string>& args)
{
clan::DisplayWindowDescription desc;
desc.set_position(clan::Rect(-800, 100, clan::Size(800, 600)), false);
desc.set_title("ClanLib 2D Dijkstra Test");
desc.set_allow_resize(false);
clan::DisplayWindow win(desc);
clan::Canvas canvas(win);
m_canvas = canvas;
Tilemap map;
map.build_map(31);
clan::GameTime game_time;
while(!win.get_ic().get_keyboard().get_keycode(clan::keycode_escape))
{
game_time.update();
canvas.clear();
map.draw(canvas);
map.update(win.get_ic(), game_time.get_time_elapsed());
win.flip();
clan::KeepAlive::process();
}
map.reset();
return 0;
}
示例2: SDL_CreateWindow
void Snake::Game::init() {
if (SDL_Init(SDL_INIT_EVERYTHING) >= 0) {
window = SDL_CreateWindow("SDL Snake",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
640, 480,
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
if (window != 0) {
renderer = SDL_CreateRenderer(window, -1,
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
}
} else {
Snake::Utils::logSDLError(std::cout, "Failed initializing SDL");
is_running = false;
}
Tilemap* tilemap = Tilemap::instance();
tilemap->init(renderer, 32, 32);
tilemap->addTile("../resources/images/grass.png", "grass");
tilemap->addTile("../resources/images/snake_head.png", "snake_head");
tilemap->addTile("../resources/images/snake_body.png", "snake_body");
player = new Player();
player->load(100, 100);
for (int i = 0; i < 100; i++) {
player->growTail();
}
is_running = true;
}
示例3: sideTiles
TilesArray sideTiles( int side, Tilemap& oTilemap )
{
int mapSize = oTilemap.size();
switch( side % 4 )
{
case 0: return oTilemap.getArea( TilePos( 0, 0), TilePos( 0, mapSize-1 ) );
case 1: return oTilemap.getArea( TilePos( 0, mapSize-1), TilePos( mapSize-1, mapSize-1 ) );
case 2: return oTilemap.getArea( TilePos( mapSize-1, mapSize-1), TilePos( mapSize-1, 0 ) );
case 3: return oTilemap.getArea( TilePos( mapSize-1, 0), TilePos( 0, 0 ) );
}
return TilesArray();
}
示例4: TilePos
void Pathfinder::update( const Tilemap& tilemap )
{
_d->tilemap = const_cast< Tilemap* >( &tilemap );
_d->grid.resize( tilemap.getSize() );
for( int k=0; k < tilemap.getSize(); k++)
{
_d->grid[ k ].resize( tilemap.getSize());
}
TilemapTiles tiles = _d->tilemap->getArea( TilePos( 0, 0 ), Size( tilemap.getSize() ) );
foreach( Tile* tile, tiles )
{
_d->grid[ tile->getI() ][ tile->getJ() ] = new AStarPoint( tile );
}
示例5: TilePos
void GameLoader::Impl::initWaterTileAnimation( Tilemap& tmap )
{
TilemapArea area = tmap.getArea( TilePos( 0, 0 ), Size( tmap.getSize() ) );
Animation water;
water.setFrameDelay( 12 );
water.load( ResourceGroup::land1a, 121, 7 );
water.load( ResourceGroup::land1a, 127, 7, true );
foreach( Tile* tile, area )
{
int rId = tile->getOriginalImgId() - 364;
if( rId >= 0 && rId < 8 )
{
water.setCurrentIndex( rId );
tile->setAnimation( water );
}
}
示例6: exp_rand
bool Prekazitor::tajna_chodba() {
bool sm = !(nahodne(2));
if (!uprav_smer(sm, 4)) {
return false;
}
int delka = exp_rand(6, max_x-(*X)-4) + 3;
if (delka < 3) {
return false;
}
Tilemap* tm = new Tilemap(delka, 4, false);
tm->pojmenuj("secretTM",s->tajnych_chodeb);
tm->z_pos = 101 + s->tajnych_chodeb;
tm->cesta = new Cesta();
float x, y;
if (sm) {
dolovak(4);
stredovak(delka);
s->intact2->obdelnik(K[1] , (*X)-delka-1, (*X)-3, (*Y)-5, (*Y)-5);
s->intact2->obdelnik(K[4] , (*X)-delka-1, (*X)-3, (*Y)-4, (*Y)-4);
s->intact2->obdelnik(K[10], (*X)-delka-1, (*X)-3, (*Y)-3, (*Y)-3);
s->intact2->poloz_blok(K[2] , (*X)-2, (*Y)-5);
s->intact2->poloz_blok(K[5] , (*X)-2, (*Y)-4);
s->intact2->poloz_blok(K[11], (*X)-2, (*Y)-3);
s->intact2->poloz_blok(V[0], (*X)-delka-1, (*Y)-3);
tm->obdelnik(S, 0, tm->sirka-2, 0, tm->vyska-1);
tm->obdelnik(K[8], tm->sirka-1, tm->sirka-1, 0, tm->vyska-3);
tm->poloz_blok(V[2], tm->sirka-1, tm->vyska-2);
tm->poloz_blok(V[4], tm->sirka-1, tm->vyska-1);
x = (*X)-delka-1;
y = (*Y)-3;
} else {
stredovak(delka);
nahorovak(4);
s->intact2->poloz_blok(K[0], (*X)-delka, (*Y)-1);
s->intact2->poloz_blok(K[3], (*X)-delka, *Y);
s->intact2->poloz_blok(K[9], (*X)-delka, (*Y)+1);
s->intact2->obdelnik(K[1] , (*X)-delka+1, *X, (*Y)-1, (*Y)-1);
s->intact2->obdelnik(K[4] , (*X)-delka+1, *X, *Y, *Y);
s->intact2->obdelnik(K[10], (*X)-delka+1, *X, (*Y)+1, (*Y)+1);
s->intact2->poloz_blok(V[1], (*X)-1, (*Y)+1);
tm->obdelnik(S, 1, tm->sirka-1, 0, tm->vyska-1);
tm->obdelnik(K[6], 0, 0, 0, tm->vyska-3);
tm->poloz_blok(V[3], 0, tm->vyska-2);
tm->poloz_blok(V[5], 0, tm->vyska-1);
x = (*X)-delka;
y = (*Y)+1;
}
secretarea(x, y, tm);
stredovak(1);
s->tilemapy.push_back(tm);
s->tajnych_chodeb++;
return true;
}
示例7: scanDistance
double Character::scanDistance(double edge, const Tilemap& map, Direction direction, intVector firstTile, intVector lastTile)
{
double distance;
//indices of tile to be checked
int xi;
int yi;
//to keep track of smallest value
int minDist = 1000000;
int distIndex;
//for each occupied tile, shoot a ray in desired direction
//insert smallest value in distance
for (int i = firstTile.y; i <= lastTile.y; i++)
{
for (int j = firstTile.x; j <= lastTile.x; j++)
{
yi = i;
xi = j;
distIndex = 0;
while (
distIndex < minDist
&& xi >= 0
&& yi >= 0
&& xi < map.horiTiles
&& yi < map.vertiTiles
&& map.getTile(xi, yi) != 1
)
{
switch (direction)
{
case LEFT: xi--; break;
case RIGHT: xi++; break;
case UP: yi--; break;
case DOWN: yi++; break;
}
distIndex++;
}
minDist = min(minDist, distIndex);
}
}
switch (direction)
{
case LEFT: distance = edge - (xi + 1)*map.tileRes; break;
case RIGHT: distance = xi*map.tileRes - edge; break;
case UP: distance = edge - (yi + 1)*map.tileRes; break;
case DOWN: distance = yi*map.tileRes - edge; break;
}
return signbit(distance) ? 0.0 : distance;
}
示例8: offset
TilesArea::TilesArea(const Tilemap& tmap, int distance, OverlayPtr overlay)
{
if( overlay.isNull() )
return;
TilePos offset( distance, distance );
TilePos size( overlay->size().width(), overlay->size().height() );
TilePos start = overlay->tile().epos();
_size = overlay->size();
append( tmap.area( start - offset, start + size + offset ) );
}
示例9: _map
Builder::Builder(Map& map,
const TileDatabase& tileTemplates,
uint32_t roomLimit) :
_map(map),
_tileTemplates(tileTemplates)
{
_regions.reserve(roomLimit);
_segments.reserve(roomLimit*8);
_connections.reserve(roomLimit*8);
// clear all tilemaps
const cinekine::overview::MapBounds& bounds = _map.bounds();
for (uint32_t z = 0; z < bounds.zUnits; ++z)
{
Tilemap* tilemap = _map.tilemapAtZ(z);
Tile zeroTile = { 0, 0 };
tilemap->fillWithValue(zeroTile, 0, 0, bounds.yUnits, bounds.xUnits);
}
}
示例10: QImage
Tilemap* TilemapLoader::load(QString path)
{
QImage *image = new QImage(path);
if(image->isNull())
{
QMessageBox::information(nullptr, "Erreur", "L'image n'est pas trouvée!");
return nullptr;
}
Tilemap *tilemap = new Tilemap();
tilemap->setHeight(image->height());
tilemap->setWidth(image->width());
for(int heightCount = 0;heightCount<image->height(); heightCount++)
{
for(int widthCount = 0;widthCount<image->width();widthCount++)
{
QRgb color = image->pixel(widthCount,heightCount);
switch(color)
{
case ASPHALT: tilemap->setTile(widthCount,heightCount,GroundType::Asphalt);
break;
case MUD: tilemap->setTile(widthCount,heightCount,GroundType::Mud);
break;
default : tilemap->setTile(widthCount,heightCount,GroundType::Grass);
}
}
}
return tilemap;
}
示例11: setNextDirection
void Pathway::setNextDirection( const Tilemap& tmap, Direction direction)
{
switch (direction)
{
case direction::north :
_d->endPos += TilePos( 0, 1 );
break;
case direction::northEast :
_d->endPos += TilePos( 1, 1 );
break;
case direction::east :
_d->endPos += TilePos( 1, 0 );
break;
case direction::southEast :
_d->endPos += TilePos( 1, -1 );
break;
case direction::south :
_d->endPos += TilePos( 0, -1 );
break;
case direction::southWest :
_d->endPos += TilePos( -1, -1 );
break;
case direction::west :
_d->endPos += TilePos( -1, 0 );
break;
case direction::northWest :
_d->endPos += TilePos( -1, 1 );
break;
default:
_d->endPos += TilePos( 0, 1 );
break;
Logger::warning( "Unexpected Direction:%d", direction);
break;
}
if( tmap.isInside( _d->endPos ) )
{
_d->tiles.push_back( const_cast<Tile*>( &tmap.at( _d->endPos )) );
}
}
示例12: load
void Pathway::load(const Tilemap& tmap, const VariantMap& stream )
{
if( stream.empty() )
{
return;
}
VARIANT_LOAD_ANY_D( _d, startPos, stream )
VARIANT_LOAD_ANY_D( _d, endPos, stream )
VariantList vmTiles = stream.get( literals::tiles ).toList();
foreach( it, vmTiles )
{
_d->tiles.push_back( const_cast<Tile*>( &tmap.at( it->toTilePos() )) );
}
示例13: if
void GameLoader::Impl::initEntryExitTile( const TilePos& tlPos, Tilemap& tileMap, const unsigned int picIdStart, bool exit )
{
unsigned int idOffset = 0;
TilePos tlOffset;
if( tlPos.getI() == 0 || tlPos.getI() == tileMap.getSize() - 1 )
{
tlOffset = TilePos( 0, 1 );
idOffset = (tlPos.getI() == 0 ? 1 : 3 );
}
else if( tlPos.getJ() == 0 || tlPos.getJ() == tileMap.getSize() - 1 )
{
tlOffset = TilePos( 1, 0 );
idOffset = (tlPos.getJ() == 0 ? 2 : 0 );
}
Tile& signTile = tileMap.at( tlPos + tlOffset );
StringHelper::debug( 0xff, "(%d, %d)", tlPos.getI(), tlPos.getJ() );
StringHelper::debug( 0xff, "(%d, %d)", tlOffset.getI(), tlOffset.getJ() );
signTile.setPicture( ResourceGroup::land3a, picIdStart + idOffset );
signTile.setFlag( Tile::tlRock, true );
}
示例14: checkMapCollision
bool checkMapCollision(Character& scanner, const Tilemap& map)
{
int x1 = scanner.rect.x / map.tileRes;
int x2 = (scanner.rect.x + scanner.rect.w - 1) / map.tileRes;
int y1 = scanner.rect.y / map.tileRes;
int y2 = (scanner.rect.y + scanner.rect.h - 1) / map.tileRes;
for (int x = x1; x <= x2; x++)
{
for (int y = y1; y <= y2; y++)
{
if (x < 0 || x >= map.horiTiles || y < 0 || y >= map.vertiTiles) continue;
if (map.getTile(x, y) == 1) return true;
}
}
return false;
}
示例15: Update
void Pacman::Update(const SDLInput& input, Tilemap& tilemap, float deltaTime, const std::shared_ptr<SDLRenderTarget>& tileSurface, const std::vector<SDLSurface>& gridSurf)
{
if (m_State == PacState::PowerUp) // if powered up
{
float currentTime = Timer::GetTime();
if ((currentTime - m_powerDuration) > 5.f) // if powered up for more tha 5 seconds
{
m_State = PacState::Normal;// return to normal
}
}
//set our speed
float speed = 5.5f * deltaTime;
// clamp position
size_t cX = (size_t)(clamp(m_Position.x, 0.f, 18.f) + 0.5f);
size_t cY = (size_t)(clamp(m_Position.y, 0.f, 22.f) + 0.5f);
switch (m_CurrentDirection) // move in direction
{
case Direction::Left:
m_Position.x -= speed;
break;
case Direction::Right:
m_Position.x += speed;
break;
case Direction::Up:
m_Position.y -= speed;
break;
case Direction::Down:
m_Position.y += speed;
break;
}
//make the side wall let us trough
if (m_Position.x < 0.f)
{
m_Position.x = 19.f;
}
if (m_Position.x > 19.0f)
{
m_Position.x = 0.f;
}
if (m_CurrentDirection == Direction::None && m_NextDirection != Direction::None && tilemap.GetDirectionFlag(cX, cY, (size_t)m_NextDirection))
{// if the current direction is None and the next input direction is not none and we can go in that direction
m_CurrentDirection = m_NextDirection; // switch directions
m_NextDirection = Direction::None; // set next to none
}
if (m_CurrentDirection != Direction::None) // if our current direction is not None ( we are not at base)
{
m_DistanceLeft -= speed; // reduce the distance of travel
if (m_DistanceLeft <= 0.f) //if we have traveled 1 tile
{
if (!tilemap.GetDirectionFlag(cX, cY, (size_t)m_CurrentDirection)) // if the tile we are on dosent have the current direction direction flag set
{
m_CurrentDirection = Direction::None;// make curent dir none
}
if (m_NextDirection != Direction::None) // if we have a pending direction command
{
if (tilemap.GetDirectionFlag(cX, cY, (size_t)m_NextDirection)) // and if the tile we are one has the next direction tag set
{
m_CurrentDirection = m_NextDirection;// go in that direction
}
}
m_DistanceLeft += 1.0f;// add distace to travel
}
}
Rect rect(m_Position.x + 0.05f, m_Position.y + 0.05f, 0.9f, 0.9f);//construct a collision rect;
//get all intersections
auto intersections = tilemap.Intersect(rect);
for (auto &i : intersections) // go trough them
{
if (i.type == Coin) // if its a coin
{
m_Points += 1; // increase points
tilemap.Set(i.x, i.y, Empty); //remove coin
tileSurface->Clear(); // clear tilemap render
tileSurface->RenderTileset(gridSurf, tilemap.GetGrid(), 19, 32.0f);// re - render the grid without the coin.
}
}
//set directions accortind to input keys
if (input.GetKey(Left))
{
m_NextDirection = Direction::Left;
}
if (input.GetKey(Right))
{
m_NextDirection = Direction::Right;
}
//.........这里部分代码省略.........