C++ 与cocos2d-x-4.0完成太空飞机大战 (四)

动画演示

游戏画面演示

工具类编码:Util.cpp


#include "Util.h"

namespace SpaceWar {

	float Util::FPS = 60.0f;

	/*角度转弧度*/
	float Util::D2R(double angle)
	{
		return angle / 180.0 * (float)M_PI;
	}

	/*弧度转角度*/
	float Util::R2D(double radian)
	{
		return radian / (float)M_PI * 180;
	}

	string Util::getPowerPath(int power)
	{
		if (power > 5)
		{
			return "power6.png";
		}
		else if (power > 4)
		{
			return "power5.png";
		}
		else if (power > 3)
		{
			return "power4.png";
		}
		else if (power > 2)
		{
			return "power3.png";
		}
		else if (power > 1)
		{
			return "power2.png";
		}
		else if (power > 0)
		{
			return "power1.png";
		}
		return "power0.png";
	}

	string Util::getArmType(int type)
	{
		if (type == 0)
		{
			return "E  ";
		}
		else if (type == 1)
		{
			return "W  ";
		}
		return "";
	}

	string Util::getMissileType(int type)
	{
		if (type == 0)
		{
			return "M  ";
		}
		else if (type == 1)
		{
			return "H  ";
		}
		return "";
	}

	string Util::getBombType(int type)
	{
		if (type == 0)
		{
			return "B1";
		}
		else if (type == 1)
		{
			return "B2";
		}
		return "";
	}

	/*根据速度与距离返回移动到目标时间(速度单位:像素/秒)*/
	float Util::getMoveTime(float speed, Vec2 position, Vec2 target)
	{
		float distance = position.distance(target);
		float tspeed = distance / (speed * Util::FPS);
		return tspeed;
	}

	/*根据速度与距离返回移动到目标时间(速度单位:像素/秒)*/
	float Util::getMoveTime(float speed, float distance)
	{
		float tspeed = distance / (speed * Util::FPS);
		return tspeed;
	}

	/*返回对追踪目标的旋转角度*/
	float Util::getTrackRotation(Vec2 position, Vec2 newPosition)
	{
		return 90 - atan2(newPosition.y - position.y, newPosition.x - position.x) * 180 / (float)M_PI;
	}

	/*返回对追踪目标的步进速度*/
	Vec2 Util::getTrackPosition(float speed, Vec2 track, Vec2 target)
	{
		//求两点的差值,事实上就是两点的坐标相减
		Vec2 delta = target - track;
		//求当前对象和目标两点间的距离
		float distance = track.distance(target);
		float x = speed * delta.x / distance;
		float y = speed * delta.y / distance;
		return Vec2(x, y);
	}

	/*返回一个距离最近的有效的NodeKey*/
	string Util::getNearNodeKey(map<string, Node*> *mapNodes, Vec2 position)
	{
		string s;
		if (mapNodes->size() > 0)
		{
			priority_queue<pair<float, string>, deque<pair<float, string>>, greater<pair<float, string>>> pq;
			map<string, Node*>::iterator ite;
			int n = 0;
			for (ite = mapNodes->begin(); ite != mapNodes->end(); ite++)
			{
				string key = ite->first;
				Node* node = ite->second;
				if (node != nullptr)
				{
					float dis = position.distance(node->getPosition());
					pq.push(make_pair(dis, key));
				}
			}
			if (pq.size() > 0)
			{
				return pq.top().second;
			}
		}
		return s;
	}

	/*随机返回一个有效的NodeKey*/
	string Util::getRandomNodeKey(map<string, Node*> *mapNodes)
	{
		string s;
		if (mapNodes->size() > 0)
		{
			map<string, Node*>::iterator ite;
			for (ite = mapNodes->begin(); ite != mapNodes->end(); ite++)
			{
				Node* node = ite->second;
				if (node != nullptr)
				{
					int rint = random(0, 1);
					if (rint == 0)
					{
						return ite->first;
					}
				}
			}
		}
		return s;
	}

	/*随机返回一个有效的NodeKey*/
	string Util::getRandomNodeKey(map<string, Node*> *mapNodes, Vec2 position)
	{
		string s;
		if (mapNodes->size() > 0)
		{
			map<string, Node*>::iterator ite;
			for (ite = mapNodes->begin(); ite != mapNodes->end(); ite++)
			{
				Node* node = ite->second;
				if (node != nullptr)
				{
					float dis = position.distance(node->getPosition());
					if (dis > 20 && dis < 200)
					{
						int rint = random(0, 1);
						if (rint == 0)
						{
							return ite->first;
						}
					}
				}
			}
		}
		return s;
	}

	/*返回第一个有效的NodeKey*/
	string Util::getTopNodeKey(map<string, Node*> *mapNodes)
	{
		string s;
		if (mapNodes->size() > 0)
		{
			map<string, Node*>::iterator ite;
			for (ite = mapNodes->begin(); ite != mapNodes->end(); ite++)
			{
				Node* node = ite->second;
				if (node != nullptr)
				{
					return ite->first;
				}
			}
		}
		return s;
	}

	/*返回一个距离最近的有效的Node*/
	Node* Util::getNearNode(map<string, Node*> *mapNodes, Vec2 position)
	{
		Node* node = nullptr;
		if (mapNodes->size() > 0)
		{
			priority_queue<pair<float, string>, deque<pair<float, string>>, greater<pair<float, string>>> pq;
			map<string, Node*>::iterator ite;
			int n = 0;
			for (ite = mapNodes->begin(); ite != mapNodes->end(); ite++)
			{
				string key = ite->first;
				node = ite->second;
				if (node != nullptr)
				{
					float dis = position.distance(node->getPosition());
					pq.push(make_pair(dis, key));
				}
			}
			if (pq.size() > 0)
			{
				string key = pq.top().second;
				return findNode(mapNodes, key);
			}
		}
		return node;
	}

	/*随机返回一个有效的Node*/
	Node* Util::getRandomNode(map<string, Node*> *mapNodes)
	{
		Node* node = nullptr;
		if (mapNodes->size() > 0)
		{
			vector<string> vlist;
			map<string, Node*>::iterator ite;
			for (ite = mapNodes->begin(); ite != mapNodes->end(); ite++)
			{
				node = ite->second;
				if (node != nullptr)
				{
					vlist.push_back(ite->first);
				}
			}
			if (vlist.size() > 0)
			{
				string key = vlist[random(0, (int)vlist.size() - 1)];
				return findNode(mapNodes, key);
			}
		}
		return node;
	}

	/*随机返回一个有效的Node*/
	Node* Util::getRandomNode(map<string, Node*> *mapNodes, float minDistance, float maxDistance, Vec2 position)
	{
		Node* node = nullptr;
		if (mapNodes->size() > 0)
		{
			vector<string> vlist;
			map<string, Node*>::iterator ite;
			for (ite = mapNodes->begin(); ite != mapNodes->end(); ite++)
			{
				node = ite->second;
				if (node != nullptr)
				{
					float dis = position.distance(node->getPosition());
					if (dis > minDistance && dis < maxDistance)
					{
						vlist.push_back(ite->first);
					}
				}
			}
			if (vlist.size()>0) 
			{
				string key = vlist[random(0, (int)vlist.size()-1)];
				return findNode(mapNodes, key);
			}
		}
		return node;
	}

	/*返回第一个有效的Node*/
	Node* Util::getTopNode(map<string, Node*> *mapNodes)
	{
		Node* node = nullptr;
		if (mapNodes->size() > 0)
		{
			map<string, Node*>::iterator ite;
			for (ite = mapNodes->begin(); ite != mapNodes->end(); ite++)
			{
				node = ite->second;
				if (node != nullptr)
				{
					return node;
				}
			}
		}
		return node;
	}

	/*返回最后一个有效的Node*/
	Node* Util::getEndNode(map<string, Node*> *mapNodes)
	{
		Node* node = nullptr;
		if (mapNodes->size() > 0)
		{
			map<string, Node*>::iterator ite;
			for (ite = mapNodes->begin(); ite != mapNodes->end(); ite++)
			{
				Node* nodea = ite->second;
				if (nodea != nullptr)
				{
					node = nodea;
				}
			}
		}
		return node;
	}

	/*根据指定的键返回一个Node*/
	Node* Util::findNode(map<string, Node*> *mapNodes, string key)
	{
		Node* node = nullptr;
		map<string, Node*>::iterator ite;
		ite = mapNodes->find(key);
		if (ite != mapNodes->end()) {
			node = ite->second;
		}
		return node;
	}

	/*返回随机Char*/
	unsigned int Util::getRandomChar()
	{
		std::random_device rd;
		std::mt19937 gen(rd());
		std::uniform_int_distribution<> dis(0, 255);
		return dis(gen);
	}

	/*返回GUID*/
	std::string Util::getGUID(const unsigned int len)
	{
		std::stringstream ss;
		for (auto i = 0; i < len; i++) {
			const auto rc = getRandomChar();
			std::stringstream hexstream;
			hexstream << std::hex << rc;
			auto hex = hexstream.str();
			ss << (hex.length() < 2 ? '0' + hex : hex);
		}
		return ss.str();
	}

	/*返回GUID*/
	std::string Util::getGUID()
	{
		return getGUID(32);
	}

	/*数字转字符串左侧补0,2补位*/
	string Util::leftCover(int num)
	{
		return leftCover(num, 2, '0');
	}

	/*数字转字符串左侧补0*/
	string Util::leftCover(int num, int coverCount)
	{
		return leftCover(num, coverCount, '0');
	}

	/*数字转字符串左侧补位*/
	string Util::leftCover(int num, int coverCount, char s)
	{
		stringstream ls;
		ls << setw(coverCount) << setfill(s) << num;
		return ls.str();
	}

	/*数字转字符串左侧补0,2补位*/
	string Util::leftCover(long num)
	{
		return leftCover(num, 2, '0');
	}

	/*数字转字符串左侧补0*/
	string Util::leftCover(long num, int coverCount)
	{
		return leftCover(num, coverCount, '0');
	}

	/*数字转字符串左侧补位*/
	string Util::leftCover(long num, int coverCount, char s)
	{
		stringstream ls;
		ls << setw(coverCount) << setfill(s) << num;
		return ls.str();
	}

	/*字符串左侧补0,2补位*/
	string Util::leftCover(string str)
	{
		return leftCover(str, 2, '0');
	}

	/*字符串左侧补0*/
	string Util::leftCover(string str, int coverCount)
	{
		return leftCover(str, coverCount, '0');
	}

	/*字符串左侧补位*/
	string Util::leftCover(string str, int coverCount, char s)
	{
		stringstream ls;
		ls << setw(coverCount) << setfill(s) << str;
		return ls.str();
	}

	/*根据多边形体与精灵大小返回物理形体列表*/
	Vec2 * Util::getVec2(PolygonInfo pi, Size size)
	{
		auto indices = pi.triangles.indices;
		auto verts = pi.triangles.verts;
		Vec2* vec2 = new Vec2[pi.triangles.indexCount];
		for (int i = 0; i < pi.triangles.indexCount; i++)
		{
			vec2[i].x = verts[indices[i]].vertices.x - size.width / 2;
			vec2[i].y = verts[indices[i]].vertices.y - size.height / 2;
		}
		return vec2;
	}

	/*根据多边形体,精灵大小,碰撞掩码创建物理刚体*/
	PhysicsBody* Util::getPhysicsBody(PolygonInfo pi, Size size, int tag, int category, int collision, int contactTest, bool gravityEnable)
	{
		Vec2* ver2 = Util::getVec2(pi, size);
		auto body = PhysicsBody::createPolygon(ver2, pi.triangles.indexCount);
		body->setTag(tag);
		body->setCategoryBitmask(category);
		body->setCollisionBitmask(collision);
		body->setContactTestBitmask(contactTest);
		body->setGravityEnable(gravityEnable);
		return body;
	}

	/*根据精灵大小,碰撞掩码创建物理刚体*/
	PhysicsBody* Util::getPhysicsBody(Size size, int tag, int category, int collision, int contactTest, bool gravityEnable)
	{
		auto body = PhysicsBody::createBox(size);
		body->setTag(tag);
		body->setCategoryBitmask(category);
		body->setCollisionBitmask(collision);
		body->setContactTestBitmask(contactTest);
		body->setGravityEnable(gravityEnable);
		return body;
	}

	/*根据图片名称以及数量返回序列动画*/
	Vector<SpriteFrame*> Util::getAnimation(const char *format, int count)
	{
		auto spritecache = SpriteFrameCache::getInstance();
		Vector<SpriteFrame*> animFrames;
		char str[100];
		for (int i = 1; i <= count; i++)
		{
			sprintf(str, format, i);
			auto name = spritecache->getSpriteFrameByName(str);
			animFrames.pushBack(name);
		}
		return animFrames;
	}

	/*返回当前时间戳*/
	long Util::getLongTime() {
		std::chrono::steady_clock::duration d = std::chrono::steady_clock::now().time_since_epoch();
		std::chrono::milliseconds mil = std::chrono::duration_cast<std::chrono::milliseconds>(d);
		return mil.count();
	}

	bool Util::isIntervalTime(long interval, long* time)
	{
		long now = Util::getLongTime();
		long enemyInterval = now - *time;
		if (enemyInterval < interval)
		{
			return false;
		}
		*time = now;
		return true;
	}

	bool Util::isIntervalTime(long interval, long* baseTime, long* time)
	{
		long now = Util::getLongTime();
		long enemyInterval = now - *time;
		if (*time > 0)
		{
			*baseTime += enemyInterval;
		}
		if (enemyInterval < interval)
		{
			return false;
		}
		*time = now;
		return true;
	}

	/*根据按键按下事件设置锁定按键*/
	void Util::onKeyPressed(EventKeyboard::KeyCode keyCode, Control* conAct)
	{
		switch (keyCode) {
		case EventKeyboard::KeyCode::KEY_W: {
			conAct->controlAct[0] = 1;
			break;
		}
		case EventKeyboard::KeyCode::KEY_S: {
			conAct->controlAct[1] = 1;
			break;
		}
		case EventKeyboard::KeyCode::KEY_A: {
			conAct->controlAct[2] = 1;
			break;
		}
		case EventKeyboard::KeyCode::KEY_D: {
			conAct->controlAct[3] = 1;
			break;
		}
		case EventKeyboard::KeyCode::KEY_SPACE: {
			conAct->controlAct[4] = 1;
			break;
		}
		case EventKeyboard::KeyCode::KEY_B: {
			conAct->controlAct[5] = 1;
			break;
		}
		case EventKeyboard::KeyCode::KEY_UP_ARROW: {
			conAct->controlAct[100] = 1;
			break;
		}
		case EventKeyboard::KeyCode::KEY_DOWN_ARROW: {
			conAct->controlAct[101] = 1;
			break;
		}
		case EventKeyboard::KeyCode::KEY_LEFT_ARROW: {
			conAct->controlAct[102] = 1;
			break;
		}
		case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: {
			conAct->controlAct[103] = 1;
			break;
		}
		case EventKeyboard::KeyCode::KEY_0: {
			conAct->controlAct[104] = 1;
			break;
		}
		case EventKeyboard::KeyCode::KEY_1: {
			conAct->controlAct[105] = 1;
			break;
		}
		default:
			break;
		}
	}

	/*根据按键弹起事件设置解锁按键*/
	void Util::onKeyReleased(EventKeyboard::KeyCode keyCode, Control* conAct)
	{
		switch (keyCode) {
		case EventKeyboard::KeyCode::KEY_W: {
			conAct->controlAct[0] = 0;
			break;
		}
		case EventKeyboard::KeyCode::KEY_S: {
			conAct->controlAct[1] = 0;
			break;
		}
		case EventKeyboard::KeyCode::KEY_A: {
			conAct->controlAct[2] = 0;
			break;
		}
		case EventKeyboard::KeyCode::KEY_D: {
			conAct->controlAct[3] = 0;
			break;
		}
		case EventKeyboard::KeyCode::KEY_SPACE: {
			conAct->controlAct[4] = 0;
			break;
		}
		case EventKeyboard::KeyCode::KEY_B: {
			conAct->controlAct[5] = 0;
			break;
		}
		case EventKeyboard::KeyCode::KEY_UP_ARROW: {
			conAct->controlAct[100] = 0;
			break;
		}
		case EventKeyboard::KeyCode::KEY_DOWN_ARROW: {
			conAct->controlAct[101] = 0;
			break;
		}
		case EventKeyboard::KeyCode::KEY_LEFT_ARROW: {
			conAct->controlAct[102] = 0;
			break;
		}
		case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: {
			conAct->controlAct[103] = 0;
			break;
		}
		case EventKeyboard::KeyCode::KEY_0: {
			conAct->controlAct[104] = 0;
			break;
		}
		case EventKeyboard::KeyCode::KEY_1: {
			conAct->controlAct[105] = 0;
			break;
		}
		default:
			break;
		}
	}

	/*根据移动方向与屏幕大小以及精灵大小和移动速度判断是否允许移动精灵*/
	bool Util::spriteSceneMove(int act, Sprite* sprite, Size vsize, Size ssize, Vec2 position, float speed)
	{
		if (act == 0)
		{
			float s = vsize.height - (ssize.height / 2) - (position.y + speed);
			if (s > 0)
			{
				auto moveBy = MoveBy::create(0.0f, Vec2(0, speed));
				sprite->runAction(moveBy);
			}
		}
		else if (act == 1)
		{
			float s = (position.y - speed) - (ssize.height / 2);
			if (s > 0)
			{
				auto moveBy = MoveBy::create(0.0f, Vec2(0, -speed));
				sprite->runAction(moveBy);
			}
		}
		else if (act == 2)
		{
			float s = (position.x - speed) - (ssize.width / 2);
			if (s > 0)
			{
				auto moveBy = MoveBy::create(0.0f, Vec2(-speed, 0));
				sprite->runAction(moveBy);
			}
		}
		else if (act == 3)
		{
			float s = vsize.width - (ssize.width / 2) - (position.x + speed);
			if (s > 0)
			{
				auto moveBy = MoveBy::create(0.0f, Vec2(speed, 0));
				sprite->runAction(moveBy);
			}
		}
		return false;
	}

	/*检测指定的Node是否已移出可视范围*/
	bool Util::isOutScene(Node* node, Size vsize)
	{
		Vec2 nPosition = node->getPosition();
		Size nSize = node->getBoundingBox().size;
		if (nPosition.y + nSize.height < 0)
		{
			return true;
		}
		if (vsize.height - nPosition.y + nSize.height < 0)
		{
			return true;
		}
		if (nPosition.x + nSize.width < 0)
		{
			return true;
		}
		if (vsize.width - nPosition.x + nSize.width < 0)
		{
			return true;
		}
		return false;
	}
}


工具类编码:Util.h


#pragma once
#include <vector>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <set>
#include "cocos2d.h"
#include "Control.h"

using namespace std;
using namespace cocos2d;

namespace SpaceWar
{
	class Util
	{
	public:

		static float FPS;

		/*角度转弧度*/
		static float D2R(double angle);

		/*弧度转角度*/
		static float R2D(double radian);

		static string getPowerPath(int power);

		static string getArmType(int type);

		static string getMissileType(int type);

		static string getBombType(int type);

		/*根据速度与距离返回移动到目标时间(速度单位:像素/秒)*/
		static float getMoveTime(float speed, Vec2 position, Vec2 target);

		/*根据速度与距离返回移动到目标时间(速度单位:像素/秒)*/
		static float getMoveTime(float speed, float distance);

		/*返回对追踪目标的旋转角度*/
		static float getTrackRotation(Vec2 position, Vec2 newPosition);

		/*返回对追踪目标的步进位置*/
		static Vec2 getTrackPosition(float speed, Vec2 track, Vec2 target);

		/*返回一个距离最近的有效的NodeKey*/
		static string getNearNodeKey(map<string, Node*>* mapNodes, Vec2 position);

		/*随机返回一个有效的NodeKey*/
		static string getRandomNodeKey(map<string, Node*>* mapNodes);

		/*随机返回一个有效的NodeKey*/
		static string getRandomNodeKey(map<string, Node*>* mapNodes, Vec2 position);

		/*返回第一个有效的NodeKey*/
		static string getTopNodeKey(map<string, Node*>* mapNodes);

		/*返回一个距离最近的有效的Node*/
		static Node * getNearNode(map<string, Node*>* mapNodes, Vec2 position);

		/*随机返回一个有效的Node*/
		static Node * getRandomNode(map<string, Node*>* mapNodes);

		/*随机返回一个有效的Node*/
		static Node * getRandomNode(map<string, Node*>* mapNodes, float minDistance, float maxDistance, Vec2 position);

		/*返回第一个有效的Node*/
		static Node * getTopNode(map<string, Node*>* mapNodes);

		/*返回最后一个有效的Node*/
		static Node * getEndNode(map<string, Node*>* mapNodes);

		static Node * findNode(map<string, Node*>* mapNodes, string key);

		/*返回随机Char*/
		static unsigned int getRandomChar();

		/*返回GUID*/
		static std::string getGUID(const unsigned int len);

		/*返回GUID*/
		static std::string getGUID();

		/*数字转字符串后左侧补0,2补位*/
		static string leftCover(int num);

		/*数字转字符串后左侧补0*/
		static string leftCover(int num, int coverCount);

		/*数字转字符串后左侧补位*/
		static string leftCover(int num, int coverCount, char s);

		/*数字转字符串后左侧补0,2补位*/
		static string leftCover(long num);

		/*数字转字符串后左侧补0*/
		static string leftCover(long num, int coverCount);

		/*数字转字符串后左侧补位*/
		static string leftCover(long num, int coverCount, char s);

		/*字符串左侧补0,2补位*/
		static string leftCover(string str);

		/*字符串左侧补0*/
		static string leftCover(string str, int coverCount);

		/*字符串左侧补位*/
		static string leftCover(string str, int coverCount, char s);

		/*返回Vec2*/
		static Vec2* getVec2(PolygonInfo pi, Size size);

		/*返回PhysicsBody*/
		static PhysicsBody * getPhysicsBody(PolygonInfo pi, Size size, int tag, int category, int collision, int contactTest, bool gravityEnable);

		/*根据精灵大小,碰撞掩码创建物理刚体*/
		static PhysicsBody * getPhysicsBody(Size size, int tag, int category, int collision, int contactTest, bool gravityEnable);

		/*返回动画组*/
		static Vector<SpriteFrame*> getAnimation(const char * format, int count);

		/*返回当前长整型时间*/
		static long getLongTime();

		/*根据是否已超过时间间隔*/
		static bool isIntervalTime(long interval, long * time);

		/*根据是否已超过时间间隔*/
		static bool isIntervalTime(long interval, long* baseTime, long * time);

		/*根据按键按下事件设置锁定按键*/
		static void onKeyPressed(EventKeyboard::KeyCode keyCode, Control* conAct);

		/*根据按键弹起事件设置解锁按键*/
		static void onKeyReleased(EventKeyboard::KeyCode keyCode, Control* conAct);

		/*根据移动方向与屏幕大小以及精灵大小和移动速度判断是否允许移动精灵*/
		static bool spriteSceneMove(int act, Sprite* sprite, Size vsize, Size ssize, Vec2 position, float speed);

		/*检测指定的Node是否已移出可视范围*/
		static bool isOutScene(Node * node, Size vsize);
	};
}



奖励精灵编码:RewardSprite.cpp


#include "RewardSprite.h"
#include "ActionBase.h"
#include "Util.h"

namespace SpaceWar {

	RewardSprite::RewardSprite()
	{
	}

	RewardSprite::~RewardSprite()
	{
	}

	void RewardSprite::update(float dt)
	{
	}
}


奖励精灵编码:RewardSprite.h


#pragma once
#include "cocos2d.h"
#include "SpriteBase.h"

using namespace std;
using namespace cocos2d;

namespace SpaceWar
{
	class ActionBase;

	class RewardSprite : public SpriteBase
	{
	public:
		RewardSprite();
		virtual ~RewardSprite();

		void update(float dt);

		ActionBase* actBase = nullptr;

		/*奖励类型*/
		int rewardType = 0;

		/*飞行速度*/
		float flightSpeed = 8.0f;

		/*奖励得分*/
		int rewardScore = -1;

		/*奖励飞行速度*/
		int airSpeed = -1;

		/*奖励武器威力*/
		int armPower = -1;

		/*奖励武器类型*/
		int armType = -1;

		/*奖励导弹威力*/
		int missilePower = -1;

		/*奖励导弹类型*/
		int missileType = -1;

		/*奖励炸弹数量*/
		int bombCount = -1;

		/*奖励炸弹类型*/
		int bombType = -1;

		/*碰撞次数*/
		int collisionCount = 0;

		/*最大碰撞次数*/
		int maxCollisionCount = 0;

		/*碰撞类型掩码*/
		int category = 0b111;

		/*碰撞掩码*/
		int collision = 0b000;

		/*碰撞事件掩码*/
		int contact = 0b110;

		/*是否允许重力*/
		bool gravityEnable = false;
	};
}



飞机奖励编码:RewardQueue.cpp


#include "RewardQueue.h"

namespace SpaceWar {

	RewardQueue::RewardQueue()
	{
	}

	RewardQueue::~RewardQueue()
	{
	}
}


飞机奖励编码:RewardQueue.h


#pragma once
#include "cocos2d.h"

using namespace std;
using namespace cocos2d;

namespace SpaceWar
{
	class RewardQueue
	{
	public:
		RewardQueue();
		virtual ~RewardQueue();

		/*类型*/
		int rewardType = 0;

		/*x坐标*/
		float x = 0.0f;

		/*y坐标*/
		float y = 0.0f;

		/*奖励得分*/
		int rewardScore = -1;

		/*奖励飞行速度*/
		int airSpeed = -1;

		/*奖励武器威力*/
		int armPower = -1;

		/*奖励武器类型*/
		int armType = -1;

		/*奖励炸弹数量*/
		int bombCount = -1;

		/*奖励炸弹类型*/
		int bombType = -1;
	};
}



奖励形状编码:RewardPolygonInfo.cpp


#include "RewardPolygonInfo.h"

namespace SpaceWar {

	RewardPolygonInfo::RewardPolygonInfo(string rinfo, int rmark)
	{
		this->rewardInfo = rinfo;
		this->rewardMark = rmark;
	}

	RewardPolygonInfo::~RewardPolygonInfo()
	{
	}
}



奖励形状编码:RewardPolygonInfo.cpp



#include "cocos2d.h"

using namespace std;
using namespace cocos2d;

#pragma once
namespace SpaceWar
{
	class RewardPolygonInfo
	{
	public:
		RewardPolygonInfo(string rinfo, int rmark);
		virtual ~RewardPolygonInfo();

		/*奖励形状*/
		string rewardInfo;

		/*奖励标识*/
		int rewardMark = -1;
	};
}



C++ 与cocos2d-x-4.0完成太空飞机大战 (五)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值