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


C++ Platform::getYOffset方法代码示例

本文整理汇总了C++中Platform::getYOffset方法的典型用法代码示例。如果您正苦于以下问题:C++ Platform::getYOffset方法的具体用法?C++ Platform::getYOffset怎么用?C++ Platform::getYOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Platform的用法示例。


在下文中一共展示了Platform::getYOffset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CheckCollision

void Game::CheckCollision() {

	// TODO all X and Y coords to absolute (level) values as opposed to screen values refactor this
	std::map<std::pair<int, int>, Entity*>* entities = level->getEntities();
	for (std::map<std::pair<int, int>, Entity*>::iterator i = entities->begin(); i != entities->end(); i++) {
		Entity* entity = i->second;
		Platform* p = dynamic_cast<Platform*>(entity);

		int levelBlockX = i->first.second;
		int levelBlockY = i->first.first;
		
		if (p != NULL && p->getState() == dislodged) {
			p->setYOffset(p->getYOffset() + 5); //TODO needs to be a variable

			int currentLevelBlockX = levelBlockX;
			int currentLevelBlockY = levelBlockY + (p->getYOffset() + 50) / Level::BLOCK_HEIGHT_PX;

			if (level->getLevelCodeByBlock(currentLevelBlockX, currentLevelBlockY) == '_') {
				p->setState(broken);
				level->setLevelCodeByBlock(currentLevelBlockX,currentLevelBlockY, '$');
				level->setLevelCodeByBlock(levelBlockX, levelBlockY, ' ');
			}
			else {
				p->setY(int(p->getY() + 5) % (Level::BLOCK_HEIGHT_PX * Level::SCENE_HEIGHT_BLK));
				//p->setY((levelBlockY - level->getSceneY()) * Level::BLOCK_HEIGHT_PX + p->getYOffset() - p->getAnim()->getSheet()->getFrameHeight());

				if (!level->inScene(levelBlockX, levelBlockY) && level->inScene(currentLevelBlockX, currentLevelBlockY)) {
					p->Animate(&graphics);
				}
			}
		}	
	}


	collision->CheckPrinceCollision(prince);
	CheckCombatCollision();
}
开发者ID:,项目名称:,代码行数:37,代码来源:

示例2: DrawBackground

void Game::DrawBackground() {
	int yOff = 0;
	int xOff = 0;

	//TODO this value is being reused in check collision move it in a common location or eliminate collision detection when drawing completely
	int princeXOffset = 22;

	for (int y = Level::SCENE_HEIGHT_BLK; y >= 0; y--) {
		for (int x = 0; x <= Level::SCENE_WIDTH_BLK; x++) {

			yOff = Level::BLOCK_HEIGHT_PX * y;
			xOff = -Level::BLOCK_WIDTH_PX + Level::BLOCK_WIDTH_PX * x;

			switch (level->getSceneCodeByBlock(y, x)) {
			case '|':
				graphics.DrawSprite(xOff, yOff - getSprite("tileCornerLeft")->height, getSprite("tileCornerLeft"));
				break;
			case 'T':
				graphics.DrawSprite(xOff, yOff - getSprite("tileCornerLeft")->height, getSprite("tileCornerLeft"));
				graphics.DrawSprite(xOff - 1, yOff - getSprite("columnBack")->height - 15, getSprite("columnBack"));
				break;
			case ']':
				graphics.DrawSprite(xOff, yOff - getSprite("blockCornerRight")->height, getSprite("blockCornerRight"));
				break;
			case '_':
				graphics.DrawSprite(xOff, yOff - getSprite("tileCornerLeft")->height, getSprite("tileCornerLeft"));
				break;
			case '1':
				graphics.DrawSprite(xOff, yOff - getSprite("tileCornerLeft")->height, getSprite("tileCornerLeft"));
				break;
			case '~': {
				std::map<std::pair<int, int>, Entity*>* entities = level->getEntities();
				int blockX = level->getLevelBlockX(x);
				int blockY = level->getLevelBlockY(y);
				std::pair<int, int> platformKey = std::make_pair(blockY, blockX);
				Entity* e = entities->at(platformKey);
				Platform* p = dynamic_cast<Platform*>(e);
				if (p != NULL) {
					int currentLevelBlockX = blockX;
					int currentLevelBlockY = blockY + (p->getYOffset() + 120) / Level::BLOCK_HEIGHT_PX;

					if (level->inScene(currentLevelBlockX, currentLevelBlockY)) {
						p->Animate(&graphics);
					}
				}
				if (level->getSceneBlockXByCoord(prince->getMidX() - princeXOffset) == x &&
					level->getSceneBlockYByCoord(prince->getMidY()) == y && prince->getState() != sJumping) {
					p->Drop();
				}
			} break;

			case 'H':
				graphics.DrawSprite(xOff, yOff - getSprite("tileCornerLeft")->height, getSprite("tileCornerLeft"));
				break;
			case '-':
				if (level->getSceneCodeByCoord(prince->getMidX() - princeXOffset, prince->getMidY()) == '-') {
					if (level->getSceneBlockXByCoord(prince->getMidX() - princeXOffset) == x &&
						level->getSceneBlockYByCoord(prince->getMidY() == y) &&
						prince->getState() != sJumping) {
						graphics.DrawSprite(xOff, yOff - getSprite("tileCornerLeft")->height, getSprite("tileCornerLeft"));
					}
					else {
						graphics.DrawSprite(xOff, yOff - getSprite("activate")->height, getSprite("activate"));
					}
				}
				else {
					graphics.DrawSprite(xOff, yOff - getSprite("activate")->height, getSprite("activate"));
				}
				break;
			case '=':
				if (level->getSceneCodeByCoord(prince->getMidX() - princeXOffset, prince->getMidY()) == '=') {
					if (level->getSceneBlockXByCoord(prince->getMidX() - princeXOffset) == x &&
						level->getSceneBlockYByCoord(prince->getMidY() == y) &&
						prince->getState() != sJumping
						) {
						graphics.DrawSprite(xOff, yOff + 2 - getSprite("trap")->height, getSprite("trap"));
					}
					else {
						graphics.DrawSprite(xOff, yOff - getSprite("trap")->height, getSprite("trap"));
					}
				}
				else {
					graphics.DrawSprite(xOff, yOff - getSprite("trap")->height, getSprite("trap"));
				}
				break;
			case '*':
				graphics.DrawSprite(xOff, yOff - getSprite("bricks")->height, getSprite("bricks"));
				break;
			case '/':
				graphics.DrawSprite(xOff, yOff - getSprite("holyFloor")->height, getSprite("holyFloor"));
				break;
			case 'S':
				graphics.DrawSprite(xOff, yOff - getSprite("deadSk")->height, getSprite("deadSk"));
				break;
			case 'G':
				graphics.DrawSprite(xOff, yOff - getSprite("doorFrameBack")->height, getSprite("doorFrameBack"));
				break;
			case '#':
				graphics.DrawSprite(xOff, yOff - getSprite("tileCornerLeft")->height, getSprite("tileCornerLeft"));
				graphics.DrawSprite(xOff, yOff - getSprite("bricks")->height, getSprite("bricks"));
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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