Example #1
0
void GameScene::addEnemyTankGroup5()
{
    addBarrier(Vec2(winsize.width/8*3,winsize.height));
    addBarrier(Vec2(winsize.width/8*5,winsize.height));
    addEnemyTank1(Vec2(winsize.width/8*4,winsize.height));
    addTower(Vec2(winsize.width/16*7,winsize.height+100));
    addTower(Vec2(winsize.width/16*9,winsize.height+100));
}
Example #2
0
void GameScene::addEnemyTankGroup4()
{
    addBarrier(Vec2(winsize.width/8*1,winsize.height));
    addBarrier(Vec2(winsize.width/8*2,winsize.height));
    addBarrier(Vec2(winsize.width/8*3,winsize.height));
    addTower(Vec2(winsize.width/16*3,winsize.height+100));
    addEnemyTank2(Vec2(winsize.width/16*5,winsize.height+100));
    
    addBarrier(Vec2(winsize.width/8*5,winsize.height));
    addBarrier(Vec2(winsize.width/8*6,winsize.height));
    addBarrier(Vec2(winsize.width/8*7,winsize.height));
    addTower(Vec2(winsize.width/16*11,winsize.height+100));
    addEnemyTank2(Vec2(winsize.width/16*13,winsize.height+100));
}
Example #3
0
// build tower
void StageLayer::addTower(int towerType)
{
	isBulidTime = false;
	auto towerlayer = dynamic_cast<Towerlayer*>(this->getChildByName("tower"));

	towerlayer->addTower(towerType, buildPos);

}
Example #4
0
//--------------------------------------------------------------------------------------------
//make sure our colleciton of towers matches up with cups in the real world
void Scene::checkCups(){
    //first, mark each tower as having not yet been checked this frame
    for (int i=0; i<towers.size(); i++){
        towers[i]->hasBeenCheckedThisFrame = false;
    }
    
    //go through the list of real world cups
    for (int i=0; i<cupTracker->activeCups.size(); i++){
        CupInfo thisCup = cupTracker->activeCups[i];
        
        bool foundTower = false;
        
        //check if there is a coresponding tower
        for (int k=0; k<towers.size(); k++){
            if (towers[k]->uniqueID == thisCup.uniqueID){
                //store the old values
                float prevAngle = towers[k]->targetAngle;
                ofVec2f prevPos = towers[k]->pos;
                
                //update
                towers[k]->setFromCupInfo(thisCup);
                towers[k]->hasBeenCheckedThisFrame = true;    //mark that we checked it so it doesn't get killed
                foundTower = true;                          //and mark that this cup is accounted for
                
                //check if it moved enough to not be considered idle
                if ( ofDistSquared(prevPos.x, prevPos.y, towers[k]->pos.x, towers[k]->pos.y) > idleTowerMoveThreshold*idleTowerMoveThreshold){
                    //cout<<"big move"<<endl;
                    idleTimer = 0;
                }
                if ( abs(prevAngle-towers[k]->targetAngle) > idleTowerRotateThreshold){
                    //cout<<"big angle"<<endl;
                    idleTimer = 0;
                }
                
                break;
            }
        }
        
        //if no tower was found, it is a new cup, and we need a tower for it!
        if ( !foundTower ){
            idleTimer = 0;
            addTower(thisCup);
        }
        
    }
    
    //now that we've gone through all cups, go through and remove any towers not accounted for
    for (int i=towers.size()-1; i>=0; i--){
        if ( !towers[i]->hasBeenCheckedThisFrame && !towers[i]->ignoreAutoRemove){
            idleTimer = 0;
            removeTower(i);
        }
    }
    
}
Example #5
0
bool Tower::init()
{
    if (!CCNode::init())
    {
        return false;
    }
    
    addTower();
    addArcher();
    return true;
}
Example #6
0
int moveCursor(cursor* c, camera *cam, char *grid, tower** towers, mob *mobs, int *money) //detecs the pressed keys and moves the cursor
{
	int towerId = -1, returned = -1, i = 0;
	if(KeyDown(K_LEFT) && c->gridX > 0)
	{
		c->gridX--;
		if(cam->x / 9 > c->gridX)
			cam->x-= 9;
	}
	if(KeyDown(K_RIGHT) && c->gridX < GRID_LENGTH -1)
	{
		c->gridX++;
		if((cam->x + 128)/ 9 < (c->gridX +1))
			cam->x+= 9;
	}
	if(KeyDown(K_UP) && c->gridY > 0)
	{
		c->gridY--;
		if(cam->y / 9 > c->gridY)
			cam->y -= 9;
	}
	if(KeyDown(K_DOWN) && c->gridY < GRID_WIDTH -1)
	{
		c->gridY++;
		if((cam->y + 64)/9 < (c->gridY+1))
			cam->y += 9;
	}
	if(KeyDown(K_EXE) && grid[c->gridY * GRID_LENGTH + c->gridX]==6)
	{
		returned = openTowerEditionMenu(*c, cam, grid, *towers, mobs, money);
		while(KeyDown(K_EXE))
		{}
	}
	if(KeyDown(K_EXE) && grid[c->gridY * GRID_LENGTH + c->gridX]==0)
	{
		towerId = openTowerSelectionMenu(*c, cam, grid, *towers, mobs, money);
		while(KeyDown(K_EXE))
		{}
	}
	if(returned != -1)
	{
		if(returned == 4)
		{
			*towers = removeTower(findTowerXY(c->gridX, c->gridY, *towers), *towers);
			grid[c->gridY * GRID_LENGTH + c->gridX] = 0;
		}
	}
	if(towerId != -1)
	{
		*towers = addTower(c->gridX, c->gridY, towerId, *towers);
	}
	return towerId;
}
Example #7
0
bool StageLayer::init()
{
	if (!Layer::init())
	{
		return false;
	}
	//get winSize and origin

	isBulidTime = true;

	// where to build
	buildPos = Vec2::ZERO;
	// the tower type

	// the origin of layer

	auto winSize = Director::getInstance()->getVisibleSize();
	m_origin = Vec2(Vec2::ZERO);

	this->setAnchorPoint(m_origin);
	auto maplayer = MapLayer::create();
	maplayer->setName("map");

	this->addChild(maplayer);
	this->setContentSize(maplayer->getContentSize());

	auto towerlayer = Towerlayer::create();
	this->addChild(towerlayer);
	towerlayer->setName("tower");

	auto enemyLayer = Enemylayer::create();
	this->addChild(enemyLayer);
	enemyLayer->setName("enemy");

	/*
	achieve the scale and move for stagelayer
	*/
	//1. create a event listener
	auto listeners = EventListenerTouchAllAtOnce::create();

	//2. achieve the listener monitor 

	m_origin = Vec2(Vec2::ZERO);
	listeners->onTouchesBegan = [=](const std::vector<Touch*>& pTouchs, Event* pEvent){
		this->setAnchorPoint(this->convertTouchToNodeSpace(pTouchs[0]));
	};


	listeners->onTouchesMoved = [=](const std::vector<Touch*>& pTouchs, Event* pEvent)
	{

		if (pTouchs.size() > 1)
		{
			//1. get there two pTouchs
			auto point1 = pTouchs[0]->getLocation();
			auto point2 = pTouchs[1]->getLocation();

			//2. get distance of the two points
			auto currDistance = point1.distance(point2);

			//3. get previous distance of the two points
			auto preDistance = pTouchs[0]->getPreviousLocation().distance(pTouchs[1]->getPreviousLocation());

		// 缩放前的位置边界设置
			auto cur_pos = this->getPosition();
			auto cur_size = this->getBoundingBox().size;
		//缩放后的位置 边界
			auto scal_size = cur_size*(currDistance / preDistance);
			if ((cur_pos.x + scal_size.width*this->getAnchorPoint().x)<winSize.width || cur_pos.x>0 || cur_pos.y>0 || cur_pos.y + scal_size.height*this->getAnchorPoint().y<winSize.height)
			{
				currDistance = preDistance;
			} 
			//4. again set scale
			auto scale = this->getScale()*(currDistance / preDistance);
			auto minScale = 720.0f / 1024.0f;
			scale = MIN(1.5, MAX(minScale, scale));
			this->setScale(scale);
		

		}
		else
		if (pTouchs.size() == 1)
		{
			//only one point
			auto touch = pTouchs[0];

			//1. get Delta
			auto diff = touch->getDelta();
			//2. get currposition
			auto currentPos = this->getPosition();
			//3.get right pos
			auto pos = currentPos + diff;
			//4.get current contentsize
			auto currSzie = this->getBoundingBox().size;

			//5.control its boundary
			pos.x = MIN(pos.x, currSzie.width*this->getAnchorPoint().x);
			pos.x = MAX(pos.x, -currSzie.width + winSize.width + currSzie.width*this->getAnchorPoint().x);

			pos.y = MIN(pos.y, currSzie.height*this->getAnchorPoint().y);
			pos.y = MAX(pos.y, -currSzie.height + winSize.height + currSzie.height*this->getAnchorPoint().y);

			//reset this position
			this->setPosition(pos);

			//update origin
			if (pos.x >= currSzie.width*this->getAnchorPoint().x || pos.x <= -currSzie.width + winSize.width + currSzie.width*this->getAnchorPoint().x)
			{
				diff.x = 0;
			}
			if (pos.y >= currSzie.height*this->getAnchorPoint().y || pos.y <= -currSzie.height + winSize.height + currSzie.height*this->getAnchorPoint().y)
			{
				diff.y = 0;
			}
			m_origin += diff;
		}

	};

	listeners->onTouchesEnded = [=](const std::vector<Touch*>& pTouchs, Event* pEvent)
	{
		this->setAnchorPoint(Vec2::ZERO);
		if (pTouchs[0]->getStartLocation().getDistance(pTouchs[0]->getLocation())>5)
		{
			return;
		}

		//delete the layer
		if (this->getChildByName("select"))
		{
			this->removeChildByName("select");

			return;
		}
		if (isBulidTime == false)
		{
			isBulidTime = true;
			return;
		}
		//chect this poistion is or not to create the tower
		if (!towerlayer->checkIsBuild(this->convertTouchToNodeSpace(pTouchs[0])))
		{

			return;
		}
		if (!maplayer->isCanBulid(this->convertTouchToNodeSpace(pTouchs[0])))

		{
			initCanBuild(maplayer->getAllCanBuild());
			return;
		}

		//create the selectLayer to select tower

		auto selectlayer = SelectTowerLayer::create();
		Vec2 posiotion = this->convertTouchToNodeSpace(pTouchs[0]);
		posiotion = Vec2((int)posiotion.x / 64, (int)posiotion.y / 64) * 64;

		posiotion = maplayer->getMapPos(posiotion);
		//get the position
		selectlayer->setPosition(posiotion);

		buildPos = (posiotion);
		selectlayer->setName("select");
		selectlayer->addTower = [=](int towerType)
		{
			addTower(towerType);
		};
		this->addChild(selectlayer);

	};
	//3.add listener to Event dispatcher
	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listeners,this);

	return true;
}
Example #8
0
bool SelectTowerLayer::init()
{
	if (!Layer::init())
	{
		return false;
	}
	 
	// show the position for tower
	auto towerPos = Sprite::create("towerPos.png");
	towerPos->setScale(0.7);
	//towerPos->setAnchorPoint(Vec2::ZERO);
	this->addChild(towerPos);

	menu = Menu::create();

	//according to Towers  to create equal num menuItems and the Sprite
	auto instance = GameManager::getInstance();
	int nums = instance->towerSelectVector.size();

	int currmoney = dynamic_cast<UiLayer*>(GameManager::getInstance()->getUiLayer())->getcurmoney();
	
	for (int i = 0; i < nums; i++)
	{
		int tower_count = instance->towerSelectVector.at(i);
		MenuItemImage* towerItem = MenuItemImage::create(StringUtils::format("startUI/tower__%02d.png", tower_count), StringUtils::format("startUI/tower__%02d.png", tower_count), StringUtils::format("startUI/tower__%02dunabled.png", tower_count), [=](Ref*)
		{			
			log("You select the %d", tower_count);
			//to assign the choose value when touch the menuItem
			addTower(tower_count);
			//clear up the contents
			 
			//this->removeAllChildrenWithCleanup(true);
			Layer::removeFromParent();
		});
		//judge this gold 
		switch (tower_count)
		{
		case 1:
			if (currmoney < TOWERONECOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		case 2:
			if (currmoney < TOWERTWOCOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		case 3:
			if (currmoney < TOWERTHREECOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		case 4:
			if (currmoney < TOWERFORECOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		case 5:
			if (currmoney < TOWERFIVECOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		case 6:
			if (currmoney < TOWERSIXCOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		case 7:
			if (currmoney < TOWERSEVENCOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		case 8:
			if (currmoney < TOWEREIGHTCOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		default:
			break;
		}
		
		int pos_x = i * 64;
		int pos_y = +64 * (i / 3 + 0);

		pos_x = pos_x - 3 * 64 * ((i / 3 + 0));

		towerItem->setPosition(pos_x, pos_y);
		menu->addChild(towerItem);
	}
	menu->setAnchorPoint(Vec2::ZERO);
	menu->setPosition(Vec2(-towerPos->getContentSize().width / 3 * 2, towerPos->getContentSize().height / 3 * 2));
 	this->addChild(menu);

	return true;
}
Example #9
0
int clickMenuTour(LTower* p_ltower, LFileTower* p_lfileTower, Interface* interface, float x, float y) {

	//Vérifie si les elements ont été alloué
	if(p_ltower != NULL && p_lfileTower != NULL && interface != NULL) {

		char* type = "None";

		//Vérifie qu'on clique sur le bon bouton : tour hybride
		if(x <= 190 && x >= 10 && y <= 120 && y >= 70)
			type = "H";

		// Tour rocket
		else if(x <= 190 && x >= 10 && y <= 175 && y >= 125)
			type = "M";

		//Si le niveau est suppérieur à 3
		if(interface->lvl >= 3) {
			if(x <= 190 && x >= 10 && y <= 230 && y >= 180)
				type = "R";
		}

		//Si le niveau est suppérieur à 5
		if(interface->lvl >= 5) {
			if(x <= 190 && x >= 10 && y <= 285 && y >= 235)
				type = "L";
		}


		//Vérifie qu'il y a un type, sinon pas de clique sur l'un des boutons
		if(strcmp("None", type) != 0) {

			//Pointeur temporaire pour parcourir la liste
			FileTower* tmp = p_lfileTower->p_head;
	
			//Parcours la liste
			while(tmp != NULL) {
				//Si c'est l'hybride 
				if(strcmp(type, tmp->type_tower) == 0)
					break;

				tmp = tmp->p_next;
			}

			//S'il le joueur a assez d'argent
			if((interface->money) >= tmp->cost) {
				//Ajoute une tour
				addTower(p_ltower, tmp->power, tmp->rate, tmp->type_tower, tmp->range, tmp->cost, x, y);
				//Met a jour l'agent
				updateMoney(interface, tmp->cost);
				return 1;
			}
		}
		
	}
	else {
		fprintf(stderr, "Erreur : liste de tour, liste de fileTour ou interface non alloué\n");
		return 0;
	}

	return 0;

}