bool Hero::init() { if (!Role::initWithSpriteFrameName("stand.png")) return false; if (!initAnimation()) return false; global->hero = this; setHalfBodyWidth(getContentSize().width / 4); setHP(100); setAP(5); setRunSpeed(10); setWalkSpeed(5); return true; }
bool EnemyTest::init() { if (!Sprite::init()) { return false; } instance = GameManager::getInstance(); sprite = Sprite::create("monster/monster1/right1.png"); //怪物本身的图片,初始化显示 addChild(sprite); iceSprite = Sprite::create("ice.png"); //冰块图片 iceSprite->setPosition(sprite->getPosition()); addChild(iceSprite, 2); iceSprite->setVisible(false); setType(1);//这是第一种敌人 setIsVisible(true); setRunSpeed(3); setHpPercentage(100); setMoney(2);//只值2元钱 animationRight = createAnimation("monster/monster1/right", 4, 0.1f,95,84); AnimationCache::getInstance()->addAnimation(animationRight, "monster1_right"); //这个cache里存有各种做好的动画,重要,以便后来取出用动画 animationLeft = createAnimation("monster/monster1/left", 4, 0.1f,95,84); AnimationCache::getInstance()->addAnimation(animationLeft, "monster1_left"); createAndSetHpBar(); schedule(schedule_selector(EnemyTest::changeDirection), 0.4f); schedule(schedule_selector(EnemyTest::deFroze), 0.2f); //每隔0.2秒执行一次检测是否减速函数 ////设置schduler来减缓敌人速度 //CCScheduler *defaultScheduler = CCDirector::sharedDirector()->getScheduler(); //// Create a new scheduler, and link it to the main scheduler //sched1 = new CCScheduler(); //defaultScheduler->scheduleUpdateForTarget(sched1, 0, false); //// Create a new ActionManager, and link it to the new scheudler //actionManager1 = new CCActionManager(); //sched1->scheduleUpdateForTarget(actionManager1, 0, false); //// Replace the default ActionManager with the new one. //this->setActionManager(actionManager1); return true; }
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; }
bool EnemyDisableTower::init() /*override*/ { if (!Sprite::init()) { return false; } instance = GameManager::getInstance(); sprite = Sprite::create("monster/monster_disable_tower/right1.png"); //怪物本身的图片,初始化显 addChild(sprite); iceSprite = Sprite::create("ice.png"); //冰块图片 iceSprite->setPosition(sprite->getPosition()); addChild(iceSprite, 2); iceSprite->setVisible(false); disableRing = Sprite::create("disableRing.png"); disableRing->setScale(2); addChild(disableRing, 10); auto fo = FadeOut::create(1); disableRing->runAction(RepeatForever::create(Sequence::create(fo, fo->reverse(), NULL))); setType(3);//这是第3种敌人 setIsVisible(true);//不是隐形单位 setRunSpeed(4); setHpPercentage(100); setMoney(8);//只值4元钱 animationRight = createAnimation("monster/monster_disable_tower/right", 4, 0.1f, 100, 100); AnimationCache::getInstance()->addAnimation(animationRight, "monster_disable_right"); //这个cache里存有各种做好的动画,重要,以便后来取出用动画 animationLeft = createAnimation("monster/monster_disable_tower/left", 4, 0.1f, 100, 100); AnimationCache::getInstance()->addAnimation(animationLeft, "monster_disable_left"); createAndSetHpBar(); schedule(schedule_selector(EnemyDisableTower::changeDirection), 0.4f); schedule(schedule_selector(EnemyDisableTower::deFroze), 0.2f); //每隔0.2秒执行一次检测是否减速函数 //schedule(schedule_selector(EnemyDisableTower::disableNearbyTower), 0.2f);//每隔0.2秒沉默敌人一次,有问题:不能在敌人这判断,要在炮塔那判断才行,否则会图片会闪烁 return true; }
bool Pirate::init() { if (!Sprite::init()) { return false; } setRunSpeed(50); setVaule(20); sprite = Sprite::createWithSpriteFrameName("enemyRight2_1.png"); this->addChild(sprite); animationRight = createAnimation("enemyRight2", 4, 0.1f); AnimationCache::getInstance()->addAnimation(animationRight, "runright2"); animationLeft = createAnimation("enemyLeft2", 4, 0.1f); AnimationCache::getInstance()->addAnimation(animationLeft, "runleft2"); animationExplode = createAnimation("explode2", 6, 0.15f); AnimationCache::getInstance()->addAnimation(animationExplode, "explode2"); createAndSetHpBar(); return true; }
Raider* Raider::createMonster(std::vector<Point> points) { auto monster = new Raider(); if (monster && monster->init()) { monster->setPointsVector(points); monster->setMaxHp(160); monster->setCurrHp(160); monster->setMoney(30); monster->setRunSpeed(40); monster->setArmor(10); monster->setForce(8); monster->setAttackBySoldier(true); monster->runNextPoint(); monster->autorelease(); return monster; } CC_SAFE_DELETE(monster); return NULL; }
Quetzal* Quetzal::createMonster(std::vector<Point> points) { auto monster = new Quetzal(); if (monster && monster->init()) { monster->setPointsVector(points); monster->setMaxHp(500); monster->setCurrHp(500); monster->setMoney(20); monster->setForce(45); monster->setArmor(10); monster->setAttackBySoldier(false); monster->setRunSpeed(60); monster->runNextPoint(); monster->autorelease(); return monster; } CC_SAFE_DELETE(monster); return NULL; }
Gorilla* Gorilla::createMonster(std::vector<Point> points) { auto monster = new Gorilla(); if (monster && monster->init()) { monster->setPointsVector(points); monster->setMaxHp(2500); monster->setCurrHp(2500); monster->setMoney(500); monster->setForce(60); monster->setArmor(0); monster->setAttackBySoldier(true); monster->setRunSpeed(30); monster->runNextPoint(); monster->autorelease(); return monster; } CC_SAFE_DELETE(monster); return NULL; }
bool Thief::init() { if (!Sprite::init()) { return false; } //初始化怪物的移动速度,左右方向的动画 setRunSpeed(25); setVaule(10); sprite = Sprite::createWithSpriteFrameName("enemyRight1_1.png"); this->addChild(sprite); animationRight = createAnimation("enemyRight1", 4, 0.1f); AnimationCache::getInstance()->addAnimation(animationRight, "runright1"); animationLeft = createAnimation("enemyLeft1", 4, 0.1f); AnimationCache::getInstance()->addAnimation(animationLeft, "runleft1"); animationExplode= createAnimation("explode1", 6, 0.15f); AnimationCache::getInstance()->addAnimation(animationExplode, "explode1"); createAndSetHpBar(); return true; }
Wolf* Wolf::createMonster(std::vector<Point> points) { auto monster = new Wolf(); if (monster && monster->init()) { monster->setPointsVector(points); monster->setMaxHp(35); monster->setCurrHp(35); monster->setRunSpeed(100); monster->runNextPoint(); monster->setMoney(20); monster->setArmor(0); monster->setForce(2); monster->setAttackBySoldier(true); monster->autorelease(); return monster; } CC_SAFE_DELETE(monster); return NULL; }
Boss_Efreeti* Boss_Efreeti::createMonster(std::vector<Point> points,std::vector<std::vector<std::vector<Point>>> sonpath) { auto monster = new Boss_Efreeti(); if (monster && monster->init()) { monster->setPointsVector(points); monster->setMaxHp(5550); monster->setCurrHp(5550); monster->setMoney(1500); monster->sonPath = sonpath; monster->setForce(50); monster->setArmor(10); monster->setAttackByTower(true); monster->setAttackBySoldier(true); monster->setRunSpeed(20); monster->runNextPoint(); monster->autorelease(); return monster; } CC_SAFE_DELETE(monster); return NULL; }
bool Thief::init() { if (!Sprite3D::init()) { return false; } setRunSpeed(25); setVaule(10); sprite = Sprite3D::create("orc.c3b"); this->addChild(sprite); sprite->setScale(2.0); sprite->setAnchorPoint(Vec2(0,0)); auto animation = Animation3D::create("orc.c3b"); if (animation) { auto animate = Animate3D::create(animation); bool inverse = (std::rand() % 3 == 0); int rand2 = std::rand(); float speed = 1.0f; if(rand2 % 3 == 1) { speed = animate->getSpeed() + CCRANDOM_0_1(); } else if(rand2 % 3 == 2) { speed = animate->getSpeed() - 0.5 * CCRANDOM_0_1(); } animate->setSpeed(inverse ? -speed : speed); sprite->runAction(RepeatForever::create(animate)); } createAndSetHpBar(); schedule(schedule_selector(EnemyBase::changeDirection), 0); return true; }
bool Thief::init() { if (!Sprite::init()) { return false; } setRunSpeed(9); setMaxHp(10); setCurrHp(10); sprite = Sprite::createWithSpriteFrameName("enemyRight1_1.png"); this->addChild(sprite); animationRight = createAnimation("enemyRight1", 4, 0.1f); AnimationCache::getInstance()->addAnimation(animationRight, "runright"); animationLeft = createAnimation("enemyLeft1", 4, 0.1f); AnimationCache::getInstance()->addAnimation(animationLeft, "runleft"); animationExplode= createAnimation("explode", 6, 0.15f); AnimationCache::getInstance()->addAnimation(animationExplode, "explode"); createAndSetHpBar(); schedule(schedule_selector(EnemyBase::changeDirection), 0.4f); return true; }
Tremor* Tremor::createMonster(std::vector<Point> points) { auto monster = new Tremor(); if (monster && monster->init()) { monster->setPointsVector(points); monster->setMaxHp(35); monster->setCurrHp(35); monster->setMoney(10); monster->setForce(4); monster->setArmor(0); monster->setForce(8); monster->setAttackByTower(false); monster->setAttackBySoldier(true); monster->setRunSpeed(50); monster->runNextPoint(); monster->autorelease(); return monster; } CC_SAFE_DELETE(monster); return NULL; }
bool Thief::init() { if (!Sprite::init()) { return false; } //初始化小偷的移动速度,左右方向的动画 setRunSpeed(25); setVaule(10); sprite = Sprite::createWithSpriteFrameName("enemyRight1_1.png"); this->addChild(sprite); animationRight = createAnimation("enemyRight1", 4, 0.1f); AnimationCache::getInstance()->addAnimation(animationRight, "runright1"); animationLeft = createAnimation("enemyLeft1", 4, 0.1f); AnimationCache::getInstance()->addAnimation(animationLeft, "runleft1"); animationExplode= createAnimation("explode1", 6, 0.15f); AnimationCache::getInstance()->addAnimation(animationExplode, "explode1"); createAndSetHpBar(); //调用定时器schedule刷新自定义的changeDirection函数 //schedule(schedule_selector(EnemyBase::changeDirection), 0.4f); return true; }
bool Pirate::init() { if (!Sprite3D::init()) { return false; } setRunSpeed(50); setVaule(20); sprite = Sprite3D::create("orc.c3b"); sprite->setAnchorPoint(Vec2(0,0)); sprite->setScale(2.0); this->addChild(sprite); animationRight = createAnimation("enemyRight2", 4, 0.1f); AnimationCache::getInstance()->addAnimation(animationRight, "runright2"); animationLeft = createAnimation("enemyLeft2", 4, 0.1f); AnimationCache::getInstance()->addAnimation(animationLeft, "runleft2"); animationExplode= createAnimation("explode2", 6, 0.15f); AnimationCache::getInstance()->addAnimation(animationExplode, "explode2"); createAndSetHpBar(); schedule(schedule_selector(Pirate::changeDirection), 0); return true; }