예제 #1
0
//创建一级防御塔时调用的方法,入口参数为武器的id
Weapon* Weapon::create(int id)
{
	//创建一个防御塔精灵对象
	Weapon* temp = new Weapon();
	//定义一个存放一级防御塔的字符串数组
	std::string picTable[4] = {"white_1.png","green_1.png","red_1.png","blue_1.png"};
	//初始化安装防御塔时金币的消耗
	int sValue[4]={15,25,30,50};
	//四种防御塔从1级升级到2级时的金币消耗
	int uValue[4]={15,20,30,40};
	//四种防御塔的初始攻击范围
	int confinesTable[4]={100,100,100,80};
	//四种防御塔初始发射子弹的速率
	float updatetimeTable[4]={1.2,1.2,1.2,1.2};
	//四种防御塔的初始伤害值
	int hurtTable[4]={10,15,20,25};
	//初始化防御塔精灵对象
	temp->initWithFile(picTable[id-1].c_str());
	//自动释放
	temp->autorelease();
	//拿到当前防御塔的id
	temp->id = id;
	//初始化防御塔的级别为1
	temp->level = 1;
	//根据id设置安装各防御塔时需要的金币
	temp->value = sValue[id-1];
	//卖掉防御塔时得到的金币
	temp->sellValue = temp->value/2;
	//根据id设置各防御塔由1级升到2级时需要的金币
	temp->upValue = uValue[id-1];
	//根据id设置各防御塔发射子弹的速率
	temp->updatetime=updatetimeTable[id-1];
	//发射子弹的标志位
	temp->fire=true;
	//根据id设置各防御塔的初始伤害
	temp->hurt=hurtTable[id-1];
	//根据id设置各防御塔的初始攻击范围
	temp->confines=confinesTable[id-1];
	//创建一个表示选中防御塔时显示效果的精灵对象
	Sprite* scope= Sprite::create("ring.png");
	//根据当前防御塔的攻击范围来设置该效果精灵的尺寸
	float scale=(float)confinesTable[id-1]/(scope->getContentSize().width/2);
	scope->setScale(scale);
	//设置该精灵对象的位置
	scope->setPosition(Point(24,24));
	//将该精灵对象添加到布景中
	temp->addChild(scope,4,1);
	//设置该精灵对象初始为不可见
	scope->setVisible(false);
	//设置升级防御塔的标志位为false
	temp->updateMark=false;

	return temp;
}
예제 #2
0
//创建四个防御塔菜单精灵时调用的创建方法
Weapon* Weapon::create(const char* pic,int id)//入口参数武器的id
{
	//创建一个防御塔对象
	Weapon* temp = new Weapon();
	//初始化安装防御塔时金币的消耗
	int sValue[4]={15,25,30,50};
	//四种防御塔的初始攻击范围
	int confinesTable[4]={100,100,100,80};
	//四种防御塔初始发射子弹的速率
	float updatetimeTable[4]={1.2,1.2,1.2,1.2};
	//四种防御塔的初始伤害值
	int hurtTable[4]={10,15,20,25};
	//初始化防御塔精灵对象
	temp->initWithFile(pic);
	//自动释放
	temp->autorelease();
	//拿到当前防御塔的id
	temp->id = id;
	//初始化防御塔的级别为1
	temp->level = 1;
	//根据id设置安装各防御塔时需要的金币
	temp->value = sValue[id-1];
	//根据id设置各防御塔发射子弹的速率
	temp->updatetime=updatetimeTable[id-1];
	//发射子弹的标志位
	temp->fire=true;
	//根据id设置各防御塔的初始伤害
	temp->hurt=hurtTable[id-1];
	//根据id设置各防御塔的初始攻击范围
	temp->confines=confinesTable[id-1];
	//创建一个表示选中防御塔时显示效果的精灵对象
	Sprite* scope= Sprite::create("ring.png");
	//设置该精灵对象的尺寸
	float scale=(float)confinesTable[id-1]/(scope->getContentSize().width/2);
	scope->setScale(scale);
	//设置位置
	scope->setPosition(Point(24,24));
	//将该对象添加到布景中
	temp->addChild(scope,4,1);
	//设置该精灵对象初始为不可见
	scope->setVisible(false);
	//设置升级防御塔的标志位为false
	temp->updateMark=false;

	return temp;
}