创建敌人基类
2016-02-08 13:35
483 查看
class EnemyBase : public Sprite { public: virtual bool init() override; CREATE_FUNC(EnemyBase); Animation* createAnimation(std::string prefixName, int framesNum, float delay); void changeDirection(float dt); Node* currPoint(); Node* nextPoint(); void runFllowPoint(); void setPointsVector(Vector<Node*> points); private: Vector<Node*> pointsVector; protected: int pointCounter; Animation *animationRight; Animation *animationLeft; CC_SYNTHESIZE(float, runSpeed, RunSpeed); };
//实现 Node* EnemyBase::currPoint() { return this->pointsVector.at(pointCounter); } Node* EnemyBase::nextPoint() { int maxCount = this->pointsVector.size(); pointCounter++; if (pointCounter < maxCount ){ auto node =this->pointsVector.at(pointCounter); return node; } else{ pointCounter = maxCount -1 ; } return NULL; }
//小偷是敌人要继承敌人基类 class Thief : public EnemyBase { public: virtual bool init() override; static Thief* createThief(Vector<Node*> points); };
//在基类已经给出了敌人的各种逻辑方法,所以在Thief中,我们只需要初始化变量,实现具体的方法,就可以实现一个很普通的敌人了。 bool Thief::init() { if (!Sprite::init()) { return false; } // 1 setRunSpeed(6); animationRight = createAnimation("enemyRight1", 4, 0.1f); AnimationCache::getInstance()->addAnimation(animationRight, "runright"); animationLeft = createAnimation("enemyLeft1", 4, 0.1f); AnimationCache::getInstance()->addAnimation(animationLeft, "runleft"); // 2 schedule(schedule_selector(EnemyBase::changeDirection), 0.4f); return true; }
//创建小偷的接口函数 Thief* Thief::createThief(Vector<Node*> points) { Thief *pRet = new Thief(); if (pRet && pRet->init()) { // 设置小偷的路径点集 pRet->setPointsVector(points); // 让小偷沿着路径点移动 pRet->runFllowPoint(); pRet->autorelease(); return pRet; } else { delete pRet; pRet = NULL; return NULL; } }
相关文章推荐
- eclipse在Android xml布局中提示
- 物理引擎一
- java的13种核心技术
- codevs 1992 聚会
- break和continue跳出指定for循环(for一些特点)
- MEF依赖注入无法在在构造函数中使用的解决办法
- Linux下的Nginx安装
- Java中HashMap遍历的两种方式
- 函数感悟(个人)
- Inverse Quadratic Interpolation (website)
- POJ 3233 矩阵的幂(求和)
- BZOJ 1648 USACO 2006 Dec Cow Picnic 奶牛野餐 搜索
- YTU 2503: 大斐波那契数列
- YTU 2500: 二元表达式计算
- 任务思维1
- Leetcode: Patching Array
- hdu 5621
- YTU 2697: 血型统计
- eclipse配置安卓环境(mac系统)
- 程序只运行一个实例,并激活已运行的程序