void RogueSkill4::Update(float timeStep) { if (!enabled_) { return; } if (node_->HasComponent<Dead>()) { return; } attackElapsedTime_ += timeStep; if (attackElapsedTime_ >= attackInterval_) { attackElapsedTime_ = 0.0f; Node* arrow = arrow_->Clone(LOCAL); arrow->SetEnabled(true); arrow->SetPosition(node_->GetPosition()); arrow->LookAt(dest_); arrow->AddComponent(new KinematicMoveTo(context_, main_, dest_, arrowSpeed_), 0, LOCAL); arrow->AddComponent(new SoundSource3D(context_), 0, LOCAL); arrow->GetComponent<SoundSource3D>()->SetGain(0.1f); arrow->GetComponent<SoundSource3D>()->Play(main_->cache_->GetResource<Sound>("Sounds/shoot.ogg")); SubscribeToEvent(arrow, E_NODECOLLISIONSTART, HANDLER(RogueSkill4, HandleNodeCollisionStart)); VariantMap vm; vm[AnimateSceneNode::P_NODE] = node_; if (node_->GetVar("sex").GetBool()) { vm[AnimateSceneNode::P_ANIMATION] = "attackF"; } else { vm[AnimateSceneNode::P_ANIMATION] = "attackM"; } vm[AnimateSceneNode::P_LOOP] = false; if (arrow->GetPosition().x_ < dest_.x_) { vm[AnimateSceneNode::P_LAYER] = 1; } else { vm[AnimateSceneNode::P_LAYER] = -1; } SendEvent(E_ANIMATESCENENODE, vm); } }
void SelectLevelState::OnInitialize() { Scene* scene = AddScene(new Scene("SelectLevel")); Node* camnode = scene->AddChildNode(new dt::Node("camnode")); camnode->SetPosition(Ogre::Vector3(0, 0, 10)); camnode->AddComponent(new dt::CameraComponent("cam"))->LookAt(Ogre::Vector3(0, 0, 0)); //************************************************************ //The following lines are for test purpose only. //Todo: Replace them with the actual content. Ogre::FontManager::getSingleton().load("DejaVuSans", "General"); Node* node1 = scene->AddChildNode(new dt::Node("node1")); dt::TextComponent* text1 = node1->AddComponent(new dt::TextComponent("Select Level", "text1")); text1->SetBackgroundMaterial("TextOverlayBackground"); text1->SetColor(Ogre::ColourValue::White); text1->SetFont("DejaVuSans"); text1->SetFontSize(72); text1->SetPadding(Ogre::Vector2(20, 20)); GuiRootWindow& rootWindow = GuiManager::Get()->GetRootWindow(); mReturnButton = rootWindow.CreateChild<GuiButton>("return"); mReturnButton->SetPosition(100, 100); mReturnButton->SetSize(250, 100); mReturnButton->SetCaption("Return"); dynamic_cast<MyGUI::Button*>(mReturnButton->GetMyGUIWidget())->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectLevelState::OnReturnClick); //************************************************************ }
Node* Node::Deserialize(const YAML::Node& node) { Node* n = new Node; std::string uuid; node["uuid"] >> uuid; std::cout << "::LOADING " << uuid << std::endl; n->mId = boost::uuids::string_generator()(uuid); try { for(unsigned i = 0; i < node["children"].size(); i++) { Node* c = Deserialize(node["children"][i]); if(c != nullptr) n->AddChild(c); } } catch(YAML::TypedKeyNotFound<std::string> e) {} try { for(unsigned i = 0; i < node["components"].size(); i++) { Component* c = Component::Deserialize(node["components"][i]); if(c != nullptr) n->AddComponent(c); } } catch(YAML::TypedKeyNotFound<std::string> e) {} return n; }
void CollisionComponent::OnCreate() { //Preload the bullet mesh. Node* bullet = this->GetNode()->GetScene()->AddChildNode(new Node("preload_bullet")); bullet->AddComponent(new MeshComponent(mBulletMeshHandle, "", "bullet")); bullet->SetPosition(0, -100, 0, Node::SCENE); bullet->Kill(); }
int main(int argc, char** argv) { qRegisterMetaType<ComponentA>("ComponentA"); qRegisterMetaType<ComponentB>("ComponentB"); Node base; base.AddChild(new Node)->AddComponent(new ComponentA); base.AddChild(new Node)->AddChild(new Node); Node* n = base.AddChild(new Node); n->AddComponent(new ComponentA); n->AddComponent(new ComponentB); //base.Display(); // // yaml test YAML::Emitter out; out << YAML::BeginMap; out << YAML::Key << "metadata" << YAML::Value; out << YAML::BeginMap; out << YAML::Key << "author" << YAML::Value << "opatut"; out << YAML::Key << "date" << YAML::Value << "2011-10-23"; out << YAML::EndMap; out << YAML::Key << "rootnode" << YAML::Value; base.Serialize(out); std::string yaml(out.c_str()); std::cout << "Output YAML:" << std::endl << "========" << std::endl; std::cout << yaml << std::endl; std::cout << "Base:" << std::endl << "========" << std::endl; base.Display(); std::istringstream stream; stream.str(yaml); YAML::Parser parser(stream); YAML::Node doc; parser.GetNextDocument(doc); Node* read = Node::Deserialize(doc["rootnode"]); std::cout << "Read:" << std::endl << "========" << std::endl; read->Display(); return 0; }
Node* TerrySpawner::LoadSprite(String name) { //Vector3 startPos = terrySpawns_->GetChild(Random(0,terrySpawns_->GetNumChildren()))->GetPosition(); Vector3 startPos = spawnPoint_; XMLFile* xmlFile = main_->cache_->GetResource<XMLFile>("Objects/terriesNode.xml"); Node* spriteNode = scene_->InstantiateXML(xmlFile->GetRoot(), startPos, Quaternion::IDENTITY, LOCAL); spriteNode->RemoveChild(spriteNode->GetChild("camera")); spriteNode->SetName(name); spriteNode->AddComponent(new Gravity(context_, main_), 0, LOCAL); spriteNode->AddComponent(new Speed(context_, main_), 0, LOCAL); //spriteNode->AddComponent(new RotateTo(context_, main_), 0, LOCAL); spriteNode->AddComponent(new MoveByTouch(context_, main_), 0, LOCAL); spriteNode->AddComponent(new Health(context_, main_), 0, LOCAL); spriteNode->GetComponent<MoveByTouch>()->UnsubscribeFromEvent(E_HUDBUTT); StaticSprite2D* sprite = spriteNode->CreateComponent<StaticSprite2D>(); sprite->SetCustomMaterial(SharedPtr<Material>(main_->cache_->GetResource<Material>("Materials/" + name + "Mat.xml"))); AnimatedSpriteSheet* animatedSpriteSheet = new AnimatedSpriteSheet(); animatedSpriteSheet->sheet_ = main_->cache_->GetResource<SpriteSheet2D>("Urho2D/" + name + "/" + name + "Sheet.xml"); animatedSpriteSheet->staticSprite_ = sprite; animatedSpriteSheet->playing_ = false; animatedSpriteSheet->spriteID_ = spriteIDCount_; animatedSpriteSheet->noed_ = spriteNode; animatedSpriteSheet->flipX_ = false; sprites_.Push(animatedSpriteSheet); spriteIDCount_++; Vector<String> files; files.Push("attackF.xml"); files.Push("attackM.xml"); files.Push("dieF.xml"); files.Push("dieM.xml"); files.Push("gestureF.xml"); files.Push("gestureM.xml"); files.Push("idleF.xml"); files.Push("idleM.xml"); files.Push("runF.xml"); files.Push("runM.xml"); /*main_->filesystem_->ScanDir(files, main_->filesystem_->GetProgramDir() + "Data/Urho2D/" + name + "/animations/", "*.xml", SCAN_FILES, false);*/ for (int x = 0; x < files.Size(); x++) { XMLElement ani = main_->cache_->GetResource<XMLFile>("Urho2D/" + name + "/animations/" + files[x])->GetRoot(); SpriteSheetAnimation* spriteSheetAni = new SpriteSheetAnimation(); animatedSpriteSheet->animations_.Push(spriteSheetAni); spriteSheetAni->name_ = ani.GetChild("Name").GetAttribute("name"); spriteSheetAni->loop_ = ani.GetChild("Loop").GetBool("loop"); int frameCount = ani.GetChild("FrameCount").GetInt("frameCount"); for (int x = 0; x < frameCount; x++) { SpriteSheetAnimationFrame* frame = new SpriteSheetAnimationFrame(); spriteSheetAni->frames_.Push(frame); String child = "Frame" + String(x); frame->duration_ = ani.GetChild(child).GetFloat("duration"); frame->sprite_ = ani.GetChild(child).GetAttribute("sprite"); } } bool sex = Random(0,2); animatedSpriteSheet->noed_->SetVar("sex",sex); VariantMap vm; vm[AnimateSpriteSheet::P_NODE] = node_; vm[AnimateSpriteSheet::P_SPRITEID] = animatedSpriteSheet->spriteID_; if (sex) { vm[AnimateSpriteSheet::P_ANIMATION] = "idleF"; } else { vm[AnimateSpriteSheet::P_ANIMATION] = "idleM"; } vm[AnimateSpriteSheet::P_FLIPX] = 0; SendEvent(E_ANIMATESPRITESHEET, vm); animatedSpriteSheet->noed_->SetVar("collisionCount",0); animatedSpriteSheet->noed_->SetVar("attack",1); animatedSpriteSheet->noed_->SetVar("attackInterval",1.0f); animatedSpriteSheet->noed_->SetVar("attackElapsedTime",0.0f); animatedSpriteSheet->noed_->SetVar("canAttack",false); animatedSpriteSheet->noed_->SetVar("npcType",1);//0 = hero, 1 = terry return spriteNode; }
void RangerSkill4::HandleHudButt(StringHash eventType, VariantMap& eventData) { UIElement* ele = static_cast<UIElement*>(eventData[HudButt::P_BUTT].GetPtr()); String name = ele->GetName(); if (name == "ranger") { skillSprite_->SetTexture(main_->cache_-> GetResource<Texture2D>("Textures/terriesHud/icons/ranger/I_SnailShell.png")); skillSprite_->SetOpacity(1.0f); } if (name == "skill4") { if (node_->HasComponent<Dead>()) { return; } if (main_->mySceneNode_->GetComponent<SpriteSheetPlayer>()->focusedSprite_ == "ranger") { Node* snail = snail_->Clone(LOCAL); snail->AddComponent(new Health(context_, main_), 0, LOCAL); snail->GetComponent<Health>()->killOn0_ = true; snail->GetComponent<Health>()->health_ = 1000; snail->SetEnabled(true); snail->SetPosition(node_->GetPosition() + (Vector3::BACK * 0.75) + (Vector3::UP * 0.25f)); VariantMap vm; vm[AnimateSceneNode::P_NODE] = node_; if (node_->GetVar("sex").GetBool()) { vm[AnimateSceneNode::P_ANIMATION] = "gestureF"; } else { vm[AnimateSceneNode::P_ANIMATION] = "gestureM"; } vm[AnimateSceneNode::P_LOOP] = false; vm[AnimateSceneNode::P_LAYER] = 0; SendEvent(E_ANIMATESCENENODE, vm); Node* particleStartNode_ = node_->GetScene()->CreateChild(0,LOCAL); /*ParticleEmitter* emitterStartFX_ = particleStartNode_->CreateComponent<ParticleEmitter>(LOCAL); emitterStartFX_->SetEffect(main_->cache_->GetResource<ParticleEffect>("Particle/dustCloud.xml")); emitterStartFX_->SetViewMask(1);*/ particleStartNode_->SetPosition(node_->GetPosition()); //emitterStartFX_->SetEmitting(true); particleStartNode_->AddComponent(new TimedRemove(context_, main_, 2.0f), 0, LOCAL); particleStartNode_->AddComponent(new SoundSource3D(context_), 0, LOCAL); particleStartNode_->GetComponent<SoundSource3D>()->SetGain(0.1f); particleStartNode_->GetComponent<SoundSource3D>()->Play(main_->cache_->GetResource<Sound>("Sounds/265385__b-lamerichs__sound-effects-01-03-2015-8-pops-2.ogg")); } } }
void WizardSkill0::HandleTouchEnd(StringHash eventType, VariantMap& eventData) { if (main_->ui_->GetFocusElement() )//|| touchSubscriberCount_) { return; } using namespace TouchEnd; Ray cameraRay = main_->mySceneNode_->GetComponent<SpriteSheetPlayer>()-> modelNode_->GetChild("camera")->GetComponent<Camera>()->GetScreenRay( (float) eventData[P_X].GetInt() / main_->graphics_->GetWidth(), (float) eventData[P_Y].GetInt() / main_->graphics_->GetHeight()); PhysicsRaycastResult raeResult_; node_->GetScene()->GetComponent<PhysicsWorld>()->RaycastSingle(raeResult_, cameraRay, 10000.0f, 1);//todo define masks. if (raeResult_.body_) { dest_ = raeResult_.position_; Node* meteor = meteor_->Clone(LOCAL); meteor->SetEnabled(true); meteor->SetPosition(node_->GetPosition() + (Vector3::UP * 3.0f)); meteor->LookAt(dest_); Vector3 victoria = meteor->GetDirection() * 2.0f; dest_ += victoria; meteor->AddComponent(new KinematicMoveTo(context_, main_, dest_, meteorSpeed_), 0, LOCAL); meteor->AddComponent(new SoundSource3D(context_), 0, LOCAL); meteor->GetComponent<SoundSource3D>()->Play(main_->cache_->GetResource<Sound>("Sounds/273587__n-audioman__mag-explosion.ogg")); SubscribeToEvent(meteor, E_NODECOLLISIONSTART, HANDLER(WizardSkill0, HandleNodeCollisionStart)); VariantMap vm; vm[AnimateSceneNode::P_NODE] = node_; if (node_->GetVar("sex").GetBool()) { vm[AnimateSceneNode::P_ANIMATION] = "gestureF"; } else { vm[AnimateSceneNode::P_ANIMATION] = "gestureM"; } vm[AnimateSceneNode::P_LOOP] = false; if (meteor->GetPosition().x_ < dest_.x_) { vm[AnimateSceneNode::P_LAYER] = 1; } else { vm[AnimateSceneNode::P_LAYER] = -1; } SendEvent(E_ANIMATESCENENODE, vm); elapsedTime_ = 0.0f; cooling_ = true; } VariantMap vm; SendEvent(E_TOUCHUNSUBSCRIBE, vm); touchSubscribed_ = false; UnsubscribeFromEvent(E_TOUCHEND); }