本文整理汇总了C++中CBlock::OnMove方法的典型用法代码示例。如果您正苦于以下问题:C++ CBlock::OnMove方法的具体用法?C++ CBlock::OnMove怎么用?C++ CBlock::OnMove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBlock
的用法示例。
在下文中一共展示了CBlock::OnMove方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ResetMap
void CApp::ResetMap(int mapIndex) {
// remove all blocks
for (auto itr = CBlock::BlockList.begin(); itr != CBlock::BlockList.end(); itr++) {
CBlock* pBlock = *itr;
if (pBlock) {
pBlock->OnMove(-MAP_W, -MAP_H); // this will reset the tile if it was on its home
delete pBlock;
}
}
CBlock::BlockList.clear();
CurrentMap = mapIndex;
if (CurrentMap > highestLevel)
highestLevel = CurrentMap;
CMap* pMap = maps[mapIndex];
ActionJackson.SetLoc(pMap->startX, pMap->startY);
ActionJackson.map = pMap;
ActionJackson.ClearUndoList();
// place all blocks
for (int i = 0; i < pMap->startBlocks.size(); i++) {
SDL_Point p = pMap->startBlocks[i];
CBlock* pBlock = new CBlock(p.x, p.y, pMap);
pBlock->SetSpriteSheet(block);
pBlock->OnMove(0, 0); // this will make the tile change to HOMEWITHBLOCK if applicable
CBlock::BlockList.push_back(pBlock);
}
// add some flavor
Uint8 redness = 2*(Uint8)CurrentMap;
SDL_SetTextureColorMod(Texture, 255, 255 - redness, 255 - redness);
}
示例2: UndoLastMove
void CPlayer::UndoLastMove() {
if (!head)
return; // don't undo anything, don't modify list, and DON'T decrement memories!
pUndo toUndo = head;
if (toUndo->dx == 0 && toUndo->dy == 0) {
// do nothing
}
else { // undo the move (must check for blocks to replace too!)
CBlock* pBlock = NULL;
if (toUndo->pushed) {
for (auto itr = CBlock::BlockList.begin(); itr != CBlock::BlockList.end(); itr++)
{
if (*itr) {
int x, y;
(*itr)->GetLoc(&x, &y);
if ((x == X + toUndo->dx) && (y == Y + toUndo->dy))
pBlock = *itr;
}
}
}
X -= toUndo->dx;
Y -= toUndo->dy;
if (pBlock)
pBlock->OnMove(-toUndo->dx, -toUndo->dy);
}
// remove the top of the list
head = head->next;
delete toUndo;
if (head) // list is not empty
head->prev = NULL;
else // that was the last undo
tail = NULL;
memories--;
}
示例3: OnLoop
void CApp::OnLoop() {
// process input
if (InputHappened) {
NeedsRedraw = true;
// quit game
if (inputs.Quit) {
Running = false;
return;
}
// reset color modulation (easier on the eyes)
if (inputs.Confirm) {
SDL_SetTextureColorMod(Texture, 255, 255, 255);
}
// reset/change level
if (inputs.Reset) {
ResetMap(CurrentMap);
}
else if (inputs.NextLevel) {
if (highestLevel > CurrentMap && CurrentMap < maps.size() - 1)
ResetMap(CurrentMap+1);
}
else if (inputs.PrevLevel) {
if (CurrentMap > 0)
ResetMap(CurrentMap-1);
}
else {
// movement
CBlock* pushed = NULL;
if (inputs.Left) {
int result = ActionJackson.CanPlayerMoveLeft(&pushed);
if (result != NO) {
ActionJackson.OnMove(-1, 0, result == BLOCK);
if (result == BLOCK)
pushed->OnMove(-1, 0);
}
}
else if (inputs.Right) {
int result = ActionJackson.CanPlayerMoveRight(&pushed);
if (result != NO) {
ActionJackson.OnMove(1, 0, result == BLOCK);
if (result == BLOCK)
pushed->OnMove(1, 0);
}
}
else if (inputs.Up) {
int result = ActionJackson.CanPlayerMoveUp(&pushed);
if (result != NO) {
ActionJackson.OnMove(0, -1, result == BLOCK);
if (result == BLOCK)
pushed->OnMove(0, -1);
}
}
else if (inputs.Down) {
int result = ActionJackson.CanPlayerMoveDown(&pushed);
if (result != NO) {
ActionJackson.OnMove(0, 1, result == BLOCK);
if (result == BLOCK)
pushed->OnMove(0, 1);
}
}
else if (inputs.Cancel) {
ActionJackson.UndoLastMove();
}
} // ~movement
//if (PROCESS_ONCE)
InputHappened = false;
}
// add other logic here
FOR_EACH_ENTITY(this)
if (entity->OnLoop()) {
NeedsRedraw = true;
}
FOR_EACH_END
// checking if all blocks are home
bool blocksAreHome = true;
FOR_EACH_BLOCK(&blocksAreHome)
if (!block->CheckForHome())
blocksAreHome = false;
FOR_EACH_END
if (blocksAreHome) {
if (CurrentMap == (maps.size() - 1))
Running = false;
else {
ResetMap(CurrentMap + 1);
}
}
}