本文整理汇总了C++中Map::GetMapWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ Map::GetMapWidth方法的具体用法?C++ Map::GetMapWidth怎么用?C++ Map::GetMapWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map::GetMapWidth方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Initialize
AnyAngleAlgorithm::AnyAngleAlgorithm(const MapEnvironment *env)
{
// Read the height and width of the map.
Map* map = env->GetMap();
width_ = map->GetMapWidth() + 2; // Add +2 for the frame of obstacles.
height_ = map->GetMapHeight() + 2;
unblocked_cells_.clear();
// Generate the cells with the padding.
cells_ = new Cell*[width_];
for (unsigned int x = 0; x < width_; x++) {
cells_[x] = new Cell[height_];
}
// Make unblocked cells traversable.
int num_traversable = 0;
for (unsigned int x = 0; x < width_ - 2; x++) {
for (unsigned int y = 0; y < height_ - 2; y++) {
if (map->GetTerrainType(x, y) == kGround) {
cells_[x+1][y+1].is_traversable = true;
num_traversable++;
unblocked_cells_.push_back(xyLoc(x,y));
}
}
}
#ifdef ANY_ANGLE_VERBOSE
std::cout << "Traversable cells: " << num_traversable << std::endl;
#endif
Initialize();
}
示例2:
void TrailMaxUnit<xyLoc,tDirection,MapEnvironment>::OpenGLDraw( int, MapEnvironment *env, SimulationInfo<xyLoc,tDirection,MapEnvironment>* ) {
GLdouble xx, yy, zz, rad;
Map *m = env->GetMap();
if( current_pos.x >= m->GetMapWidth() || current_pos.y >= m->GetMapHeight() ) {
fprintf( stderr, "Warning: TrailMaxUnit is out of bounds. Could not draw it.\n" );
return;
}
m->GetOpenGLCoord( current_pos.x, current_pos.y, xx, yy, zz, rad );
if( done )
glColor3d( 0., 1., 0. ); // turn green when done
else
glColor3f( r, g, b );
DrawSphere( xx, yy, zz, rad );
// draw the path in front of us
if( pathcache.size() > 0 && !done) {
glBegin(GL_LINE_STRIP);
glVertex3f( xx, yy, zz-rad/2 );
for( unsigned int i = 0; i < pathcache.size(); i++ ) {
m->GetOpenGLCoord( pathcache[i].x, pathcache[i].y, xx, yy, zz, rad );
glVertex3f( xx, yy, zz-rad/2 );
}
glEnd();
}
return;
};
示例3: Move
void Bulldog_Physics::Move( Component_Game_Actor& actor, Map &map, float timeStep )
{
int previousx = tempNewX;
int previousy = tempNewY;
//Temporary holdings for the speeds
tempNewX += (int)xVelocity * timeStep;
tempNewY += (int)yVelocity * timeStep;
actorBox.x = tempNewX;
actorBox.y = tempNewY;
//moving right
if( xVelocity > 0 )
{
//Check out of bounds right
if( tempNewX + actorBox.w > map.GetMapWidth() ) {
tempNewX = map.GetMapWidth() - actor.GetGraphics()->GetDestination().w;
StopX();
SetXVelocity( NEGATIVE_MOVEMENT );
}
}
//moving left
else if( xVelocity < 0 )
{
//Check out of bounds left
if( tempNewX < 0 ) {
tempNewX = 0;
StopX();
SetXVelocity( POSITIVE_MOVEMENT );
}
}
actor.GetGraphics()->SetDestinationX( tempNewX );
actor.GetGraphics()->SetDestinationY( tempNewY );
}
示例4: generatePaths
// outputs algorithm/path length/time per step
void generatePaths(char *_map, int mapSizeX, int mapSizeY, int numBuckets, int bucketSize, int pathsPerBucket)
{
// int numBuckets = (int)(mapSize/4.0);
// const int pathsPerBucket = 10;
int pathsLeft = numBuckets*pathsPerBucket;
int iterations = 0;
int maxIterations = 10*numBuckets*pathsPerBucket;
Map *map = new Map(_map);
if ((mapSizeX != -1) && (mapSizeY != -1))
map->Scale(mapSizeX, mapSizeY);
else {
mapSizeX = map->GetMapWidth();
mapSizeY = map->GetMapHeight();
}
MapFlatAbstraction *absMap = new MapFlatAbstraction(map);
Graph *g = absMap->GetAbstractGraph(0);
node *r1, *r2;
// 10 maps/bigMaps/600.map 48 151 55 152 7.4142135624
// bucket, map, sizex, sizey, startx, starty, endx, endy, a* length
printf("# bucket\tmap\tsizex\tsizey\tfromx\tfromy\ttox\ttoy\tA*len\n");
std::vector<int> buckets(numBuckets);
for (int x = 0; x < numBuckets; x++)
buckets[x] = 0;
while ((pathsLeft > 0) && (iterations < maxIterations))
{
iterations++;
// try to find two valid points
do {
r1 = g->GetRandomNode();
r2 = g->GetRandomNode();
} while (!absMap->Pathable(r1, r2) || (r1 == r2) ||
((iterations > maxIterations/2) && (absMap->h(r1, r2) > numBuckets*bucketSize)));
aStar a;
path *p;
p = a.GetPath(absMap, r1, r2);
int cnt = 0;
double length = 0;
for (path *q = p; q; q = q->next)
{
if (q && q->next)
{
double t1, t2;
t1 = q->n->GetLabelL(kFirstData)-q->next->n->GetLabelL(kFirstData);
t2 = q->n->GetLabelL(kFirstData+1)-q->next->n->GetLabelL(kFirstData+1);
length += sqrt(t1*t1+t2*t2);
}
cnt++;
}
if ((length > numBuckets*bucketSize) ||
((iterations > maxIterations/2) && (buckets[(int)length/bucketSize] == pathsPerBucket)))
{
while (p && p->next)
{
double t1, t2;
t1 = p->n->GetLabelL(kFirstData)-p->next->n->GetLabelL(kFirstData);
t2 = p->n->GetLabelL(kFirstData+1)-p->next->n->GetLabelL(kFirstData+1);
length -= sqrt(t1*t1+t2*t2);
path *t = p;
p = p->next;
t->next = 0; delete t;
if (p->next == 0)
{
delete p;
p = 0;
}
if (p == 0)
break;
if (buckets[(int)length/numBuckets] < pathsPerBucket)
break;
}
if (p && p->next)
{
r1 = p->n;
for (path *q = p; q; q = q->next)
{
r2 = q->n;
}
delete p;
p = a.GetPath(absMap, r1, r2);
length = 0; cnt = 0;
for (path *q = p; q; q = q->next)
{
if (q && q->next)
{
double t1, t2;
t1 = q->n->GetLabelL(kFirstData)-q->next->n->GetLabelL(kFirstData);
t2 = q->n->GetLabelL(kFirstData+1)-q->next->n->GetLabelL(kFirstData+1);
length += sqrt(t1*t1+t2*t2);
}
cnt++;
}
//.........这里部分代码省略.........
示例5: MyRandomUnitKeyHandler
void MyRandomUnitKeyHandler(unsigned long windowID, tKeyboardModifier mod, char)
{
// if (mod == kShiftDown)
// {
// RunWorkMeasureTest();
// return;
// }
Map *m = unitSims[windowID]->GetEnvironment()->GetMap();
unitSims[windowID]->ClearAllUnits();
m->SetTileSet(kFast);
// recording = true;
// startRecording();
int x1, y1, x2, y2;
if (mod == kShiftDown)
{
x1 = 0; y1 = 0;
x2 = m->GetMapWidth()-1;
// x2 = 0;//m->GetMapWidth()-1;
y2 = m->GetMapHeight()-1;
}
else {
do {
x2 = random()%m->GetMapWidth();
y2 = random()%m->GetMapHeight();
x1 = random()%m->GetMapWidth();
y1 = random()%m->GetMapHeight();
} while ((m->GetTerrainType(x1, y1) != kGround) || (m->GetTerrainType(x2, y2) != kGround));
do {
x2 = random()%m->GetMapWidth();
y2 = random()%m->GetMapHeight();
x1 = random()%m->GetMapWidth();
y1 = random()%m->GetMapHeight();
} while ((m->GetTerrainType(x1, y1) != kGround) || (m->GetTerrainType(x2, y2) != kGround));
}
//x1 = 6; y1 = 3; x2 = 15; y2 = 72;
xySpeedHeading a(x1, y1), b(x2, y2);
//xySpeedHeading a(0, 0), b(mazeSize-1, mazeSize-1);
// xySpeedHeading a(0, 0), b(mazeSize-1, 0);
a1.GetPath(unitSims[windowID]->GetEnvironment(), a, b, path);
std::cout << "Found path -- " << a1.GetNodesExpanded() << " nodes expanded; length: " << unitSims[windowID]->GetEnvironment()->GetPathLength(path) << std::endl;
std::cout << "Solving " << a << " to " << b << std::endl;
stepsPerFrame = 1.0/120.0;
// GLdouble a1, b1, c1, r1;
// m->GetOpenGLCoord((x1+x2)/2, (y1+y2)/2, a1, b1, c1, r1);
// cameraMoveTo(a1, b1, c1-600*r1, 1.0);
// cameraLookAt(a1, b1, c1, 1.0);
// measure.MeasureDifficultly(unitSims[windowID]->GetEnvironment(), a, b);
// measure.ShowHistogram();
// LocalSensing::RIBS<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment> *u1 = new LocalSensing::RIBS<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment>(a, b);
// u1->SetWeight(1.0);
// u1->SetSpeed(0.02);
// unitSims[windowID]->AddUnit(u1);
// LSSLRTAStarUnit<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment> *u2 = new LSSLRTAStarUnit<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment>(a, b, new LSSLRTAStar<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment>(1));
// u2->SetSpeed(0.02);
// unitSims[windowID]->AddUnit(u2);
LSSLRTAStarUnit<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment> *u2 = new LSSLRTAStarUnit<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment>(a, b, new LSSLRTAStar<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment>(10));
u2->SetSpeed(0.02);
unitSims[windowID]->AddUnit(u2);
// LSSLRTAStarUnit<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment> *u3 = new LSSLRTAStarUnit<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment>(a, b, new LSSLRTAStar<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment>(10));
// u3->SetSpeed(0.02);
// unitSims[windowID]->AddUnit(u3);
// FLRTAStarUnit<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment> *u4 = new FLRTAStarUnit<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment>(a, b, new FLRTA::FLRTAStar<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment>(10, 1.5));
// u4->SetSpeed(0.02);
// unitSims[windowID]->AddUnit(u4);
//
// FLRTAStarUnit<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment> *u5 = new FLRTAStarUnit<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment>(a, b, new FLRTA::FLRTAStar<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment>(10, 5.5));
// u5->SetSpeed(0.02);
// unitSims[windowID]->AddUnit(u5);
//
FLRTA::FLRTAStar<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment> *f;
FLRTAStarUnit<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment> *u6 = new FLRTAStarUnit<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment>(a, b, f = new FLRTA::FLRTAStar<xySpeedHeading, deltaSpeedHeading, Directional2DEnvironment>(10, 1.5));
f->SetOrderRedundant(false);
f->SetUseLocalGCost(true);
u6->SetSpeed(0.02);
unitSims[windowID]->AddUnit(u6);
unitSims[windowID]->GetStats()->AddFilter("trialDistanceMoved");
unitSims[windowID]->GetStats()->AddFilter("TotalLearning");
unitSims[windowID]->GetStats()->AddFilter("nodesExpanded");
unitSims[windowID]->GetStats()->EnablePrintOutput(true);
unitSims[windowID]->SetTrialLimit(50000);
SetNumPorts(windowID, 1+(unitSims[windowID]->GetNumUnits()-1)%MAXPORTS);
}
示例6: Move
void Corgi_Physics::Move( Component_Game_Actor& actor, Map &map, float timeStep )
{
int previousx = tempNewX;
int previousy = tempNewY;
//Temporary holdings for the speeds
tempNewX += (int)xVelocity * timeStep;
tempNewY += (int)yVelocity * timeStep;
actorBox.x = tempNewX;
actorBox.y = tempNewY;
//moving right
if( xVelocity > 0 )
{
//Check out of bounds right
if( tempNewX + actorBox.w < map.GetMapWidth() ) {
//Get the tile where the actor is
xTile = ( tempNewX + actorBox.w ) / TILE_SIZE;
yTile = tempNewY / TILE_SIZE;
int midTile = ( tempNewY + ( actorBox.h / 2 ) ) / TILE_SIZE;
//int botTile = ( tempNewY + actorBox.h - 1 ) / TILE_SIZE;
//Check the tile just to the right
if( map.GetCollision( xTile, yTile ) || map.GetCollision( xTile, midTile ) ) {
//Check box collision for all tiles in front of the character.
if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, yTile ), actorBox ) ) {
actorBox.x = previousx;
tempNewX = previousx;
StopX();
SetXVelocity( NEGATIVE_MOVEMENT );
} else if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, midTile ), actorBox ) ) {
actorBox.x = previousx;
tempNewX = previousx;
StopX();
SetXVelocity( NEGATIVE_MOVEMENT );
} /*else if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, botTile ), actorBox ) ) {
actorBox.x = previousx;
tempNewX = previousx;
} */
}
} else {
tempNewX = map.GetMapWidth() - actor.GetGraphics()->GetDestination().w - TILE_SIZE;
StopX();
SetXVelocity( NEGATIVE_MOVEMENT );
}
}
//moving left
else if( xVelocity < 0 )
{
//Check out of bounds left
if( tempNewX > 0 ) {
//Get the tile where the actor is
xTile = tempNewX / TILE_SIZE;
yTile = tempNewY / TILE_SIZE;
int midTile = ( tempNewY + ( actorBox.h / 2 ) ) / TILE_SIZE;
//int botTile = ( tempNewY + actorBox.h - 1) / TILE_SIZE;
//Check the tile just to the right
if( map.GetCollision( xTile, yTile ) || map.GetCollision( xTile, midTile ) ) {
//Check box collision for all tiles in front of the character.a
if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, yTile ), actorBox ) ) {
actorBox.x = previousx;
tempNewX = previousx;
StopX();
SetXVelocity( POSITIVE_MOVEMENT );
} else if ( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, midTile ), actorBox ) ) {
actorBox.x = previousx;
tempNewX = previousx;
StopX();
SetXVelocity( POSITIVE_MOVEMENT );
}/* else if ( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, botTile ), actorBox ) ) {
actorBox.x = previousx;
tempNewX = previousx;
} */
}
} else {
tempNewX = 0;
StopX();
SetXVelocity( POSITIVE_MOVEMENT );
}
}
//Falling
//if( yVelocity > 0 ) {
//Check bounds bottom
if( tempNewY + actor.GetGraphics()->GetDestination().h < SCREEN_HEIGHT ) {
// left side of the sprite underneath
yTile = ( tempNewY + actorBox.h ) / TILE_SIZE;
xTile = tempNewX / TILE_SIZE;
//middle underneath
int midX = ( tempNewX + ( actorBox.w / 2 ) ) / TILE_SIZE;
// right side of the sprite underneath
int rightX = ( tempNewX + actorBox.w ) / TILE_SIZE;
//Check both undersides of the sprite to see if it should stop falling
if( map.GetCollision( xTile, yTile ) || map.GetCollision( rightX, yTile ) || map.GetCollision( midX, yTile ) ) {
if( Game_Collision::CheckCollisionBox( map.GetTileDest( xTile, yTile ), actorBox ) ) {
actor.SetState( ACTOR_STAND );
jumpTotal = 0;
tempNewY = map.GetTileDest( xTile, yTile ).y - actorBox.h;
actorBox.y = tempNewY;
//.........这里部分代码省略.........