Ejemplo n.º 1
0
bool UFOSprite::initWithType(int type) {
    mType = type;

    if (type == TYPE_UFO1) {
        initWithSpriteFrameName("ufo1.png");
    } else if (type == TYPE_UFO2) {
        initWithSpriteFrameName("ufo2.png");
    } else if (type == TYPE_UFO3) {
        initWithSpriteFrameName("ufo3.png");
    }

    Size winSize = Director::getInstance()->getWinSize();
    Size s = getContentSize();
    float x = CCRANDOM_0_1()*(winSize.width-s.width)+s.width/2;
    float y = winSize.height+s.height/2;
    setPosition(x, y);

    auto m1 = MoveBy::create(0.4, Point(0, -150));
    auto m2 = MoveBy::create(0.2, Point(0, 100));
    auto m3 = MoveBy::create(0.8, Point(0, -winSize.height));
    auto m4 = RemoveSelf::create();
    Sequence *seq = Sequence::create(m1, m2, m3, m4, nullptr);
    runAction(seq);

    return true;
}
Ejemplo n.º 2
0
bool Fire::init(int base_hurt){
    if (!Sprite::init()){
        return false;
    }


    initWithSpriteFrameName("fire00.png");

    Animation* fly = GameUtile::createNormalAction("fire%02d.png", 10, 30);
    setFlyAction(Animate::create(fly));
    Animation* end = GameUtile::createNormalAction("fire_end%02d.png", 4, 20);
    setEndAction(Sequence::create(Animate::create(end),
        CallFuncN::create(CC_CALLBACK_0(Fire::EndFire, this)),
        NULL));

    m_baseHurt = base_hurt;
    m_bodyBox = GameUtile::createBoundingBox(Vec2(0, 0), getContentSize());
    m_velocity = Vec2(10, 0);
    setFlippedX(global->hero->getDirection() == ROLE_DIRECTION_RIGHT);

    m_nTimer = 0;

    scheduleUpdate();

    return true;
}
Ejemplo n.º 3
0
bool Chicken::initWithLayer( HelloWorld * layer )
{
	if (initWithSpriteFrameName("chicken_001.png"))
	{   
		_layer = layer;
		auto animation = Animation::create();
		for (int i = 1; i <= 40; i++)
		{   
			auto str = String::createWithFormat("chicken_%03d.png",i);
			auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(str->getCString());
			animation->addSpriteFrame(frame);
		}
		animation->setDelayPerUnit(1.0f / 1000 * 90);
		setNormalAnimation(animation);

		animation = Animation::create();
		for (int i = 1; i <= 12; i++)
		{   
			auto str = String::createWithFormat("ccchick_%03d.png",i);
			auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(str->getCString());
			animation->addSpriteFrame(frame);
		}
		animation->setDelayPerUnit(1.0f / 1000 * 40);
		setTrapAnimation(animation);
		layer->addChild(this);

		runAnimation(getNormalAnimation());

		return true;
	}
	return false;
}
Ejemplo n.º 4
0
void Hero::down(std::function<void()>& funcCallback)
{
    stopAllActions();
    initWithSpriteFrameName("tom_jump_1.png");
    MoveBy* moveByDown = MoveBy::create(HERO_JUMP_DOWN_TIME, Point(0.0f, -90.0f));
    CallFunc* callFunc = CallFunc::create(funcCallback);
    runAction(Sequence::create(moveByDown, callFunc, NULL));
}
Ejemplo n.º 5
0
void Food::setType(int type)
{
   this->type	=	type;
   char chType[10];
   sprintf(chType,"item%d.png",type);

   initWithSpriteFrameName(chType);
}
Ejemplo n.º 6
0
PlayerEntity* PlayerEntity::createPlayer(){
    auto player = PlayerEntity::create();
    if (player->initWithSpriteFrameName("tank11.png")) {
        player->setFrameName("tank11");
        player->setMode(PlayerModeNormal);
        CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("blast.wav");
    }
    return player;
}
Ejemplo n.º 7
0
void Bullet::initBulletWithTank(Tank* tank)
{
    mTank = tank;
    mTileMapInfo = mTank->getTileMapInfo();

    initWithSpriteFrameName("bullet.png");
    mTileMapInfo->getTileMap()->addChild(this);
    setVisible(false);
}
Ejemplo n.º 8
0
Bird::Bird()
{
    // 1. load a default image
    initWithSpriteFrameName("FlappyBird1.png");
    
    // 2. run the move action
   
    //this->scheduleUpdate( );
     this->runAction(moving());
}
Igloo* Igloo::create(GameLayer * game) {
    auto sprite = new Igloo(game);
	if (sprite && sprite->initWithSpriteFrameName("igloo_off.png")) {
		sprite->autorelease();
        sprite->addBlock();
		return sprite;
	}
	CC_SAFE_DELETE(sprite);
	return nullptr;
}
Ejemplo n.º 10
0
bool WaittClockCtrl::init()
{
    bool ret = false;
    do 
    {
        CC_BREAK_IF(!initWithSpriteFrameName("popup_timer.png"));
        setAnchorPoint(Point(0.5f, 0.5f));
        ret = true;
    } while (false);
    return ret;
}
Ejemplo n.º 11
0
///////////////////////////////////////////////////////////////
// Hero
///////////////////////////////////////////////////////////////
bool Hero::init()
{
    bool ret = false;
    do 
    {
        CC_BREAK_IF(!Sprite::init());
        CC_BREAK_IF(!initWithSpriteFrameName("tom_standing_1.png"));
        CC_BREAK_IF(!createSupperBar());
        ret = true;
    } while (false);
    return ret;
}
Ejemplo n.º 12
0
void Hero::stand(std::function<void()>& funcCallback)
{
    if (HS_STAND==_hero_status)
    {
        return;
    }
    stopAllActions();
    _hero_status = HS_STAND;
    initWithSpriteFrameName("tom_standing_1.png");
    runAction(RepeatForever::create(UIHelper::createAnimate("tom_standing_%d.png", 3, 4, 1)));
    funcCallback();
}
Ejemplo n.º 13
0
bool LeftRunBlock::init()
{
	if(!initWithSpriteFrameName("move_p1.png"))
		return false;

	CCAnimation* animation = CCAnimationCache::sharedAnimationCache()->animationByName("LeftBlockAnimation");
	
	CCAnimate* animate = CCAnimate::create(animation);
	this->runAction(CCRepeatForever::create(animate));

	return true;
}
Ejemplo n.º 14
0
void Food::setType(int type)
{
	char* foodTypeList[] = 
	{
		"bao.png",
		"food.png",
		"jiu.png",
		"zhong.png"
	};
	this->type = type;
	initWithSpriteFrameName(foodTypeList[type]);
}
Ejemplo n.º 15
0
bool Bullet::initBulletWithLevel(int level) {
    if(!Sprite::init()) return false;
    mLevel = level;
    const char* frameName = String::createWithFormat("1_%d.png", mLevel)->getCString();
    initWithSpriteFrameName(frameName);

    mSpeed = mLevel / 5 * 2 + 30;
    mAp = mLevel + 10;
    
    
    
    return true;
}
Ejemplo n.º 16
0
void Hero::resurgence(float toPos, std::function<void()>& funcCallback)
{
    if (HS_RESURGENCE==_hero_status)
    {
        return;
    }
    stopAllActions();
    _hero_status = HS_RESURGENCE;
    initWithSpriteFrameName("tom_miss_1.png");
    auto moveBy = MoveBy::create(HERO_RESTORE_TIME, Point(0.0f, toPos+90.0f));
    auto callFunc = CallFunc::create(funcCallback);
    runAction(Sequence::createWithTwoActions(moveBy, callFunc));
    runAction(RepeatForever::create(UIHelper::createAnimate("tom_res_%d.png", 4, 4, 1)));
}
Ejemplo n.º 17
0
void Tank::initTankWithTankType(const char* tankTypeName, TileMapInfo* tileMapInfo)
{
    initWithSpriteFrameName(tankTypeName);
    mTileMapInfo = tileMapInfo;

    mTileMapInfo->getTileMap()->addChild(this);

    TMXTiledMap* tmxTileMap = mTileMapInfo->getTileMap();
    Size tileSize = tmxTileMap->getTileSize();
    Size tankSize = getContentSize();

    setScale((tileSize.height * 2 - 4) / (tankSize.height));

    mBullet = Bullet::createBulletWithTank(this);
}
Ejemplo n.º 18
0
bool Bullet::init()
{
	bool bl = Sprite::init();
	if (InGameLayer::bulletState == 0)//state判断创建怎么样的子弹
	{
		initWithSpriteFrameName("bullet1_.png");
	}
	else if (InGameLayer::bulletState==1)
	{
		initWithFile("bullet_1.png");
	}

	
	return bl;
}
Ejemplo n.º 19
0
void Hero::jump(std::function<void()>& funcCallback)
{
    if (HS_JUMP==_hero_status)
    {
        return;
    }
    stopAllActions();
    _hero_status = HS_JUMP;
    SOUNDMANAGER()->playSound(ST_HERO_JUMP);
    initWithSpriteFrameName("tom_jump_1.png");
    MoveBy* moveByUp = MoveBy::create(HERO_JUMP_UP_TIME, Point(0.0f, 35.0f));
    MoveBy* moveByDown = MoveBy::create(HERO_JUMP_DOWN_TIME, Point(0.0f, -35.0f));
    CallFunc* callFunc = CallFunc::create(funcCallback);
    runAction(Sequence::create(moveByUp, moveByDown, callFunc, NULL));
}
Ejemplo n.º 20
0
void Hero::die(std::function<void()>& funcCallback)
{
    if (HS_DIE==_hero_status)
    {
        return;
    }
    stopAllActions();
    _hero_status = HS_DIE;
    SOUNDMANAGER()->playSound(ST_HERO_DIE);
    initWithSpriteFrameName("tom_miss_1.png");
    auto repeatMiss = Repeat::create(UIHelper::createAnimate("tom_miss_%d.png", 3, HERI_MISS_ANIM_TIMES, 1), 3);
    auto moveBy = MoveBy::create(HERO_MISS_DOWN_TIME, Point(0.0f, -getPositionY()));
    auto callFunc = CallFunc::create(funcCallback);
    runAction(Sequence::create(repeatMiss, moveBy, callFunc, NULL));
}
Ejemplo n.º 21
0
Panda *Panda::create()
{
    auto panda = new Panda();
    if(panda&&panda->initWithSpriteFrameName("taopaoxiongmao00000.png"))
    {
        panda->autorelease();
        panda->setAnchorPoint(Point::ANCHOR_MIDDLE_BOTTOM);
        panda->initAnimations();
        panda->runAction(RepeatForever::create(Animate::create(AnimationCache::getInstance()->getAnimation("taopaoxiongmao"))));
        panda->setDisplayFrameWithAnimationName("taopaoxiongmao", 1);
        return panda;
    }
    CC_SAFE_FREE(panda);
    return nullptr;
}
PurifyParticle::PurifyParticle(cocos2d::Vec2 position, std::string img, Player* player, std::vector<ResetParticles*>* particles, float playerDetectRange, float particleResetRange, float speed) 
	:	m_player(player),
		m_particles(particles),
		m_playerDetectRange(playerDetectRange),
		m_particleResetRange(particleResetRange),
		m_speed(speed),
		m_isFollowing(false),
		m_followOffset(rand() % 40 - 20, rand() % 40 - 20),
		m_origPos(position)
{
	setPosition(position);
	initWithSpriteFrameName(img);
	this->setCameraMask(4);
	scheduleUpdate();
}
Ejemplo n.º 23
0
bool Player::init()
{
	bool ret = false;
	do 
	{
		CC_BREAK_IF(!GameObject::init());
		setType(kGameObjectPlayer);
		CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
		cache->addSpriteFramesWithFile("Hero_image.plist");
		initWithSpriteFrameName("Hero_idle_right.png");	

		CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("Audio_jump.mp3");
		ret = true;
	}
	while (false);
	return ret;
}
Ejemplo n.º 24
0
void Tank::initTankWithTankType(const char* tankTypeName, TileMapInfo* tileMapInfo)
{
	initWithSpriteFrameName(tankTypeName);
	mTileMapInfo = tileMapInfo;

	//将坦克放入地图层中
	mTileMapInfo->getTileMap()->addChild(this);

	//缩放到合适大小
	CCTMXTiledMap* tmxTileMap = mTileMapInfo->getTileMap();
	CCSize tileSize = tmxTileMap->getTileSize();
	CCSize tankSize = getContentSize();
	//比地图上砖块小一点
	setScale((tileSize.height * 2-4) / (tankSize.height));

	//初始化坦克的子弹
	mBullet = Bullet::createBulletWithTank(this);
}
Ejemplo n.º 25
0
bool Hero::initWithWorld(b2World *world)
{
	if (!initWithSpriteFrameName("seal1.png")) {
		return false;
	}

	_world = world;
	createBody();

	_normalAnim = Animation::create();
	_normalAnim->addSpriteFrame(SpriteFrameCache::getInstance()->spriteFrameByName("seal1.png"));
	_normalAnim->addSpriteFrame(SpriteFrameCache::getInstance()->spriteFrameByName("seal2.png"));
	_normalAnim->setDelayPerUnit(0.1);

	_nextVel = 0;

	return true;
}
Ejemplo n.º 26
0
Archivo: Guard.cpp Proyecto: ilhaeYe/MB
Guard* Guard::create()
{
	auto pSprite = new Guard();
	pSprite->SetMonsterData();

	auto cache = SpriteFrameCache::sharedSpriteFrameCache();
	cache->addSpriteFramesWithFile(
		String::createWithFormat("%s/%s/%sImage.plist", pSprite->getType().c_str(), pSprite->getName().c_str(), pSprite->getName().c_str())->getCString(),
		String::createWithFormat("%s/%s/%s.png", pSprite->getType().c_str(), pSprite->getName().c_str(), pSprite->getName().c_str())->getCString()
		);
	if (pSprite->initWithSpriteFrameName(String::createWithFormat("%s.png", pSprite->getName().c_str())->getCString()))
	{
		pSprite->autorelease();
		pSprite->InitSprite();
		return pSprite;
	}
	CC_SAFE_DELETE(pSprite);
	return NULL;
}
UnlockPortals::UnlockPortals(std::string lockImg, std::string unlockImg, std::string particleBaseImg, std::string particleBaseImgExt, int numRedParticlesNeeded, std::string boundaryImg, int imgXOffset, int imgYoffset)
	:	m_numParticlesLeft(numRedParticlesNeeded),
		m_curParticleTotal(0),
		m_unlockImage(unlockImg),
		m_lockImage(lockImg),
		m_particleBaseImg(particleBaseImg),
		m_particleBaseImgExt(particleBaseImgExt),
		m_lockCollision(nullptr),
		m_unlockCollision(nullptr),
		m_boundaryImg(boundaryImg),
		m_imgXOffset(imgXOffset),
		m_imgYOffset(imgYoffset)
{
	m_unlockRect = cocos2d::Rect(0,0,0,0);
	initWithSpriteFrameName(lockImg);
	setSpriteFrame(lockImg);
	
	this->setCameraMask(4);
}
Ejemplo n.º 28
0
bool AirPlane::init()
{
    if (!GoodNPC::init() || !initWithSpriteFrameName("pet2_0.png"))
    {
        return false;
    }
    setRotation(90);
    setWalkSpeed(1);
    setRunSpeed(2);
    setAttackRate(2);
    setHalfBodyWidth(getContentSize().width / 2);
    setHP(50.0f);
    setAP(5.0f);
    setAttackRect(Rect(0, 0, 150, getContentSize().height));
    
    initAnimation();
    
    return true;
}
Ejemplo n.º 29
0
BallSprite* BallSprite::create(const Character & obj)
{
	auto pSprite = new BallSprite(obj);

	auto cache = SpriteFrameCache::sharedSpriteFrameCache();
	cache->addSpriteFramesWithFile("Ball/Ball.plist", "Ball/Ball.png");

	if (pSprite->initWithSpriteFrameName(String::createWithFormat("Ball/%s.png", pSprite->getName().c_str() )->getCString()))
	{
		pSprite->autorelease();

		pSprite->InitSprite();
		pSprite->scheduleUpdate();

		return pSprite;
	}

	CC_SAFE_DELETE(pSprite);
	return NULL;
}
Ejemplo n.º 30
0
void Tank::initTankWithTankType(const char *tankTypeName, TileMapInfo *tileMapInfo) {
    
    initWithSpriteFrameName(tankTypeName);
    mTileMapInfo = tileMapInfo;
    
    mTileMapInfo->getTileMap()->addChild(this);
    CCTMXTiledMap* tmxTileMap = mTileMapInfo->getTileMap(); 
    CCSize tileSize = tmxTileMap->getTileSize();
    
    CCSize tankSize = getContentSize();
    
    printf("cont: %f,%f\n",tankSize.width,tankSize.height);
   // CCRect rect = this->boundingBox();
   //  printf("rect_pos: %f, %f",rect.getMinX(),rect.getMinY());
    
    setScale((tileSize.height * 2-4) / (tankSize.height));
    
    
    // CCRect rect = this->boundingBox();
    // printf("rect_pos: %f, %f",rect.getMinX(),rect.getMinY());
    
   mBullet = Bullet::createBulletWithTank(this);
}