cocos2dx 3.3 魂斗罗初步尝试 (目前)敌人和子弹(只做了一点点)
2014-10-27 11:39
429 查看
想把敌人设计为一个类,根据读取地图的数据来设定敌人的数据,类别。。
#pragma once #include "cocos2d.h" USING_NS_CC; class Enemy :public Sprite { public: static Enemy *createWithFile(std::string s); bool init(int Hp,bool isMove,bool isShoot); void setHP(int n); int getHP(); bool IsSHoot(); void setShoot(bool); void setMove(bool); private: int HP; bool isMove; bool isShoot; }; #include "Enemy.h" Enemy *Enemy::createWithFile(std::string s) { Enemy *enemy = new Enemy; enemy->initWithFile(s); return enemy; } bool Enemy::init(int Hp, bool isMove, bool isShoot) { this->HP = Hp; this->isMove = isMove; this->isShoot = isShoot; auto animation = Animation::create(); for (int i = 0; i < 4; i++) { std::string s = "enemy" + std::to_string(i) + ".png"; animation->addSpriteFrameWithFile(s); } animation->setDelayPerUnit(0.1); animation->setLoops(-1); auto animate = Animate::create(animation); this->runAction(animate); return true; } void Enemy::setHP(int n) { HP = n; } int Enemy::getHP() { return HP; } bool Enemy::IsSHoot() { return isShoot; } void Enemy::setShoot(bool b) { isShoot = b; } void Enemy::setMove(bool b) { isMove = b; }子弹只做了一个,只是用来测试,还没怎么写:
#pragma once #include "cocos2d.h" #include "Def.h" USING_NS_CC; class Bullt :public Sprite { public: static Bullt* createWithFile(std::string s); bool init(); int m_direction; int m_speed; void setDirection(int n); int getDirection(); }; #include "Bullt.h" Bullt *Bullt::createWithFile(std::string s) { Bullt *b = new Bullt; b->initWithFile(s); b->init(); return b; } bool Bullt::init() { m_speed = BULLT_SPEED; m_direction = STATE_PLAYER_RUNRIGHT; return true; } void Bullt::setDirection(int n) { m_direction = n; } int Bullt::getDirection() { return m_direction; }
相关文章推荐
- cocos2dx 3.3 魂斗罗初步尝试 欢迎场景和声音类
- cocos2dx 3.3 魂斗罗初步尝试 人物类
- cocos2dx 3.3 魂斗罗初步尝试 游戏层(暂停段时间,以后再写)。。。
- 【cocos2dx 3.3】口袋空战2 子弹层
- 【cocos2dx 3.3】口袋空战3 敌人层
- 用Quick3.3开发微信打飞机 (二) -------------------- 子弹和敌人的配置和创建
- 菜鸟尝试初步编程
- Node OAuth2 server 初步尝试和验证
- Arduino 中断和睡眠状态初步尝试_1
- cocos2dx3.3 跑马灯功能的简单实现
- Cocos2d-x自定义按钮类控制精灵攻击----之游戏开发《赵云要格斗》(2) cocos2dx 3.3移植版
- 前面搭建好环境后,cocos2dx3.3如何新建项目?
- cocos2dx3.3开发FlappyBird总结七:说说游戏流程
- cocos2dx3.3开发FlappyBird总结十七:结束语
- .net下对数据库操作的初步尝试
- cocos2dx3.3 打包官方cpp-tests例子Apk
- cocos2dx3.3视频播放的实现VideoPlayer的使用
- cocos2dx 3.3 跑酷游戏 人物的创建
- cocos2dx 3.3 + lua 学习笔记(02)--- 游戏场景的基本搭建
- cocos2dx-打敌人游戏(二)