您的位置:首页 > 移动开发 > Cocos引擎

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: