当前位置: 首页>>代码示例>>C++>>正文


C++ CBlock::OnMove方法代码示例

本文整理汇总了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);
}
开发者ID:RKJokela,项目名称:rjSokoban,代码行数:32,代码来源:CApp.cpp

示例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--;
}
开发者ID:RKJokela,项目名称:rjSokoban,代码行数:34,代码来源:CPlayer.cpp

示例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);
        }
    }
}
开发者ID:RKJokela,项目名称:rjSokoban,代码行数:92,代码来源:CApp.cpp


注:本文中的CBlock::OnMove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。