本文整理汇总了C++中Tilemap类的典型用法代码示例。如果您正苦于以下问题:C++ Tilemap类的具体用法?C++ Tilemap怎么用?C++ Tilemap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tilemap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:thecherry94,项目名称:ClanLib_2D_Dijkstra_Test,代码行数:32,代码来源:App.cpp
示例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;
}
开发者ID:spajus,项目名称:sdl2-snake,代码行数:30,代码来源:game.cpp
示例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();
}
开发者ID:KSLcom,项目名称:caesaria-game,代码行数:13,代码来源:terrain_generator.cpp
示例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 );
}
开发者ID:brobits,项目名称:opencaesar3,代码行数:15,代码来源:astarpathfinding.cpp
示例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 );
}
}
开发者ID:brobits,项目名称:opencaesar3,代码行数:17,代码来源:loader.cpp
示例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;
}
开发者ID:Hume2,项目名称:level_gen,代码行数:56,代码来源:prekazitor.cpp
示例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;
}
开发者ID:Limenut,项目名称:Platform,代码行数:55,代码来源:main.cpp
示例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 ) );
}
开发者ID:dalerank,项目名称:caesaria-game,代码行数:11,代码来源:tilearea.cpp
示例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);
}
}
开发者ID:imclab,项目名称:gamelabs,代码行数:21,代码来源:builder.cpp
示例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;
}
开发者ID:DreamTeamHelha,项目名称:ProjectCpp,代码行数:35,代码来源:tilemaploader.cpp
示例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 )) );
}
}
开发者ID:andrelago13,项目名称:caesaria-game,代码行数:40,代码来源:pathway.cpp
示例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() )) );
}
开发者ID:andrelago13,项目名称:caesaria-game,代码行数:14,代码来源:pathway.cpp
示例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 );
}
开发者ID:brobits,项目名称:opencaesar3,代码行数:24,代码来源:loader.cpp
示例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;
}
开发者ID:Limenut,项目名称:Platform,代码行数:17,代码来源:main.cpp
示例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;
}
//.........这里部分代码省略.........
开发者ID:AlexanderMladenov,项目名称:Pacman,代码行数:101,代码来源:Pacman.cpp
示例16: m_tm
BackgroundGenerator::BackgroundGenerator(Tilemap tm): m_tm(tm), m_currLine(tm.getHeight()), m_isWindowBeingCreated(true), m_windowLine(1), m_windowPos(10), m_lineSinceLastWindow(0)
{
}
开发者ID:dolfinsbizou,项目名称:Paper-Plane-Fork,代码行数:4,代码来源:BackgroundGenerator.cpp
示例17: paintTileWallCorners
void Builder::paintTileWallCorners(Tilemap& tileMap, uint32_t tileY, uint32_t tileX,
const TileBrush& brush)
{
uint16_t cornerMask = kTileDirection_N | kTileDirection_W |
kTileDirection_S | kTileDirection_E;
Tile& thisTile = tileMap.at(tileY, tileX);
if (thisTile.wall)
{
// this tile already has a wall - no need to run tests
return;
}
//printf("at (%u,%u) => ", tileX, tileY);
uint16_t wallRoleFlags = 0;
if (tileY > 0)
{
const Tile& north = tileMap.at(tileY-1, tileX);
//printf("north:[%u,%u], ", north.floor, north.wall);
if (!tileWallsEqual(north, kTileDirection_W, brush.tileClassId) &&
!tileWallsEqual(north, kTileDirection_E, brush.tileClassId) &&
!tileWallsEqual(north, kTileDirection_NW, brush.tileClassId) &&
!tileWallsEqual(north, kTileDirection_NE, brush.tileClassId))
{
cornerMask &= ~(kTileDirection_N);
}
}
if (tileX > 0)
{
const Tile& west = tileMap.at(tileY, tileX-1);
//printf("west:[%u,%u], ", west.floor, west.wall);
if (!tileWallsEqual(west, kTileDirection_N, brush.tileClassId) &&
!tileWallsEqual(west, kTileDirection_S, brush.tileClassId) &&
!tileWallsEqual(west, kTileDirection_NW, brush.tileClassId) &&
!tileWallsEqual(west, kTileDirection_SW, brush.tileClassId))
{
cornerMask &= ~(kTileDirection_W);
}
}
if (tileY < tileMap.rowCount()-1)
{
const Tile& south = tileMap.at(tileY+1, tileX);
//printf("south:[%u,%u], ", south.floor, south.wall);
if (!tileWallsEqual(south, kTileDirection_W, brush.tileClassId) &&
!tileWallsEqual(south, kTileDirection_E, brush.tileClassId) &&
!tileWallsEqual(south, kTileDirection_SW, brush.tileClassId) &&
!tileWallsEqual(south, kTileDirection_SE, brush.tileClassId))
{
cornerMask &= ~(kTileDirection_S);
}
}
if (tileX < tileMap.columnCount()-1)
{
const Tile& east = tileMap.at(tileY, tileX+1);
//printf("east:[%u,%u], ", east.floor, east.wall);
if (!tileWallsEqual(east, kTileDirection_S, brush.tileClassId) &&
!tileWallsEqual(east, kTileDirection_N, brush.tileClassId) &&
!tileWallsEqual(east, kTileDirection_NE, brush.tileClassId) &&
!tileWallsEqual(east, kTileDirection_SE, brush.tileClassId))
{
cornerMask &= ~(kTileDirection_E);
}
}
if (cornerMask & kTileDirection_W)
{
if (cornerMask & kTileDirection_N)
wallRoleFlags |= kTileDirection_NW;
else if (cornerMask & kTileDirection_S)
wallRoleFlags |= kTileDirection_SW;
}
if (!wallRoleFlags && (cornerMask & kTileDirection_N))
{
if (cornerMask & kTileDirection_E)
wallRoleFlags |= kTileDirection_NE;
}
if (!wallRoleFlags && (cornerMask & kTileDirection_E))
{
if (cornerMask & kTileDirection_S)
wallRoleFlags |= kTileDirection_SE;
}
//printf("cornerFlags, wallRoleFlags (%04x,%04x)\n",
// cornerMask, wallRoleFlags);
wallRoleFlags |= (kTileRole_Wall+kTileRole_Corner);
TileHandle wallTileHandle =
_tileTemplates.tileHandleFromDescriptor(brush.tileCategoryId,
brush.tileClassId,
wallRoleFlags);
thisTile.wall = wallTileHandle;
}
开发者ID:imclab,项目名称:gamelabs,代码行数:94,代码来源:builder.cpp
示例18: append
TilesArea::TilesArea(const Tilemap &tmap, const TilePos& leftup, const Size& size)
{
_size = size;
append( tmap.area( leftup, size ) );
}
开发者ID:dalerank,项目名称:caesaria-game,代码行数:5,代码来源:tilearea.cpp
示例19: Update
void Player::Update(Tilemap &t, sf::RenderWindow &window, BackgroundProcesses &b)
{
m_top = m_rect.getPosition().y;
m_bottom = m_rect.getPosition().y + m_rect.getSize().y;
m_left = m_rect.getPosition().x;
m_right = m_rect.getPosition().x + m_rect.getSize().x;
//collision with portal
if(t.getLevelMap(m_bottom/64, m_left/64) == 999 || t.getLevelMap(m_bottom/64, m_right/64) == 999 || t.getLevelMap(m_top/64, m_left/64) == 999 || t.getLevelMap(m_top/64, m_right/64) == 999)
{
setPosition(sf::Vector2f(0, 0));
t.setMap(window);
}
//respawning when falling through the bottom of the map!!
if(m_bottom >= 30*64)
{
setPosition(sf::Vector2f(0, 0));
t.setMap(t.getLevel(), window);
}
//downward collision on tilemap
if(m_bottom / 64 < 0 || m_right < 0)
m_onGround = false;
else if(int(m_bottom) % 64 != 0)
m_onGround = false;
else if( (t.getLevelMap(m_bottom/64, m_left/64) >= 100 && t.getLevelMap(m_bottom/64, m_left/64) < 200) || (t.getLevelMap(m_bottom/64, m_left/64) >= 500 && t.getLevelMap(m_bottom/64, m_left/64) < 600) || (t.getLevelMap(m_bottom/64, m_right/64) >= 100 && t.getLevelMap(m_bottom/64, m_right/64) < 200) || (t.getLevelMap(m_bottom/64, m_right/64) >= 500 && t.getLevelMap(m_bottom/64, m_right/64) < 600) )
m_onGround = true;
else
m_onGround = false;
//downward collision on platform
for(int i = 0; i < t.getPlatformSize(); i++)
{
if(m_right < t.getPlatformLeft(i) || m_left > t.getPlatformRight(i) || m_top > t.getPlatformBottom(i) || m_bottom < t.getPlatformTop(i))
{}
else if(int(m_bottom) <= t.getPlatformTop(i))
m_onGround = true;
}
int whichCrate = -1;
for(int i = 0; i < t.getCrateSize(); i++)
{
//downward collision on crate
if(m_right < t.getCrateLeft(i) || m_left > t.getCrateRight(i) || m_top > t.getCrateBottom(i) || m_bottom < t.getCrateTop(i))
{}
else if(m_bottom >= t.getCrateTop(i) && m_bottom - 2 <= t.getCrateTop(i) && m_right - 2 > t.getCrateLeft(i) && m_left + 2 < t.getCrateRight(i))
{
m_onGround = true;
m_onCrate = true;
whichCrate = i;
break;
}
else
{
m_onCrate = false;
}
}
for(int i = 0; i < t.getCrateSize(); i++)
{
//downward collision on crate
/*if(m_right < t.getCrateLeft(i) || m_left > t.getCrateRight(i) || m_top > t.getCrateBottom(i) || m_bottom < t.getCrateTop(i))
{}
else if(m_bottom >= t.getCrateTop(i) && m_bottom - 2 <= t.getCrateTop(i) && m_right - 2 > t.getCrateLeft(i) && m_left + 2 < t.getCrateRight(i))
{
m_onGround = true;
m_onCrate = true;
}
else
{
m_onCrate = false;
} */
if(i != whichCrate)
{
//not colliding with crate
if(m_right < t.getCrateLeft(i) || m_left > t.getCrateRight(i) || m_top > t.getCrateBottom(i) || m_bottom < t.getCrateTop(i))
{}
//on top of crate
else if(m_top <= t.getCrateBottom(i) && m_top >= (t.getCrateBottom(i) - 2))
{
t.setCratePos(i, sf::Vector2f(t.getCrateLeft(i), m_top - (t.getCrateBottom(i) - t.getCrateTop(i))));
}
//pushing crate right
else if(m_right >= t.getCrateLeft(i) && m_left < t.getCrateLeft(i))
{
if(m_movement.x > 0)
t.setCratePos(i, sf::Vector2f(m_right, t.getCrateTop(i)));
}
//pushing crate left
else if(m_left <= t.getCrateRight(i) && m_left > t.getCrateLeft(i))
{
if(m_movement.x < 0)
t.setCratePos(i, sf::Vector2f(m_left - (t.getCrateRight(i) - t.getCrateLeft(i)), t.getCrateTop(i)));
}
}
//.........这里部分代码省略.........
开发者ID:Nicholas-Swift,项目名称:Game-of-Crates,代码行数:101,代码来源:Player.cpp
示例20: xml
void Level::Load(const std::string &filename, Scene* scene)
{
// load from an xml file, into the scene
if (scene != NULL)
{
instance->scene = scene;
}
if (instance->scene)
{
// unload tilemaps... (need to destroy them?)
instance->tilemaps.clear();
//clearfringeTileset
TiXmlDocument xml(Assets::GetContentPath() + filename);
instance->filename = filename;
bool isLoaded = xml.LoadFile();
if (isLoaded)
{
TiXmlElement* eLevel = xml.FirstChildElement("Level");
if (eLevel)
{
instance->width = XMLReadInt(eLevel, "width");
instance->height = XMLReadInt(eLevel, "height");
TiXmlElement *eTilemap = eLevel->FirstChildElement("Tilemap");
while (eTilemap)
{
Entity *entity = new Entity();
Tilemap *tilemap = new Tilemap(instance->GetTilesetByName(XMLReadString(eTilemap, "set")), instance->width, instance->height, XMLReadInt(eTilemap, "tileWidth"), XMLReadInt(eTilemap, "tileHeight"));
instance->tilemaps.push_back(tilemap);
entity->SetGraphic(tilemap);
instance->scene->Add(entity);
TiXmlElement *eTile = eTilemap->FirstChildElement("Tile");
while (eTile)
{
tilemap->SetTile(XMLReadInt(eTile, "x"), XMLReadInt(eTile, "y"), XMLReadInt(eTile, "tileID"));
eTile = eTile->NextSiblingElement("Tile");
}
eTilemap = eTilemap->NextSiblingElement("Tilemap");
}
TiXmlElement *eFringeTiles = eLevel->FirstChildElement("FringeTiles");
while (eFringeTiles)
{
FringeTileset *fringeTileset = instance->GetFringeTilesetByName(XMLReadString(eFringeTiles, "set"));
/*
Entity *entity = new Entity();
Tilemap *tilemap = new Tilemap(instance->GetTileset(XMLString(eTilemap, "set")), instance->width, instance->height, XMLInt(eTilemap, "tileWidth"), XMLInt(eTilemap, "tileHeight"));
instance->tilemaps.push_back(tilemap);
entity->SetGraphic(tilemap);
instance->scene->Add(entity);
*/
if (fringeTileset)
{
TiXmlElement *eFringeTile = eFringeTiles->FirstChildElement("FringeTile");
while (eFringeTile)
{
int tileID = XMLReadInt(eFringeTile, "id");
int layer = XMLReadInt(eFringeTile, "layer");
Vector2 position = Vector2(XMLReadFloat(eFringeTile, "x"), XMLReadFloat(eFringeTile, "y"));
Vector2 scale = Vector2::one;
if (eFringeTile->Attribute("scaleX") != NULL && eFringeTile->Attribute("scaleY") != NULL)
scale = Vector2(XMLReadFloat(eFringeTile, "scaleX"), XMLReadFloat(eFringeTile, "scaleY"));
int rotation = XMLReadFloat(eFringeTile, "rotation");
Color color = Color::white;
if (eFringeTile->Attribute("ca"))
{
color.a = XMLReadFloat(eFringeTile, "ca");
}
AddFringeTile(fringeTileset, tileID, layer, position, scale, rotation, color);
eFringeTile = eFringeTile->NextSiblingElement("FringeTile");
}
}
eFringeTiles = eFringeTiles->NextSiblingElement("FringeTiles");
}
}
}
}
}
开发者ID:FrozenCow,项目名称:Monocle-Engine,代码行数:95,代码来源:Level.cpp
注:本文中的Tilemap类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论