bool Missile::init() { _Model = Sprite3D::create("daodanv001.obj", "daodan_32.png"); if(_Model) { addChild(_Model); _radius=10; _type = kPlayerMissiles; _Model->setScale(3); _Model->setRotation3D(Vertex3F(90,0,0)); _damage = 75; static_cast<Sprite3D*>(_Model)->setOutline(0.3, Color3B(0,0,0)); _left = (CCRANDOM_MINUS1_1()>0); if(_left) _yRotSpeed *= -1; // missile effects auto part2 = ParticleSystemQuad::create("emission.plist"); addChild(part2); part2->setPosition(0,-34); part2->setPositionType(tPositionType::GROUPED); //part2->setScale(2.5); auto part1 = ParticleSystemQuad::create("missileFlare.plist"); addChild(part1); part1->setPosition(0,-30); part1->setPositionType(tPositionType::GROUPED); part1->setScale(2.5); return true; } return false; }
bool HandObjectState::readFromFile(FILE *fp) { //this whole read-write system is one big hack. int type; fpos_t pos; fgetpos(fp,&pos); if (!fscanf(fp,"%d",&type)) return false; DBGP("Pose type: " << type); if ( (StateType)type != POSE_DOF && (StateType)type != POSE_EIGEN ) return false; if ( type != mPosture->getType() ) { setPostureType((StateType)type); } fsetpos(fp,&pos); if ( !mPosture->readFromFile(fp) ) { DBGA("Failed"); return false; } fgetpos(fp,&pos); if (!fscanf(fp,"%d",&type)) return false; DBGP("Space type: " << type); if ( (StateType)type != SPACE_COMPLETE && (StateType)type != SPACE_APPROACH && (StateType)type != SPACE_AXIS_ANGLE && (StateType)type != SPACE_ELLIPSOID ) return false; if ( type != mPosition->getType() ) { setPositionType((StateType)type); } fsetpos(fp,&pos); if ( !mPosition->readFromFile(fp) ) return false; return true; }
void Ship::landOnIsle(const uint inIsleId, const QPointF inPos) { m_onIsleById = inIsleId; setPositionType(ShipPositionEnum::SP_ONISLE); m_pos = inPos; setTargetFinished(); }
bool Ship::nextRound() { if(m_positionType == ShipPositionEnum::SP_TRASH or m_positionType == ShipPositionEnum::SP_IN_FLEET) { return false; // we don't care, because universe/fleet does } if(m_targetList.count() == 0) return false; // Rod_Steward::Sailing, YouTube::DyIw0gcgfik Target currentTarget = m_targetList[m_currentTargetIndex]; setPositionType(ShipPositionEnum::SP_OCEAN); float dx = currentTarget.pos.x() - m_pos.x(); float dy = currentTarget.pos.y() - m_pos.y(); float d = sqrt( dx * dx + dy * dy ); if(d <= m_technology) return true; float ex = dx / d; float ey = dy / d; m_pos = QPointF{m_pos.x() + m_technology * ex, m_pos.y() + m_technology * ey}; m_shape->setPos(m_pos); return false; }
bool SmallDevil::ToDamage(int dmg){ hp -= dmg; auto blood = ParticleSystemQuad::create("bloodParticle.plist"); blood->setPosition(this->GetHitPoint()); blood->setPositionType(ParticleSystem::PositionType::RELATIVE); blood->setAutoRemoveOnFinish(true); CreatureLayer::GetInstance()->addChild(blood, 6); if(hp <= 0){ auto effect = Sprite::createWithSpriteFrameName("sdExplosion00.png"); effect->setPosition(this->getPosition()); effect->setAnchorPoint(Point::ANCHOR_MIDDLE); effect->setScale(info.option/5.0f); CreatureLayer::GetInstance()->addChild(effect, 6); auto act1 = Animation::create(); act1->setDelayPerUnit(0.03f); for(int i=0; i<4; i++){ auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(StringUtils::format("sdExplosion%02d.png", i)); act1->addSpriteFrame(frame); } auto act2 = Animate::create(act1); auto act3 = Sequence::create(act2, RemoveSelf::create(), NULL); effect->runAction(act3); return false; } return true; }
void Ship::addToFleet(const uint inFleetId) { // we don't have own targets removeTargets(); if(m_positionType == ShipPositionEnum::SP_TRASH) return; setPositionType(ShipPositionEnum::SP_IN_FLEET); m_fleetId = inFleetId; }
void Ship::removeFromFleet(const ShipInfo inFleetInfo) { if(m_positionType == ShipPositionEnum::SP_TRASH) return; setPositionType(inFleetInfo.posType); m_onIsleById = inFleetInfo.isleId; m_carryTechnology = inFleetInfo.carryTechnology; m_pos = inFleetInfo.pos; m_fleetId = 0; }
void Ship::setDead() { setPositionType(ShipPositionEnum::SP_TRASH); removeTargets(); if(m_shipType == ShipTypeEnum::ST_FLEET) { for(Ship *s : m_fleetShips) s->setDead(); updateFleet(); } }
bool StageScoreScene::fillListViewScoreRecords() { if (_stageManager == nullptr || _listView_scoreRecords == nullptr) { return false; } // TODO: may need to handle exepction later for (auto recordIt : _stageManager->getStageScoreRecords()) { auto item = Item_StageScoreRecord::createItem(recordIt.second); item->setAnchorPoint(Vec2(0.5,0.5)); item->setPositionType(ui::Widget::PositionType::PERCENT); item->setPositionPercent(Vec2(0.5,0.5)); _listView_scoreRecords->pushBackCustomItem(item); } return true; }
void EvilQueenBlade::Arrive(bool isBullet){ auto particle = ParticleSystemQuad::create("shatterParticle.plist"); particle->setPosition(this->getPosition()); particle->setAutoRemoveOnFinish(true); particle->setPositionType(ParticleSystem::PositionType::RELATIVE); CreatureLayer::GetInstance()->addChild(particle, 6); this->runAction(TintTo::create(0.5f, 0, 0, 0)); if(aim) CreatureLayer::GetInstance()->removeChild(aim); if(isBullet) CreatureLayer::GetInstance()->EraseBullet(this); else CreatureLayer::GetInstance()->EraseMissile(this); this->unscheduleUpdate(); }
void Ship::updateFleet() { Q_ASSERT(m_shipType == ShipTypeEnum::ST_FLEET); float techlevel = 0.0; float maxTech = 0.0; float damage = 0.0; m_carryTechnology = 0.0; for(Ship * &s : m_fleetShips) { ShipInfo shipInfo = s->info(); if(shipInfo.shipType == ShipTypeEnum::ST_FLEET) { s->updateFleet(); // update info shipInfo = s->info(); } if(s->isDead()) { m_fleetShips.removeOne(s); // delete all elements, if s is a fleet deleteFleetContent(s); delete s; } else { // @fixme: I'm not sure, if this is all correct maxTech = shipInfo.technology > maxTech ? shipInfo.technology : maxTech; techlevel += shipInfo.technology; damage = damage + shipInfo.technology * shipInfo.damage; if(shipInfo.carryTechnology > m_carryTechnology) m_carryTechnology = shipInfo.carryTechnology; } } m_technology = maxTech; m_damage = damage / techlevel; if(m_damage >= 0.99f or m_fleetShips.count() == 0) setPositionType(ShipPositionEnum::SP_TRASH); }
bool GetUnitScene::fillListViewUnitRecords() { _listView_unitRecords->removeAllItems(); if (_statusManager == nullptr || _listView_unitRecords == nullptr) { return false; } // TODO: may need to handle exepction later auto records = _statusManager->getUnitRecords(); for (auto it = records.begin(); it != records.end(); it++) { auto record = *it; auto index = it - records.begin(); auto item = ListItem_UnitRecord::createListItem(record); item->setAnchorPoint(Vec2(0.5,0.5)); item->setPositionType(ui::Widget::PositionType::PERCENT); item->setPositionPercent(Vec2(0.5,0.5)); item->index = index; _listView_unitRecords->pushBackCustomItem(item); } return true; }
// on "init" you need to initialize your instance bool MainMenuScene::init() { if ( !Layer::init() ) { return false; } pRate = 3.1415926/2; // Music By Matthew Pable (http://www.matthewpablo.com/) // Licensed under CC-BY 3.0 (http://creativecommons.org/licenses/by/3.0/) CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("Star_Chaser.mp3"); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("menu_scene.plist","menu_scene.png"); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Particle.plist","Particle.png"); Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); //************ adds Plane **************** plane = Plane::create(); this->addChild(plane, 10); this->scheduleUpdate(); //************ adds emission flare **************** auto flare = ParticleSystemQuad::create("missileFlare.plist"); flare->setScale(5); float originX = -9.0f; float originY = 159.0f; float originZ = 9.0f; flare->setTotalParticles(50); flare->setRotation3D(Vertex3F(-originX,-originY,-originZ)); flare->setPosition(-39,0); flare->setPositionType(tPositionType::GROUPED); flare->setStartColor(Color4F(0,0.99,1,1)); plane->addChild(flare, -1); auto emis = ParticleSystemQuad::create("menuEmission.plist"); emis->setScale(3); emis->setRotation3D(Vertex3F(-originX,-originY,-originZ)); emis->setPosition(-40,0); emis->setPositionType(tPositionType::GROUPED); emis->setRotation(180); plane->addChild(emis, -2); //************ adds vanishing **************** auto fileUtil = FileUtils::getInstance(); auto plistData = fileUtil->getValueMapFromFile("vanishingPoint.plist"); //auto sf = SpriteFrame::create("bullets.png", Rect(5,8,24,32)); auto vanishing = ParticleSystemQuad::create(plistData); vanishing->setAnchorPoint(Point(0.5f,0.5f)); vanishing->setPosition(visible_size_macro.width-90,visible_size_macro.height/2 +50); this->addChild(vanishing,1,1); //************* adds background *********** auto background = Sprite::createWithSpriteFrameName("mainmenu_BG.png"); background->setAnchorPoint(Point(0,0)); this->addChild(background,-1,-1); //************* adds start game *********** auto start_normal=Sprite::createWithSpriteFrameName("start_game.png"); auto start_pressed=Sprite::createWithSpriteFrameName("start_game.png"); startgame_item = MenuItemSprite::create(start_normal, start_pressed, CC_CALLBACK_1(MainMenuScene::startgame, this)); startgame_item->setPosition(visibleSize.width/2,200); startgame_item->setScale(1.3); //************* license ******************* auto license_normal=Sprite::createWithSpriteFrameName("license.png"); auto license_pressed=Sprite::createWithSpriteFrameName("license.png"); license_item = MenuItemSprite::create(license_normal, license_pressed, CC_CALLBACK_1(MainMenuScene::license, this)); license_item->setPosition(visibleSize.width/2-200,100); license_item->setScale(0.7); //************* credits ****************** auto credits_normal=Sprite::createWithSpriteFrameName("credits.png"); auto credits_pressed=Sprite::createWithSpriteFrameName("credits.png"); credits_item = MenuItemSprite::create(credits_normal, credits_pressed, CC_CALLBACK_1(MainMenuScene::credits, this)); credits_item->setPosition(visibleSize.width/2+200,100); credits_item->setScale(0.7); //************* Menu ****************** auto menu = Menu::create(startgame_item,license_item,credits_item, NULL); menu->setPosition(origin); this->addChild(menu,3); return true; }
Head_ParticalEffect void addParticalToHead(Node* node) { Vec2 pos[4]; pos[0] = Vec2(5, 75); pos[1] = Vec2(75, 75); pos[2] = Vec2(75, 5); pos[3] = Vec2(5, 5); for (int i = 0; i < 2; i++) { auto partNode = ParticleSystemQuad::createWithTotalParticles(60); partNode->setTexture(TextureCache::getInstance()->addImage("GameUI/CommonUI/fire.png"));//设置粒子图 partNode->setDuration(-1);//发射时长 // life of particles partNode->setLife(0.5f);//粒子生命 partNode->setLifeVar(0.1f); partNode->setEmissionRate(partNode->getTotalParticles() / partNode->getLife());//发射器发射频率 partNode->setPositionType(ParticleSystem::PositionType::FREE);//设置发射器的跟随模式 // color of particles partNode->setStartColor(ccc4f(0.76f, 0.25f, 0.12f, 1.0f));//起始颜色 partNode->setStartColorVar(ccc4f(0.1f, 0.1f, 0.1f, 0.0f)); partNode->setEndColor(ccc4f(1.0f, 1.0f, 1.0f, 1.0f));//结束颜色 partNode->setEndColorVar(ccc4f(0.1f, 0.1f, 0.1f, 0.1f)); // size, in pixels partNode->setStartSize(15);//粒子大小 partNode->setStartSizeVar(3); partNode->setEndSize(0); partNode->setEndSizeVar(3); // angle partNode->setAngle(0);//发射器角度 partNode->setAngleVar(0); // speed of particles partNode->setSpeed(0);//粒子速度 partNode->setSpeedVar(0); // emitter position partNode->setPosVar(ccp(0, 0));//发射器位置变化 partNode->setBlendAdditive(true); node->addChild(partNode); partNode->setTag(PARTICALTAG); auto move0 = MoveTo::create(1.f, pos[0]); auto move1 = MoveTo::create(1.f, pos[1]); auto move2 = MoveTo::create(1.f, pos[2]); auto move3 = MoveTo::create(1.f, pos[3]); if (i == 0) { partNode->setPosition(pos[0]); partNode->runAction(RepeatForever::create(Sequence::create(move1, move2, move3, move0, nullptr))); } else { partNode->setPosition(pos[2]); partNode->runAction(RepeatForever::create(Sequence::create(move3, move0, move1, move2, nullptr))); } } }
bool FiledScene::init(){ if (!Layer::init()) return false; _isGameOver = false; auto visibleSize = Director::getInstance()->getVisibleSize(); _screenWidth = visibleSize.width; _screenHeight = visibleSize.height; _tileMap = TMXTiledMap::create("field_map.tmx"); _tileMap->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _tileMap->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2)); // ②获取障碍层,并设置障碍层为不可见 _collidable = _tileMap->getLayer("collidable"); _collidable->setVisible(false); /********③初始化读取地图所有网格,并确定网格对象是否是障碍物,将信息保存到网格二维数组**************/ for (int i = 0; i < _tileMap->getMapSize().width; i++) { // 内部网格集合([x,0]-[x-20]),存储网格 Vector<Grid*> inner; for (int j = 0; j < _tileMap->getMapSize().height; j++) { // 设置网格对象的x轴和y轴以及是否可通过变量值 Grid *o = Grid::create(i, j); // 将网格加入到集合 inner.pushBack(o); } // 将内部集合加入到网格集合 _gridVector.push_back(inner); } // 循环保存根据每个网格的x轴和y轴查找对应的地图的GID,判断是否可通过 for (int i = 0; i < _gridVector.size(); i++) { Vector<Grid*> inner = _gridVector.at(i); // 循环内部网格集合 for (int j = 0; j < inner.size(); j++) { // 获取每一个网格对象 Grid *grid = inner.at(j); // 获取每一个网格对象对应的的坐标 Vec2 tileCoord = Vec2(grid->getX(), grid->getY()); // 使用TMXLayer类的tileGIDAt函数获取TileMap坐标系里的“全局唯一标识”GID int tileGid = _collidable->getTileGIDAt(tileCoord); if (tileGid) { // 使用GID来查找指定tile的属性,返回一个Value Value properties = _tileMap->getPropertiesForGID(tileGid); // 返回的Value实际是一个ValueMap ValueMap map = properties.asValueMap(); // 查找ValueMap,判断是否有”可碰撞的“物体,如果有,设置网格对象的isPass变量为false std::string value = map.at("collidable").asString(); if (value.compare("true") == 0) { grid->setPass(false); } } } } // 人物出场特效 auto effects_player_out = Sprite::create("effects/effects_player_out/effects_player_out_11.png"); effects_player_out->setPosition(Vec2(visibleSize.width*0.3,visibleSize.height*0.3)); this->addChild(effects_player_out, 1); auto player_out_animate = getAnimateByName("effects/effects_player_out/effects_player_out_", 0.1f, 11); auto delay1 = DelayTime::create(1.5f); auto fadeOut = FadeOut::create(0.2f); auto sequence = Sequence::create(delay1, player_out_animate, fadeOut, nullptr); effects_player_out->runAction(sequence); _player = SpriteBase::create("player/player_sword/player_sword_stand.png"); this->addChild(_player, 1); _player->setPosition(Vec2(visibleSize.width*0.3, visibleSize.height*0.3)); this->addChild(_tileMap,0); _player->setFlippedX(true); XmlTools::readPlayerData(_player); /// 传送门 ArmatureDataManager::getInstance()->addArmatureFileInfo("/buildings/gate/AnimationStart0.png", "/buildings/gate/AnimationStart0.plist", "/buildings/gate/AnimationStart.ExportJson"); Armature *armature = Armature::create("AnimationStart"); armature->getAnimation()->play("Start"); this->addChild(armature); armature->setScale(0.3); armature->setPosition(Vec2(visibleSize.width*0.9, visibleSize.height*0.7)); auto gate_effect = ParticleSystemQuad::create("effects/gate_effect.plist"); this->addChild(gate_effect); gate_effect->setScale(0.3); gate_effect->setPosition(Vec2(visibleSize.width*0.9, visibleSize.height*0.75)); gate_effect->setPositionType(kCCPositionTypeRelative); // 结束战斗按钮 auto end_fight_button = Button::create("ui/end_fight.png"); end_fight_button->setPosition(Vec2(visibleSize.width*0.95, visibleSize.height*0.97)); end_fight_button->setScale(0.5f); this->addChild(end_fight_button, 0); //结束战斗对话框 auto end_fight_dialog_bg = Sprite::create("ui/end_fight_dialog_bg.png"); end_fight_dialog_bg->setAnchorPoint(Vec2::ANCHOR_MIDDLE); end_fight_dialog_bg->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2)); this->addChild(end_fight_dialog_bg, 3); // 确定结束战斗按钮 auto end_fight_sub_button = Button::create("ui/end_fight_sub_button.png"); end_fight_dialog_bg->addChild(end_fight_sub_button); end_fight_sub_button->setAnchorPoint(Vec2::ZERO); end_fight_sub_button->setPosition(Vec2(20, 30)); end_fight_sub_button->addTouchEventListener([=](Ref* pSender, Widget::TouchEventType type){ XmlTools::writePlayerData(_player); auto transition = TransitionSplitCols::create(2, Game::createScene()); Director::getInstance()->pushScene(transition); }); // 取消结束战斗按钮 auto end_fight_cancel_button = Button::create("ui/end_fight_cancel_button.png"); end_fight_dialog_bg->addChild(end_fight_cancel_button); end_fight_cancel_button->setAnchorPoint(Vec2::ZERO); end_fight_cancel_button->setPosition(Vec2(140, 30)); end_fight_cancel_button->addTouchEventListener([=](Ref* pSender, Widget::TouchEventType type){ end_fight_dialog_bg->setVisible(false); }); end_fight_dialog_bg->setVisible(false); end_fight_button->addTouchEventListener([=](Ref* pSender, Widget::TouchEventType type){ if (type == Widget::TouchEventType::ENDED){ end_fight_dialog_bg->setVisible(true); } }); // ⑤创建事件监听器 auto gameListener = EventListenerTouchOneByOne::create(); // 响应触摸事件函数 gameListener->onTouchBegan = [](Touch* touch, Event* event){return true; }; gameListener->onTouchEnded = [=](Touch *touch, Event *event){ // OpenGL坐标 Vec2 touchLocation = touch->getLocation(); // 将触摸点坐标转换成相对的Node坐标 Vec2 nodeLocation = this->convertToNodeSpace(touchLocation); // 玩家镜像反转 if (_player->getPosition().x > nodeLocation.x) { if (_player->isFlippedX() == true){ _player->setFlippedX(false); } } else{ if (_player->isFlippedX() == false) _player->setFlippedX(true); } // 用玩家位置作为起点,触摸点作为终点,转换为网格坐标,在地图上查找最佳到达路径 Vec2 from = tileCoordForPosition(_player->getPosition()); Vec2 to = tileCoordForPosition(nodeLocation); // 如果终点是不可通过(即有障碍物)的位置,则直接return int tileGid = _collidable->getTileGIDAt(to); if (tileGid) { // 使用GID来查找指定tile的属性,返回一个Value Value properties = _tileMap->getPropertiesForGID(tileGid); // 返回的Value实际是一个ValueMap ValueMap map = properties.asValueMap(); // 查找ValueMap,判断是否有”可碰撞的“物体,如果有,直接返回 std::string value = map.at("collidable").asString(); if (value.compare("true") == 0) { return; } } /**************玩家精灵移动到指定位置************************/ // 在玩家精灵移动过程中,如果用户在此触摸屏幕移动玩家时,如果精灵没有运行动作,直接执行移动动作 if (_player->getNumberOfRunningActions() == 0) { this->playerMover(nodeLocation); } else { //如果精灵正在运行动作,先停止精灵动作和层动作,再执行移动动作 _player->stopAllActions(); this->stopAllActions(); this->playerMover(nodeLocation); } // 接触传送门, 如果boss被杀死, 则传送回主场景. if (_player->getBoundingBox().intersectsRect(armature->getBoundingBox())){ if (monster_1->isVisible()==false){ _player->setExp(_player->getExp() + 200); _player->setGold(_player->getGold() + 1000); XmlTools::writePlayerData(_player); const string player_task = FileUtils::getInstance()->fullPathForFilename("data/kill_count.xml"); ssize_t player_taskFile_size; char* pPlayerTaskContent = (char*)FileUtils::getInstance()->getFileData(player_task, "r", &player_taskFile_size); TiXmlDocument* player_task_el = new TiXmlDocument(); player_task_el->Parse(pPlayerTaskContent, 0, TIXML_ENCODING_UTF8); TiXmlElement* rootElement = player_task_el->RootElement();//Root TiXmlElement* player_kill_count_1 = rootElement->FirstChildElement(); string accept = player_kill_count_1->GetText(); TiXmlElement* player_kill_count_2 = player_kill_count_1->NextSiblingElement(); stringstream ss; string kill_count = player_kill_count_2->GetText(); int kill_count_int; ss << kill_count; ss >> kill_count_int; if (accept=="true"){ kill_count_int += 1; player_kill_count_2->Clear(); string kill_count_str; stringstream ss; ss << kill_count_int; ss >> kill_count_str; TiXmlText* kill_count_text = new TiXmlText(kill_count_str.c_str()); player_kill_count_2->LinkEndChild(kill_count_text); player_task_el->SaveFile(player_task.c_str()); } auto transform_to = TransitionSplitCols::create(2.0f, Game::createScene()); Director::getInstance()->pushScene(transform_to); }