本文整理汇总了C++中Vector2D::Set方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector2D::Set方法的具体用法?C++ Vector2D::Set怎么用?C++ Vector2D::Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector2D
的用法示例。
在下文中一共展示了Vector2D::Set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetNearestGridSquarePositionToMouse
//Returns the nearest grid square position to the provided mouse position
Vector2D GameWorld::GetNearestGridSquarePositionToMouse(int ix, int iy)
{
Vector2D mousepos;
mousepos.Set(ix, iy);
Vector2D gsp;
Vector2D retval;
retval.Set(-1, -1);
for(int y = 0; y < 11; y++)
{
for(int x = 0; x < 17; x++)
{
gsp = m_gamegrid[x][y].pos;
if(mousepos.x > gsp.x && mousepos.x < gsp.x+19
&& mousepos.y > gsp.y && mousepos.y < gsp.y+19)
{
retval.Set(x, y);
return retval;
}
}
}
return retval;
}
示例2: LoadLevel
//Loads a Level
void GameWorld::LoadLevel()
{
string file;
sprintf((char*)file.c_str(), "maps/%s%i.mrl", m_levelname.c_str(), m_level);
//Load Data
int id;
int e;
char p[256];
int bi=0; //butterfly id
//Clear the background of any decals
SDL_BlitSurface(gConMgr.GetSurface("sprites/grid.fif"), 0, m_surf_background, &renderarea);
//Reset Player Anim State
m_players[0].ResetAnim();
//Clear level data
for(int y = 0; y < 11; y++)
{
for(int x = 0; x < 17; x++)
{
m_gamegrid[x][y].ent = NULL;
}
}
//Reset some data
memset(&m_description, 0x00, sizeof(m_description));
for(int i = 0; i < MAX_CELLS; i++){m_mushrooms[i].SetVisible(0);}
m_totalmushrooms = 0;
m_totalboxes = 0;
m_totalbutterflys = 0;
m_totalhats = 0;
m_totalwells = 0;
m_well[0].SetVisible(0);
m_hat[0].SetVisible(0);
//If level doesnt exist:
FILE* ec = fopen((char*)file.c_str(), "r");
if(ec != NULL){fclose(ec);}else
{
//It doesnt exist
gGameWorld.gScores.AddScore(m_players[0].GetScore(), gGameWorld.GetLevel(), m_players[0].GetLife());
gGameWorld.gScores.m_enabled = 1;
gGameWorld.gMenu.m_selected = 2;
gGameWorld.gMenu.m_enabled = 1;
return;
}
//Decrypt
XorCrypt((char*)file.c_str(), "temp.dat", 471);
//Open Map File
char out[32];
FILE* open = fopen("temp.dat", "r");
if(open != NULL)
{
for(int x = 0; x < 17; x++)
{
for(int y = 0; y < 11; y++)
{
fscanf(open, "%s", out);
id = atoi(out);
if(id == 9)
{
fscanf(open, "%s", out);
e = atoi(out);
}
if(id == 2)
{
memset(&p, 0x00, sizeof(p));
fscanf(open, "%s", p);
}
//Add object to the game
if(id == 0){AddBoxX(x, y, 1);}
if(id == 1){AddBoxX(x, y, 0);}
if(id == 2){AddButterflyX(x, y, p, bi); bi++;}
if(id == 3)
{
m_gamegrid[x][y].ent = &m_players[0];
m_players[0].SetPos(x, y);
}
if(id == 4){AddWellX(x, y);} // well
if(id == 5){AddMushroomX(x, y, MUSHROOM_BLACK);}
if(id == 6){AddMushroomX(x, y, MUSHROOM_RED);}
if(id == 7){AddMushroomX(x, y, MUSHROOM_PINK);}
if(id == 8){AddMushroomX(x, y, MUSHROOM_PURPLE);}
if(id == 9){Vector2D tp; tp.Set(x, y); AddBlueBonus(tp, e);}
if(id == 10){AddHatX(x, y, 4);} // mexican hat
if(id == 11){AddHatX(x, y, 3);} // fez hat
if(id == 12){AddHatX(x, y, 2);} // diving hat
if(id == 13){AddHatX(x, y, 5);} // nightcap
if(id == 14){AddHatX(x, y, 6);} // skullcap
//.........这里部分代码省略.........
示例3: GenerateMaze
//This is a horrible Hunt & Kill maze algorithm i (shamefully) wrote (deliberate problem: it doesnt account for cross sections)
void GameWorld::GenerateMaze()
{
//Clear the background of any decals
SDL_BlitSurface(gConMgr.GetSurface("sprites/grid.fif"), 0, m_surf_background, &renderarea);
//Clear game grid (of all but the players)
for(int y = 0; y < 11; y++)
{
for(int x = 0; x < 17; x++)
{
if(m_gamegrid[x][y].ent != NULL)
{
if(m_gamegrid[x][y].ent->m_ident != IDENT_MAN){m_gamegrid[x][y].ent = NULL;}
}
}
}
//Clear arrays
for(int i = 0; i < 100; i++){m_mushrooms[i].SetVisible(0);}
m_totalmushrooms = 0;
m_totalboxes = 0;
m_totalbutterflys = 0;
m_totalhats = 0;
m_totalwells = 0;
m_well[0].SetVisible(0);
m_hat[0].SetVisible(0);
//Vars
Vector2D start_cell;
Vector2D current_cell;
Vector2D last_cell;
int visited[17][11];
//Set all cell pointers to 1 for unvisited
for(int y = 0; y < 11; y++)
{
for(int x = 0; x < 17; x++)
{
visited[x][y] = 0;
}
}
//Pick a random starting cell, set it as visited 1
start_cell.Set(qRand(0, 17), qRand(0, 11));
visited[start_cell.x][start_cell.y] = 1;
last_cell.x = start_cell.x;
last_cell.y = start_cell.y;
int dir=0; //direction to check
int lastdir=0; //last direction
int checked[4]; //checked directions
loopsearch: //i'm going to hell
checked[0]=0;
checked[1]=0;
checked[2]=0;
checked[3]=0;
//Choose a random direction to move to if the cell is unvisited, then place the borders around it
do
{
doloop: //there's no redemption for people like me
current_cell.x = last_cell.x;
current_cell.y = last_cell.y;
dir = qRand(1, 5);
if(dir == 1){current_cell.x--; checked[0] = 1;} //left
if(dir == 2){current_cell.x++; checked[1] = 1;} //right
if(dir == 3){current_cell.y--; checked[2] = 1;} //up
if(dir == 4){current_cell.y++; checked[3] = 1;} //down
if(current_cell.x < 0){goto doloop;}
if(current_cell.y < 0){goto doloop;}
if(current_cell.x > 16){goto doloop;}
if(current_cell.y > 10){goto doloop;}
//if no direction was found search all visited cells untill you find one with an accessable direction
if(checked[0] == 1 && checked[1] == 1 && checked[2] == 1 && checked[3] == 1) //No unvisited direction avalible
{
//Find a new last cell (if there are no unvisited cells its complete)
for(int y = 0; y < 11; y++)
{
for(int x = 0; x < 17; x++)
{
if(visited[x][y] == 0)
{
visited[x][y] = 1;
last_cell.Set(x, y);
goto loopsearch;
}
}
}
//Well Maze is pretty much done, add some entities
AddMushrooms(10, 50, 1);
AddMushrooms(1, 4, 4);
for(int i = 0; i < qRand(0, 5); i++){AddButterfly(i);}
AddEscapeMushroom(0, 0);
//.........这里部分代码省略.........