Exemplo n.º 1
0
/*
* Check if user has killed a monster
*/
void ListOfMonsters::checkIfSomeMonsterDies() {
	for (int i = 0; i < _numMonsters; i++) {
		if (_mouseCoordinates.x >= _arrayMonsters[i].getXAtWorld() && _mouseCoordinates.x <= _arrayMonsters[i].getXAtWorld() + SPRITE_DEFAULT_WIDTH &&
			_mouseCoordinates.y >= _arrayMonsters[i].getYAtWorld() && _mouseCoordinates.y <= _arrayMonsters[i].getYAtWorld() + SPRITE_DEFAULT_HEIGHT)
			removeMonster(i);
	}
}
Exemplo n.º 2
0
void HelloWorld::moveYCallback(Ref * pSender)
{
	auto animation = Animation::createWithSpriteFrames(attack, 0.1f);
	auto animate = Animate::create(animation);
	auto idleAnimation = Animation::createWithSpriteFrames(idle, 0.1f);
	auto idleAnimate = Animate::create(idleAnimation);
	auto seq = Sequence::create(animate, idleAnimate, CCCallFunc::create(this, callfunc_selector(HelloWorld::enCallback)), NULL);
	if (en == false) {
		en = true;
		player->runAction(seq);
	}

	auto fac = Factory::getInstance();
	Rect playerRect = player->getBoundingBox();
	Rect attackRect=Rect(playerRect.getMinX()-40,playerRect.getMinY(),
		playerRect.getMaxX()-playerRect.getMinX()+80,
		playerRect.getMaxY() - playerRect.getMinY());
	Sprite* collision = fac->collider(attackRect);
	if (collision != NULL) {
		fac->removeMonster(collision);

		hp += 20;
		if (hp > 100)
			hp = 100;
		CCProgressTo* ac1 = CCProgressTo::create(2.0f, hp);
		pT->runAction(ac1);

		++sc;
		auto temp = CCString::createWithFormat("%d", sc);
		score->setString(temp->getCString());
		UserDefault::getInstance()->setIntegerForKey("score", sc);
	}
}
Exemplo n.º 3
0
void Factory::removeMonster(const Vector<Sprite*>& collision) {
	auto collisionIt = collision.begin();

	for (; collisionIt != collision.end(); collisionIt++) {
		removeMonster(*collisionIt);
	}
}
Exemplo n.º 4
0
/*
* Check if user has killed a monster
*/
bool ListOfMonsters::checkIfSomeMonsterDies(int x, int y) {
	for (int i = 0; i < _numMonsters; i++) {
		if (x >= _arrayMonsters[i].getXAtWorld() && x <= _arrayMonsters[i].getXAtWorld() + SPRITE_DEFAULT_WIDTH &&
			y >= _arrayMonsters[i].getYAtWorld() && y <= _arrayMonsters[i].getYAtWorld() + SPRITE_DEFAULT_HEIGHT){
			removeMonster(i);
			return true;
		}
	}return false;
}
Exemplo n.º 5
0
void removeAllMonsters (LMonster* p_lmonster) {
	//Si la liste n'est pas vide
	if (p_lmonster->length != 0) {

		//Tant que la liste n'est pas vide
		while (p_lmonster->p_head != NULL) {
			p_lmonster = removeMonster(p_lmonster, p_lmonster->p_head);
		}
		
	}
}
Exemplo n.º 6
0
void HelloWorld::hitByMonster(float dt)
{
	auto fac = Factory::getInstance();
	Sprite* collision = fac->collider(player->getBoundingBox());
	if (collision != NULL) {
		fac->removeMonster(collision);
		hp -= 20;

		if (hp <= 0) {
			CCProgressTo* ac1 = CCProgressTo::create(2.0f, 0);
			auto seq = Sequence::create(ac1, CCCallFunc::create(this, callfunc_selector(HelloWorld::endCallback)), NULL);
			pT->runAction(seq);

		}
		else {
			CCProgressTo* ac1 = CCProgressTo::create(2.0f, hp);
			pT->runAction(ac1);
		}
	}
}
Exemplo n.º 7
0
void GameLayer::checkAndRemoveChain()
{
	Monster *monster;
	// 1. reset ingnore flag
	for (int i = 0; i < m_height * m_width; i++) {
		monster = m_matrix[i];
		if (!monster) {
			continue;
		}
		monster->setIgnoreCheck(false);
	}

	// 2. check chain
	for (int i = 0; i < m_height * m_width; i++) {
		monster = m_matrix[i];
		if (!monster) {
			continue;
		}

		if (monster->getIsNeedRemove()) {
			continue;// 已标记过的跳过检查
		}
		if (monster->getIgnoreCheck()) {
			continue;// 新变化的特殊monster,不消除
		}

		// start count chain
		std::list<Monster *> colChainList;
		getColChain(monster, colChainList);

		std::list<Monster *> rowChainList;
		getRowChain(monster, rowChainList);

		std::list<Monster *> &longerList = colChainList.size() > rowChainList.size() ? colChainList : rowChainList;
		if (longerList.size() < 3) {
			continue;// 小于3个不消除
		}
		countRemoveMonster = longerList.size();
		std::list<Monster *>::iterator itList;
		bool isSetedIgnoreCheck = false;
		for (itList = longerList.begin(); itList != longerList.end(); itList++) {
			monster = (Monster *)*itList;
			if (!monster) {
				continue;
			}

			if (longerList.size() > 3) {
				if (monster == m_srcMonster || monster == m_destMonster) {
					isSetedIgnoreCheck = true;
					monster->setIgnoreCheck(true);
					//4消特殊元素先关闭
					monster->setIsNeedRemove(true);
					//monster->setDisplayMode(m_movingVertical ? DISPLAY_MODE_VERTICAL : DISPLAY_MODE_HORIZONTAL);
					continue;
				}
			}
			markRemove(monster);
		}

		// 如何是自由掉落产生的4消, 取最后一个变化为特殊怪物
		if (!isSetedIgnoreCheck && longerList.size() > 3) {
			monster->setIgnoreCheck(true);
			//4消特殊元素先关闭
			monster->setIsNeedRemove(true);
			//monster->setDisplayMode(m_movingVertical ? DISPLAY_MODE_VERTICAL : DISPLAY_MODE_HORIZONTAL);
		}
	}

	// 3.消除标记了的怪物
	removeMonster();
    // 4.计算消除的分数
	//计算消除得分
	calculateScore(countRemoveMonster);
}