virtual void Initialize() { for(int i = 1; i <= 10; i++){ Entity* pEntity = Repo::Core()->CreateEntity(); pEntity->AddComponent(new BuildingComponent()); pEntity->AddComponent(new TypeComponent("House")); pEntity->AddComponent(new LevelComponent(i)); cout << "New entity created of type " << GetType(pEntity) << " and level " << GetLevel(pEntity) << endl; } }
Entity* CommonFactory::CreateCamera() { Entity* camera = new Entity(); TransformComponent* transformComponent = new TransformComponent(); PhysicsComponent* physicsComponent = new PhysicsComponent(); CameraComponent* cameraComponent = new CameraComponent(); cameraComponent->UseCamera(); camera->AddComponent(physicsComponent); camera->AddComponent(cameraComponent); camera->AddComponent(transformComponent); return camera; }
void Box2DSystem::__AddCircle(const sf::Vector2f& pos) { // Define the dynamic body. We set its position and call the body factory. b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position.Set(pos.x, pos.y); b2Body* body = m_world->CreateBody(&bodyDef); // Define another box shape for our dynamic body. b2CircleShape dynamicCircle; dynamicCircle.m_p.Set(pos.x,pos.y); dynamicCircle.m_radius = .5; // Define the dynamic body fixture. b2FixtureDef fixtureDef; fixtureDef.shape = &dynamicCircle; // Set the box density to be non-zero, so it will be dynamic. fixtureDef.density = 1.0f; // Override the default friction. fixtureDef.friction = 0.3f; // Add the shape to the body. body->CreateFixture(&fixtureDef); Entity* boxEntity = GetOwner()->CreateEntity(); Box2DComponent* boxComponent = Box2DComponent::Pool.CreateComponent(); boxEntity->AddComponent(boxComponent); boxComponent->m_body = body; }
Entity* SkyboxSystem::AddSkybox() { Entity* result = skyboxEntity; if(NULL == skyboxEntity) { SkyboxRenderObject* skyboxRenderObject = new SkyboxRenderObject(); AABBox3 box = AABBox3(Vector3(-0.5f, -0.5f, -0.5f), Vector3(0.5f, 0.5f, 0.5f)); skyboxRenderObject->Initialize(box); //first time initialization RenderComponent* renderComponent = new RenderComponent(); renderComponent->SetRenderObject(skyboxRenderObject); result = new Entity(); result->SetName("Skybox"); result->RemoveComponent(Component::RENDER_COMPONENT); result->AddComponent(renderComponent); renderComponent->Release(); GetScene()->AddNode(result); Matrix4 * worldTransformPointer = ((TransformComponent*)result->GetComponent(Component::TRANSFORM_COMPONENT))->GetWorldTransformPtr(); skyboxRenderObject->SetWorldTransformPtr(worldTransformPointer); result->GetScene()->renderSystem->MarkForUpdate(skyboxRenderObject); SafeRelease(skyboxRenderObject); DVASSERT(skyboxEntity); result->Release(); } return result; }
bool LandscapesController::ShowEditorLandscape(EditorLandscape *displayingLandscape) { Landscape *landscape = EditorScene::GetLandscape(scene); if (!landscape) { Logger::Error("[LandscapesController::ShowEditorLandscape] Can be only one landscape"); return false; } displayingLandscape->SetNestedLandscape(landscape); if(!landscapeRenderer) { renderedHeightmap = new EditorHeightmap(landscape->GetHeightmap()); landscapeRenderer = new LandscapeRenderer(renderedHeightmap, landscape->GetBoundingBox()); displayingLandscape->SetHeightmap(renderedHeightmap); } displayingLandscape->SetRenderer(landscapeRenderer); //TODO: remove SetWorldTransformPtr displayingLandscape->SetWorldTransformPtr(landscape->GetWorldTransformPtr()); Entity* lanscapeNode = EditorScene::GetLandscapeNode(scene); lanscapeNode->RemoveComponent(Component::RENDER_COMPONENT); RenderComponent* component = new RenderComponent(displayingLandscape); lanscapeNode->AddComponent(component); currentLandscape = displayingLandscape; return true; }
void Box2DSystem::__AddCube(const sf::Vector2f& pos) { // Define the dynamic body. We set its position and call the body factory. b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position.Set(pos.x, pos.y); b2Body* body = m_world->CreateBody(&bodyDef); // Define another box shape for our dynamic body. b2PolygonShape dynamicBox; float width = Random::NextNormal(4.0f,1.0f); float height = Random::NextNormal(10.0f, 3.0f); dynamicBox.SetAsBox(width,height); // Define the dynamic body fixture. b2FixtureDef fixtureDef; fixtureDef.shape = &dynamicBox; // Set the box density to be non-zero, so it will be dynamic. fixtureDef.density = 1.0f; // Override the default friction. fixtureDef.friction = 0.3f; // Add the shape to the body. body->CreateFixture(&fixtureDef); Entity* boxEntity = GetOwner()->CreateEntity(); Box2DComponent* boxComponent = Box2DComponent::Pool.CreateComponent(); boxEntity->AddComponent(boxComponent); boxComponent->m_body = body; }
void DungeonSystem::Init(GameCommon* owner) { System::Init(owner); Entity* dungeonEntity = GetOwner()->CreateEntity(); DungeonComponent* dungeonComponent = DungeonComponent::Pool.CreateComponent(); dungeonEntity->AddComponent(dungeonComponent); }
Entity* ParticlesEditorSceneModelHelper::CreateParticleEffectNode() { Entity * newParentNodeParticleEffect = new Entity(); newParentNodeParticleEffect->SetName(ResourceEditor::PARTICLE_EFFECT_NODE_NAME); newParentNodeParticleEffect->AddComponent(ScopedPtr<ParticleEffectComponent> (new ParticleEffectComponent())); return newParentNodeParticleEffect; }
int main(int argc, const char * argv[]) { EntityManager *Manager = new EntityManager; Entity *Thingy = Manager->GetNewEntity(); Thingy->AddComponent("Physics", new PhysicsClass()); Thingy->AddComponent("Graphics", new GraphicsClass()); Manager->Update(1.0f); delete Manager; Manager = NULL; system("PAUSE"); return 0; }
void TestGame::Init() { Entity *camera = new Entity( Vector3f( 0, 5, 15 ) ); camera->AddComponent( new FreeLookFreeMoveComponent() ); SetCamera( camera ); Planet *planet = new Planet( 12310, 4, 10.0f, 30 ); Entity *entity = new Entity(); RenderComponent* render = new RenderComponent( planet->CreateMesh() ); render->SetShaderType( ShaderType::SHADER_COLORIZED ); entity->AddComponent( render ); entity->AddComponent( new PlanetColorComponent( planet ) ); AddToScene( entity ); // Entity* cube = new Entity(); // cube->AddComponent( new RenderComponent( "cube.obj", "test.png" ) ); // AddToScene( cube ); }
Entity* ParticlesEditorSceneModelHelper::CreateParticleEffectNode() { Entity * newParentNodeParticleEffect = new Entity(); newParentNodeParticleEffect->SetName("Particle effect"); ParticleEffectComponent * newEffectComponent = new ParticleEffectComponent(); newParentNodeParticleEffect->AddComponent(newEffectComponent); return newParentNodeParticleEffect; }
Entity * EntityFactory::CreateDrone(double x, double y, double rotation) { Entity * entity; Image * drone = nullptr; drone = ResourceStore::Instance().GetDroneImage(63, 1); entity = new Entity(x, y, drone->GetWidth(), drone->GetHeight(), rotation); ComponentRenderer * renderer = new ComponentRenderer(drone,0, 63, 30); entity->AddComponent(renderer); entityStore.Add(entity); return entity; }
Entity * EntityFactory::CreateSmallExplosion(double x, double y) { Entity * entity; Image * explosion = nullptr; explosion = ResourceStore::Instance().GetSmallExplosionImage(); entity = new Entity(x, y, explosion->GetWidth(), explosion->GetHeight(), 0); ComponentRenderer * renderer = new ComponentRenderer(explosion, (rand() % 4)*10, 10, 30, false); entity->AddComponent(renderer); entityStore.Add(entity); return entity; }
Entity* CommonFactory::CreateSprite(std::string path) { Entity* sprite = new Entity(); RenderComponent* renderComponent = new RenderComponent(); sf::Texture* texture = new sf::Texture(); texture->loadFromFile(resourcePath() + path); texture->setSmooth(true); renderComponent->sprite = *new Sprite(); renderComponent->sprite.setTexture(*texture); sprite->AddComponent(renderComponent); return sprite; }
Entity * EntityFactory::createMissile(double damage, double x, double y, double rotation, double linearSpeed) { double trueX, trueY; Entity * entity; Image * missile = nullptr; missile = ResourceStore::Instance().GetMissileImage(); trueX = x + DegCos(rotation-90) * missile->GetWidth() / 2; x += x - trueX; trueY = y - DegSin(rotation-90) * missile->GetHeight() / 2; y += y - trueY; entity = new Entity(x, y, missile->GetWidth(), missile->GetHeight(), rotation); ComponentRenderer * renderer = new ComponentRenderer(missile,1,1,false); entity->AddComponent(renderer); ComponentLinearMovement * linearMovement = new ComponentLinearMovement(linearSpeed); entity->AddComponent(linearMovement); ComponentSmallExplosion * SmallExplosion = new ComponentSmallExplosion(this); entity->AddComponent(SmallExplosion); ComponentCircleCollision * collision = new ComponentCircleCollision(damage,true); entity->AddComponent(collision); entityStore.Add(entity); return entity; }
void VariantTuner::setTunableVariant(Variant& var, const Variant& step) { Entity* rootEntity = GetBaseApp()->GetEntityRoot(); VariantChangerComponent* varChanger = dynamic_cast<VariantChangerComponent*>(rootEntity->GetComponentByName("VariantChanger")); if (varChanger == NULL) { varChanger = new VariantChangerComponent; rootEntity->AddComponent(varChanger); } varChanger->SetChangeableVariant(&var); varChanger->GetVar("step")->Reset(); varChanger->GetVar("step")->Set(step); }
bool LandscapesController::HideEditorLandscape(EditorLandscape *hiddingLandscape) { hiddingLandscape->FlushChanges(); EditorLandscape *parentLandscape = hiddingLandscape->GetParentLandscape(); Landscape *nestedLandscape = hiddingLandscape->GetNestedLandscape(); if(parentLandscape) { Heightmap *hmap = SafeRetain(parentLandscape->GetHeightmap()); parentLandscape->SetNestedLandscape(nestedLandscape); parentLandscape->SetHeightmap(hmap); SafeRelease(hmap); currentLandscape = parentLandscape; } else { EditorLandscape *editorLandscape = dynamic_cast<EditorLandscape *>(nestedLandscape); if(editorLandscape) { editorLandscape->SetParentLandscape(NULL); } Entity* lanscapeNode = EditorScene::GetLandscapeNode(scene); lanscapeNode->RemoveComponent(Component::RENDER_COMPONENT); lanscapeNode->AddComponent(new RenderComponent(nestedLandscape)); if(NeedToKillRenderer(nestedLandscape)) { SafeRelease(renderedHeightmap); SafeRelease(landscapeRenderer); } currentLandscape = nestedLandscape; } SafeRelease(hiddingLandscape); return true; }
Entity * EntityFactory::CreatePlayerOne(World * world) { Entity * entity; Image * ship = nullptr; Document document; String string; const char * json; float life, energy, eneryRegeneration; /*Retive spaceshipdata*/ switch (LevelManager::Instance().GetPLayerOneSpaceShip()) { case LevelManager::AVATAR: string = String::Read("../data/spaceships/avatar/data.cfg"); json = string.ToCString(); document.Parse(json); ship = ResourceStore::Instance().GetAvatarImage(); break; case LevelManager::DREADNOUGH: string = String::Read("../data/spaceships/dreadnought/data.cfg"); json = string.ToCString(); document.Parse(json); ship = ResourceStore::Instance().GetDreadnoughtImage(); break; } entity = new Entity(0, 0, ship->GetWidth(), ship->GetHeight(), 0);//create entity /*Set spaceship control*/ switch (LevelManager::Instance().GetPLayerOneType()) { float linearVel, angularVel; case LevelManager::HUMAN: { string = String::Read("../data/config/keybindings.cfg"); json = string.ToCString(); Document keybindings; keybindings.Parse(json); assert(keybindings.HasMember("Player1")); assert(keybindings["Player1"].IsObject()); assert(document.HasMember("LinearVelocity")); assert(document["LinearVelocity"].IsNumber()); assert(document["LinearVelocity"].IsFloat()); linearVel = document["LinearVelocity"].GetFloat(); assert(document.HasMember("AngularVelocity")); assert(document["AngularVelocity"].IsNumber()); assert(document["AngularVelocity"].IsFloat()); angularVel = document["AngularVelocity"].GetFloat(); ComponentPlayerController * playerController = new ComponentPlayerController(linearVel, angularVel); playerController->BinKeys( static_cast<inputs>(keybindings["Player1"]["UP"].GetInt()), static_cast<inputs>(keybindings["Player1"]["DOWN"].GetInt()), static_cast<inputs>(keybindings["Player1"]["RLEFT"].GetInt()), static_cast<inputs>(keybindings["Player1"]["RRIGHT"].GetInt()), static_cast<inputs>(keybindings["Player1"]["FIREMAIN"].GetInt()), static_cast<inputs>(keybindings["Player1"]["FIRESECONDARY"].GetInt()) ); entity->AddComponent(playerController); } break; case LevelManager::EASY: ComponentBehaviour *EasyIA= new ComponentBehaviour(new DroneBehaviouralTree(entity)); break; } life = document["Life"].GetFloat(); energy = document["Energy"].GetFloat(); eneryRegeneration = document["EnergyRegeneration"].GetFloat(); ComponentStats * stats = new ComponentStats(life, energy, eneryRegeneration); entity->AddComponent(stats); ComponentRenderer * renderer = new ComponentRenderer(ship); entity->AddComponent(renderer); ComponentCircleCollision * collider = new ComponentCircleCollision(1000, false); entity->AddComponent(collider); ComponentShipExplosion * explosion = new ComponentShipExplosion(this); entity->AddComponent(explosion); assert(document.HasMember("PrimaryWeapon")); assert(document["PrimaryWeapon"].IsObject()); assert(document["PrimaryWeapon"].HasMember("Type")); assert(document["PrimaryWeapon"]["Type"].IsString()); string = document["PrimaryWeapon"]["Type"].GetString(); if(string==String("LASER")){ ComponentLaserWeapon * weapon = new ComponentLaserWeapon(world,WT_MAIN, document["PrimaryWeapon"]["Cooldown"].GetDouble(), document["PrimaryWeapon"]["Damage"].GetDouble(), document["PrimaryWeapon"]["EnergyConsumption"].GetDouble(), document["PrimaryWeapon"]["Range"].GetDouble()); entity->AddComponent(weapon); }else if (string == String("MISSILE")) { ComponentBalisticWeapon * weapon = new ComponentBalisticWeapon(world, this,WT_MAIN, document["PrimaryWeapon"]["Cooldown"].GetDouble(), document["PrimaryWeapon"]["Damage"].GetDouble(), document["PrimaryWeapon"]["EnergyConsumption"].GetDouble(), document["PrimaryWeapon"]["Speed"].GetDouble()); entity->AddComponent(weapon); } entityStore.Add(entity); return entity; }
void GameProcess::VOnInit(void) { //pSkillInterface = new SkillInterface(); DialogueInterface* pDialogue = new DialogueInterface( NULL, "DialogueInterface.xml", "Dialogue.xml" ); pDialogue->SetName( "Dialogue" ); BaseApplication::Get()->AttachProcess( pDialogue ); pDialogue->Release(); Entity* pEntity = Game::CreateEntity(); ThirdPersonCamera* pCamera = new ThirdPersonCamera(); pCamera->SetDistanceMax( 50.0f ); m_pCamera = pCamera; pEntity->AddComponent( pCamera ); pCamera->SetClearColor( ColorF::BLACK ); pCamera->Release(); pCamera->SetPosition( Vector4( 2000.0f, 30.0f, 2000.0f ) ); pCamera->SetDirection( Vector4( 0.0f, 0.0f, 1.0f ) ); pCamera->Start(); pEntity = Game::CreateEntity(); int iWorldSize = 512; m_IslandData.Generate( iWorldSize, iWorldSize ); HeightmapComponent* pComponent = new HeightmapComponent( iWorldSize, iWorldSize, m_IslandData ); m_pHeightMapEntity = pComponent; //pComponent->SetTexture( "sketch.png" ); m_IslandData.GenerateBiomes(); ColorF* pColors = new ColorF[ iWorldSize * iWorldSize ]; for ( int i = 0; i < iWorldSize; ++i ) { for ( int j = 0; j < iWorldSize; ++j ) { ColorF color; IslandData::Biome eBiome = m_IslandData.GetBiome( i, j ); if ( eBiome == IslandData::SeaWater ) { color = Color::BLUE; } else if ( eBiome == IslandData::FreshWater ) { color = Color( 0, 191, 255 ); } else if ( eBiome == IslandData::Grassland ) { color = Color( 195, 211, 170, 255 ); } else if ( eBiome == IslandData::Snow ) { color = Color::WHITE; } else if ( eBiome == IslandData::Bare ) { color = Color( 200, 200, 200, 255 ); } else if ( eBiome == IslandData::Scorched ) { color = Color::GREY; } else if ( eBiome == IslandData::Tundra ) { color = Color( 220, 220, 186, 255 ); } else if ( eBiome == IslandData::Taiga ) { color = Color( 203, 211, 186, 255 ); } else if ( eBiome == IslandData::Shrubland ) { color = Color( 195, 203, 186, 255 ); } else if ( eBiome == IslandData::TemperateDesert ) { color = Color( 227, 231, 201, 255 ); } else if ( eBiome == IslandData::TemperateRainForest ) { color = Color( 163, 195, 167, 255 ); } else if ( eBiome == IslandData::TemperateDecidousForest ) { color = Color( 180, 200, 168, 255 ); } else if ( eBiome == IslandData::TropicalRainForest ) { color = Color( 155, 186, 168, 255 ); } else if ( eBiome == IslandData::TropicalSeasonalForest ) { color = Color( 168, 203, 163, 255 ); } else if ( eBiome == IslandData::SubtropicalDesert ) { color = Color( 232, 220, 198, 255 ); } else if ( eBiome == IslandData::Unassigned ) { throw "Whoops"; } else { throw "Unhandled biome"; } pColors[ j * iWorldSize + i ] = color; } } pComponent->GenerateHeightMap( iWorldSize, iWorldSize, m_IslandData, pColors ); delete [] pColors; pEntity->AddComponent( pComponent ); pComponent->Release(); pComponent->Start(); // Generate blend map for splatting unsigned int* pBlendMap = new unsigned int[ iWorldSize * iWorldSize ]; for ( int i = 0; i < iWorldSize; ++i ) { for ( int j = 0; j < iWorldSize; ++j ) { Color color; IslandData::Biome eBiome = m_IslandData.GetBiome( i, j ); if ( eBiome == IslandData::SeaWater ) { color = Color::BLUE; color.Alpha = 0; } else if ( eBiome == IslandData::FreshWater ) { color = Color::BLUE; color.Alpha = 0; } else if ( eBiome == IslandData::Grassland ) { color = Color::GREEN; color.Alpha = 0; } else if ( eBiome == IslandData::Snow ) { color = Color( 0, 0, 0, 255 ); } else if ( eBiome == IslandData::Bare ) { color = Color( 0, 0, 0 ,0 ); } else if ( eBiome == IslandData::Scorched ) { color = Color( 0, 0, 0 ,0 ); } else if ( eBiome == IslandData::Tundra ) { color = Color( 0, 0, 0 ,255 ); } else if ( eBiome == IslandData::Taiga ) { color = Color::BLACK; color.Alpha = 0; } else if ( eBiome == IslandData::Shrubland ) { color = Color::BLACK; color.Alpha = 0; } else if ( eBiome == IslandData::TemperateDesert ) { color = Color::RED; color.Alpha = 0; } else if ( eBiome == IslandData::TemperateRainForest ) { color = Color::GREEN; color.Alpha = 0; } else if ( eBiome == IslandData::TemperateDecidousForest ) { color = Color::GREEN; color.Alpha = 0; } else if ( eBiome == IslandData::TropicalRainForest ) { color = Color::GREEN; color.Alpha = 0; } else if ( eBiome == IslandData::TropicalSeasonalForest ) { color = Color::GREEN; color.Alpha = 0; } else if ( eBiome == IslandData::SubtropicalDesert ) { color = Color::RED; color.Alpha = 0; } else if ( eBiome == IslandData::Unassigned ) { throw "Whoops"; } else { throw "Unhandled biome"; } pBlendMap[ j * iWorldSize + i ] = color.RGBA; } } ITexture* pBlendMapTexture = IRenderer::CreateTexture(); pBlendMapTexture->VCreate( iWorldSize, iWorldSize, 4, (char*)pBlendMap ); delete [] pBlendMap; StructuredMaterial<Vector4>* pSplattingMaterial = new StructuredMaterial<Vector4>(); pSplattingMaterial->GetBuffer()->VAddProperty( "u_vLightDirection", BufferProperty::BP_VECTOR3 ); IShaderProgram* pProgram = IRenderer::CreateShaderProgram(); IVertexShader* pVertexShader = IRenderer::CreateVertexShader(); IPixelShader* pPixelShader = IRenderer::CreatePixelShader(); BinaryResource* pVertexResource = AssetManager::Get().GetAsset< BinaryResource >( "Terrain.vert" ); BinaryResource* pPixelResource = AssetManager::Get().GetAsset< BinaryResource >( "Terrain.frag" ); if ( pVertexShader->VCreateFromMemory( pVertexResource->Buffer(), pVertexResource->Size() ) == false ) throw "Error"; if ( pPixelShader->VCreateFromMemory( pPixelResource->Buffer(), pPixelResource->Size() ) == false ) throw "error"; pProgram->VSetPixelShader( pPixelShader ); pProgram->VSetVertexShader( pVertexShader ); pVertexShader->VAddAttribute( "u_vPosition", Position_VertexData ); pVertexShader->VAddAttribute( "u_vTexCoords", UV_VertexData ); pVertexShader->VAddAttribute( "u_vNormal", Normal_VertexData ); pVertexShader->VAddAttribute( "u_vColor", Color_VertexData ); pProgram->VLink(); pSplattingMaterial->SetShaderProgram( pProgram ); pSplattingMaterial->AddTextureRegister( "Desert" ); pSplattingMaterial->AddTextureRegister( "Grass" ); pSplattingMaterial->AddTextureRegister( "Water" ); pSplattingMaterial->AddTextureRegister( "Snow" ); pSplattingMaterial->AddTextureRegister( "Rock" ); pSplattingMaterial->AddTextureRegister( "BlendMap" ); ITexture* pTexture = AssetManager::Get().GetAsset<ITexture>( "Desert.png" ); pSplattingMaterial->SetTexture( 0, pTexture ); pTexture = AssetManager::Get().GetAsset<ITexture>( "Grass.png" ); pSplattingMaterial->SetTexture( 1, pTexture ); pTexture = AssetManager::Get().GetAsset<ITexture>( "Water.png" ); pSplattingMaterial->SetTexture( 2, pTexture ); pTexture = AssetManager::Get().GetAsset<ITexture>( "Snow.png" ); pSplattingMaterial->SetTexture( 3, pTexture ); pTexture = AssetManager::Get().GetAsset<ITexture>( "Rock.png" ); pSplattingMaterial->SetTexture( 4, pTexture ); pSplattingMaterial->SetTexture( 5, pBlendMapTexture ); m_pHeightMapEntity->SetMaterial( pSplattingMaterial ); pSplattingMaterial->Release(); pProgram->Release(); pPixelShader->Release(); pVertexShader->Release(); pBlendMapTexture->Release(); /*pEntity = Game::CreateEntity(); SkyBox* pSkyBox = new SkyBox(); pEntity->AddComponent( pSkyBox ); pSkyBox->Start(); pSkyBox->Release();*/ Matrix mat; MeshComponent* pMeshComponent = NULL; Mesh* pMesh = NULL; pMesh = Mesh::CreateBox(); mat.BuildScale( Vector4::ONE * 2.0f ); mat.SetPosition( Vector4( 1900.0f, 0.0f, 1900.0f ) ); mat.SetPosition( Vector4( 0.0f, 0.0f, 0.0f ) ); pEntity = Game::CreateEntity( mat ); pMeshComponent = new MeshComponent(); // pEntity->AddComponent( pMeshComponent ); pMeshComponent->SetMesh( pMesh ); pMesh->Release(); pMeshComponent->Start(); pMeshComponent->Release(); m_pSteering = new SteeringComponent(); pEntity->AddComponent( m_pSteering ); m_pSteering->SetSpeed( 15.0f ); m_pSteering->SetHeightOffset( 1.0f ); m_pSteering->Start(); m_pSteering->Release(); Character* pCharacter = new Character(); XmlResource* pResource = AssetManager::Get().GetAsset<XmlResource>( "CombatAbilities.xml" ); if ( pResource ) { auto pElement = pResource->GetRoot()->FirstChildElement(); while ( pElement ) { CombatAbility ability; ability.VFromXML( pElement ); pCharacter->AddAbility( ability ); pElement = pElement->NextSiblingElement( "Ability" ); } } pEntity->AddComponent( pCharacter ); pCharacter->Release(); GameHUDComponent* pGameHud = new GameHUDComponent(); pEntity->AddComponent( pGameHud ); pGameHud->Start(); pGameHud->Release(); m_pMrBitey = pEntity; pEntity = Game::CreateEntity(); m_pAtmosphere = new AtmosphericScattering(); pEntity->AddComponent( m_pAtmosphere ); m_pAtmosphere->Start(); m_pAtmosphere->Release(); Transform waterPosition; waterPosition.SetPosition( 0.0f, 5.0f, 0.0f ); pEntity = Game::CreateEntity( waterPosition ); WaterPlane* pWater = new WaterPlane(); pEntity->AddComponent( pWater ); pWater->Start(); pWater->Release(); }
bool GameProcess::VOnMouseButtonUp( const int iButtonIndex, const Vector3& vPosition ) { Vector3 vResolution( IRenderer::Get()->VGetScreenWidth(), IRenderer::Get()->VGetScreenHeight(), 1.0f ); Vector3 vRayPos, vRayDir; Matrix::Unproject( vPosition, vResolution, m_pCamera->GetProjection(), m_pCamera->GetView(), vRayPos, vRayDir ); float fDistance = 0.0f; if ( iButtonIndex == 0 ) { if ( m_pHeightMapEntity->VPick( vRayPos, vRayDir, &fDistance ) ) { if ( fDistance < 0.0f ) fDistance = -fDistance; Transform& transform = m_pMrBitey->GetTransform(); if ( InputManager::Get()->GetKeyState( KEY_T ) == HELD_KEYSTATE ) { transform.SetPosition( vRayPos + vRayDir * fDistance + Vector3::UP ); } else { Vector4 vTarget = vRayPos + vRayDir * fDistance + Vector3( 0.0f, 1.0f, 0.0f ); m_pSteering->SetTargetPosition( vTarget ); } return false; } } else if ( iButtonIndex == 1 ) { SceneNode* pSceneNode = SceneManager::Get()->VPickAndReturnClosest( vRayPos, vRayDir, &fDistance ); if ( pSceneNode ) { Entity* pEntity = pSceneNode->VGetEntity(); if ( pEntity ) { if ( pEntity != m_pHeightMapEntity->GetOwner() ) { Transform& matTransform = m_pMrBitey->GetTransform(); Vector4 vPosition( pEntity->GetTransform().GetPosition() - Vector4( Vector4( 0.0f, 0.0f, -20.0f ) ) ); m_pHeightMapEntity->GetHeight( vPosition.x, vPosition.z, vPosition.y ); matTransform.SetPosition( vPosition ); InteractableComponent* pInteractable = (InteractableComponent*)pEntity->GetComponent( InteractableComponent::g_hID ); if ( pInteractable ) { pInteractable->VOnInteract( m_pMrBitey ); } Combat::InitiateCombat( m_pCamera, m_pMrBitey, pEntity ); } else { Matrix matTransform; matTransform.BuildScale( Vector4::ONE * 2.0f ); vRayDir.Normalize(); matTransform.SetPosition( vRayPos + vRayDir * fDistance + Vector4( 0.0f, 1.0f, 0.0f ) ); Entity* pEntity = Game::CreateEntity( matTransform ); MeshComponent* pMeshComponent = new MeshComponent(); pEntity->AddComponent( pMeshComponent ); Mesh* pMesh = Mesh::CreateBox(); pMeshComponent->SetMesh( pMesh ); pMesh->Release(); pMeshComponent->Start(); pMeshComponent->Release(); TalkerComponent* pTalker = new TalkerComponent( "Dialogue.xml" ); pEntity->AddComponent( pTalker ); pTalker->Start(); pTalker->Release(); StateMachineComponent* pStateMachine = new StateMachineComponent(); pEntity->AddComponent( pStateMachine ); //pStateMachine->Start(); pStateMachine->Release(); Character* pCharacter = new Character(); XmlResource* pResource = AssetManager::Get().GetAsset<XmlResource>( "CombatAbilities.xml" ); if ( pResource ) { auto pElement = pResource->GetRoot()->FirstChildElement(); while ( pElement ) { CombatAbility ability; ability.VFromXML( pElement ); pCharacter->AddAbility( ability ); pElement = pElement->NextSiblingElement( "Ability" ); } } pEntity->AddComponent( pCharacter ); pCharacter->Release(); /*ParticleEmitter* pSystem = new ParticleEmitter(); pEntity->AddComponent( pSystem ); pSystem->Start(); pSystem->SetTexture( "explosion.png" ); EmitterProcessor* pPositionProcessor = new SphericalSpawnPositionProcessor( 0.5f ); pSystem->AddProcessor( pPositionProcessor ); pPositionProcessor->Release(); pPositionProcessor = new SpawnPositionProcessor( Vector3( 0.0f, 2.0f, 0.0f ) ); pSystem->AddProcessor( pPositionProcessor ); pPositionProcessor->Release(); //pPositionProcessor = new VelocityOverAgeProcessor( new CurveModifier( Vector3( 0.0f, 2.0f, 0.0f ) * 5.0f, Vector3( 1.0f, 2.0f, 1.0f ) * 5.0f, Vector3( -1.0f, 2.0f, -1.0f ) * 5.0f, Vector3( 1.0f, 2.0f, 1.0f ) * 5.0f ) ); pPositionProcessor = new VelocityOverAgeProcessor( new ConstantEmitterModifier( Vector3::UP * 5.0f ) ); pSystem->AddProcessor( pPositionProcessor ); pPositionProcessor->Release(); pPositionProcessor = new RadialVelocityProcessor( Vector3( 1.0f, 1.0f, 1.0f ) * 20.0f ); pSystem->AddProcessor( pPositionProcessor ); pPositionProcessor->Release(); pPositionProcessor = new ColorOverAgeProcessor( new CurveModifier( Vector3::ZERO, Vector3( 1.0f, 0.0f, 0.0f ), Vector3( 0.0f, 1.0f, 0.0f ), Vector3( 0.0f, 0.0f, 1.0f ) ) ); pSystem->AddProcessor( pPositionProcessor ); pPositionProcessor->Release(); pSystem->Release();*/ } } } } return false; }
void App::Update() { //game can think here. The baseApp::Update() will run Update() on all entities, if any are added. The only one //we use in this example is one that is watching for the Back (android) or Escape key to quit that we setup earlier. BaseApp::Update(); if (!m_bDidPostInit) { //stuff I want loaded during the first "Update" m_bDidPostInit = true; //for android, so the back key (or escape on windows) will quit out of the game Entity *pEnt = GetEntityRoot()->AddEntity(new Entity); EntityComponent *pComp = pEnt->AddComponent(new CustomInputComponent); //tell the component which key has to be hit for it to be activated pComp->GetVar("keycode")->Set(uint32(VIRTUAL_KEY_BACK)); //attach our function so it is called when the back key is hit pComp->GetFunction("OnActivated")->sig_function.connect(1, boost::bind(&App::OnExitApp, this, _1)); //nothing will happen unless we give it input focus pEnt->AddComponent(new FocusInputComponent); //ACCELTEST: To test the accelerometer uncomment below: (will print values to the debug output) //SetAccelerometerUpdateHz(25); //default is 0, disabled //GetBaseApp()->m_sig_accel.connect(1, boost::bind(&App::OnAccel, this, _1)); //TRACKBALL/ARCADETEST: Uncomment below to see log messages on trackball/key movement input pComp = pEnt->AddComponent(new ArcadeInputComponent); GetBaseApp()->m_sig_arcade_input.connect(1, boost::bind(&App::OnArcadeInput, this, _1)); //these arrow keys will be triggered by the keyboard, if applicable AddKeyBinding(pComp, "Left", VIRTUAL_KEY_DIR_LEFT, VIRTUAL_KEY_DIR_LEFT); AddKeyBinding(pComp, "Right", VIRTUAL_KEY_DIR_RIGHT, VIRTUAL_KEY_DIR_RIGHT); AddKeyBinding(pComp, "Up", VIRTUAL_KEY_DIR_UP, VIRTUAL_KEY_DIR_UP); AddKeyBinding(pComp, "Down", VIRTUAL_KEY_DIR_DOWN, VIRTUAL_KEY_DIR_DOWN); AddKeyBinding(pComp, "Shift", VIRTUAL_KEY_CONTROL, VIRTUAL_KEY_CONTROL); AddKeyBinding(pComp, "Fire", VIRTUAL_KEY_CONTROL, VIRTUAL_KEY_GAME_FIRE); //INPUT TEST - wire up input to some functions to manually handle. AppInput will use LogMsg to //send them to the log. (Each device has a way to view a debug log in real-time) GetBaseApp()->m_sig_input.connect(&AppInput); /* //file handling test, if TextScanner.h is included at the top.. TextScanner t; t.m_lines.push_back("Testing 123"); t.m_lines.push_back("F**k ya'll!"); t.m_lines.push_back("Whoopsopsop!"); LogMsg("Saving file..."); t.SaveFile("temp.txt"); TextScanner b; b.LoadFile("temp.txt"); b.DumpToLog(); */ } //game is thinking. if (g_game->game_state_ == 1) //we update the objects { g_game->update(); } }
void Box2DSystem::__InitTestBodies() { // Define the ground body. b2BodyDef groundBodyDef; groundBodyDef.position.Set(0.0f, 5.0f); // Call the body factory which allocates memory for the ground body // from a pool and creates the ground box shape (also from a pool). // The body is also added to the world. b2Body* groundBody = m_world->CreateBody(&groundBodyDef); // Define the ground box shape. b2PolygonShape groundBox; // The extents are the half-widths of the box. groundBox.SetAsBox(40, 5); // Define the ground box shape. b2PolygonShape groundBox2; b2PolygonShape groundBox3; int count = 4; b2Vec2 vertices[4]; vertices[0].Set(20, -30); vertices[1].Set(30, -30); vertices[2].Set(30, 0); vertices[3].Set(20, 0); // The extents are the half-widths of the box. groundBox2.Set(vertices, count); vertices[0].Set(-20, -30); vertices[1].Set(-10, -30); vertices[2].Set(-10, 0); vertices[3].Set(-20, 0); groundBox3.Set(vertices, count); // Add the ground fixture to the ground body. groundBody->CreateFixture(&groundBox, 0.0f); groundBody->CreateFixture(&groundBox2, 0.0f); groundBody->CreateFixture(&groundBox3, 0.0f); Entity* groundEntity = GetOwner()->CreateEntity(); Box2DComponent* groundComponent = Box2DComponent::Pool.CreateComponent(); groundEntity->AddComponent(groundComponent); groundComponent->m_body = groundBody; // Player entity b2BodyDef playerBodyDef; playerBodyDef.type = b2_dynamicBody; playerBodyDef.position.Set(10, 0); b2Body* playerBody = m_world->CreateBody(&playerBodyDef); playerBody->SetBullet(true); b2PolygonShape playerBodyShape; playerBodyShape.SetAsBox(2, 4); playerBody->CreateFixture(&playerBodyShape, 0.0f); m_playerEntity = GetOwner()->CreateEntity(); Box2DComponent* playerCmp = Box2DComponent::Pool.CreateComponent(); m_playerEntity->AddComponent(playerCmp); playerCmp->m_body = playerBody; }