Exemplo n.º 1
0
j1SceneManager::j1SceneManager() : j1Module()
{
	intro = new snIntro();
	outdoor1 = new snOutdoor1();

	AddScene(intro);
	AddScene(outdoor1);
}
Exemplo n.º 2
0
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);
    //************************************************************
}
Exemplo n.º 3
0
    void OnInitialize() {
        mStep = 0;

        dt::ResourceManager::Get()->AddResourceLocation("gui","FileSystem", true);

        // need to create a camera so we have a window
        dt::Scene* scene = AddScene(new dt::Scene("testscene"));
        scene->AddChildNode(new dt::Node("camnode"))->AddComponent<dt::CameraComponent>(new dt::CameraComponent("cam"));
    }
Exemplo n.º 4
0
    void OnInitialize() {
        dt::Scene* scene = AddScene(new dt::Scene("testscene"));

        OgreProcedural::Root::getInstance()->sceneManager = scene->GetSceneManager();

	dt::ResourceManager::Get()->AddResourceLocation("","FileSystem");
        Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

	// Test primitive generation
	OgreProcedural::PlaneGenerator().setNumSegX(20).setNumSegY(20).setSizeX(150).setSizeY(150).setUTile(5.0).setVTile(5.0).realizeMesh("planeMesh");
	putMeshShadow("planeMesh", Ogre::Vector3(0,5,-20), "PrimitivesTest/Pebbles");

	OgreProcedural::SphereGenerator().setRadius(2.f).setUTile(5.).setVTile(5.).realizeMesh("sphereMesh");
	putMeshShadow("sphereMesh", Ogre::Vector3(0,10,0), "PrimitivesTest/RedBrick");

	OgreProcedural::CylinderGenerator().setHeight(3.f).setRadius(1.f).setUTile(3.).realizeMesh("cylinderMesh");
	putMeshShadow("cylinderMesh", Ogre::Vector3(10,10,0), "PrimitivesTest/RedBrick");

	OgreProcedural::TorusGenerator().setRadius(3.f).setSectionRadius(1.f).setUTile(10.).setVTile(5.).realizeMesh("torusMesh");
	putMeshShadow("torusMesh", Ogre::Vector3(-10,10,0), "PrimitivesTest/RedBrick");

	OgreProcedural::ConeGenerator().setRadius(2.f).setHeight(3.f).setNumSegBase(36).setNumSegHeight(2).setUTile(3.).realizeMesh("coneMesh");
	putMeshShadow("coneMesh", Ogre::Vector3(0,10,-10), "PrimitivesTest/RedBrick");

	OgreProcedural::TubeGenerator().setHeight(3.f).setUTile(3.).realizeMesh("tubeMesh");
	putMeshShadow("tubeMesh", Ogre::Vector3(-10,10,-10), "PrimitivesTest/RedBrick");

	OgreProcedural::BoxGenerator().setSizeX(2.0).setSizeY(4.f).setSizeZ(6.f).realizeMesh("boxMesh");
	putMeshShadow("boxMesh", Ogre::Vector3(10,10,-10), "PrimitivesTest/RedBrick");

	OgreProcedural::CapsuleGenerator().setHeight(2.f).realizeMesh("capsuleMesh");
	putMeshShadow("capsuleMesh", Ogre::Vector3(0,10,10), "PrimitivesTest/RedBrick");

	OgreProcedural::TorusKnotGenerator().setRadius(2.f).setSectionRadius(.5f).setUTile(3.f).setNumSegCircle(64).setNumSegSection(16).realizeMesh("torusKnotMesh");
	putMeshShadow("torusKnotMesh", Ogre::Vector3(-10,10,10), "PrimitivesTest/RedBrick");

	OgreProcedural::IcoSphereGenerator().setRadius(2.).setNumIterations(3).setUTile(5.).setVTile(5.).realizeMesh("icoSphereMesh");
	putMeshShadow("icoSphereMesh", Ogre::Vector3(10,10,10), "PrimitivesTest/RedBrick");

	OgreProcedural::RoundedBoxGenerator().setSizeX(1.f).setSizeY(5.f).setSizeZ(5.f).setChamferSize(1.f).realizeMesh("roundedBoxMesh");
	putMeshShadow("roundedBoxMesh", Ogre::Vector3(20,10,10), "PrimitivesTest/RedBrick");		

        dt::Node* camnode = scene->AddChildNode(new dt::Node("camnode"));
        camnode->AddComponent(new dt::CameraComponent("cam"));
        camnode->SetPosition(Ogre::Vector3(-30, 20, 30));
        camnode->FindComponent<dt::CameraComponent>("cam")->LookAt(Ogre::Vector3(0, 0, 0));

        dt::Node* lightnode1 = scene->AddChildNode(new dt::Node("lightnode1"));
        lightnode1->AddComponent(new dt::LightComponent("light1"));
        lightnode1->SetPosition(Ogre::Vector3(0, 30, 0));

        dt::Node* lightnode2 = scene->AddChildNode(new dt::Node("lightnode2"));
        lightnode2->AddComponent(new dt::LightComponent("light2"));
        lightnode2->SetPosition(Ogre::Vector3(0, -10, 0));
    }
Exemplo n.º 5
0
void Main::OnInitialize() {
    dt::Scene* scene = AddScene(new dt::Scene("testscene"));

    OgreProcedural::Root::getInstance()->sceneManager = scene->GetSceneManager();

    dt::ResourceManager::Get()->AddResourceLocation("","FileSystem");
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    OgreProcedural::PlaneGenerator().setNumSegX(20).setNumSegY(20).setSizeX(150).setSizeY(150).setUTile(5.0).setVTile(5.0).realizeMesh("Ground");
    dt::Node* node = scene->AddChildNode(new dt::Node("node"));
    dt::MeshComponent* mesh = new dt::MeshComponent("Ground", "PrimitivesTest/Pebbles", "mesh");
    node->AddComponent(mesh);
    node->SetPosition(Ogre::Vector3(0,0,0));


    OgreProcedural::SphereGenerator().setRadius(1.f).setUTile(5.).setVTile(5.).realizeMesh("Sphere");
    OgreProcedural::BoxGenerator().setSizeX(2.0).setSizeY(2.f).setSizeZ(2.f).realizeMesh("Box");

    // Test primitive generation
    dt::Node* node1 = scene->AddChildNode(new dt::Node("node1"));
    dt::MeshComponent* mesh1 = new dt::MeshComponent("Sphere", "PrimitivesTest/RedBrick", "mesh");
    node1->AddComponent(mesh1);
    node1->SetPosition(Ogre::Vector3(-2,5,0));

    dt::Node* node2 = scene->AddChildNode(new dt::Node("node2"));
    dt::MeshComponent* mesh2 = new dt::MeshComponent("Box", "PrimitivesTest/RedBrick", "mesh");
    mesh2->SetCastShadows(false);
    node2->AddComponent(mesh2);
    node2->SetPosition(Ogre::Vector3(2,5,0));

    dt::Node* camnode = scene->AddChildNode(new dt::Node("camnode"));
    camnode->SetPosition(Ogre::Vector3(0, 5, 10));
    camnode->AddComponent(new dt::CameraComponent("cam"))->LookAt(Ogre::Vector3(0, 2, 0));

    dt::Node* lightnode1 = scene->AddChildNode(new dt::Node("lightnode1"));
    dt::LightComponent* light = lightnode1->AddComponent(new dt::LightComponent("light1"));
    light->SetColor(Ogre::ColourValue::White);
    Ogre::Light* ogl = light->GetOgreLight();
    ogl->setType(Ogre::Light::LT_SPOTLIGHT);
    ogl->setSpotlightInnerAngle(Ogre::Degree(30));
    ogl->setSpotlightOuterAngle(Ogre::Degree(40));
    lightnode1->SetPosition(Ogre::Vector3(0, 20, 0));
    lightnode1->SetDirection(Ogre::Vector3::NEGATIVE_UNIT_Y);

    dt::Node* lightnode2 = scene->AddChildNode(new dt::Node("lightnode2"));
    dt::LightComponent* light2 = lightnode2->AddComponent(new dt::LightComponent("light2"));
    light2->SetColor(Ogre::ColourValue::White);
    Ogre::Light* ogl2 = light->GetOgreLight();
    ogl2->setType(Ogre::Light::LT_SPOTLIGHT);
    ogl2->setSpotlightInnerAngle(Ogre::Degree(30));
    ogl2->setSpotlightOuterAngle(Ogre::Degree(40));
    lightnode2->SetPosition(Ogre::Vector3(5, 20, 0));
    lightnode2->LookAt(Ogre::Vector3(-2,5,0));
}
Exemplo n.º 6
0
    void OnInitialize() {
        dt::Scene* scene = AddScene(new dt::Scene("testscene"));

        dt::ResourceManager::Get()->AddResourceLocation("sinbad.zip","Zip", true);
        dt::ResourceManager::Get()->AddResourceLocation("gui","FileSystem", true);
        Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

        dt::Node* camnode = scene->AddChildNode(new dt::Node("camnode"));
        dt::CameraComponent* cam = camnode->AddComponent(new dt::CameraComponent("cam"));
        camnode->SetPosition(Ogre::Vector3(0, 5, 10));
        cam->LookAt(Ogre::Vector3(0, 0, 0));

        dt::Node* meshnode = scene->AddChildNode(new dt::Node("meshnode"));
        dt::MeshComponent* mesh = new dt::MeshComponent("Sinbad.mesh");
        meshnode->AddComponent(mesh);
        mesh->SetAnimation("Dance");
        mesh->SetLoopAnimation(true);
        mesh->PlayAnimation();

        // GUI
        dt::Node* w1 = scene->AddChildNode(new dt::Node("w1"));
        dt::GuiWidgetComponent* b1 = w1->AddComponent(new dt::GuiWidgetComponent("Button", "Button", "b1"));
        b1->GetWidget<MyGUI::Button>()->setCaption("Campaign");
        b1->GetWidget<MyGUI::Button>()->eventMouseButtonClick += MyGUI::newDelegate(this, &Main::Click);
        w1->SetPosition(Ogre::Vector3(0.4, 0.15, 0.0));
        w1->SetScale(Ogre::Vector3(0.2, 0.1, 0.0));

        dt::Node* w2 = scene->AddChildNode(new dt::Node("w2"));
        dt::GuiWidgetComponent* b2 = w2->AddComponent(new dt::GuiWidgetComponent("Button", "Button", "b2"));
        b2->GetWidget<MyGUI::Button>()->setCaption("Tutorial");
        b2->GetWidget<MyGUI::Button>()->eventMouseButtonClick += MyGUI::newDelegate(this, &Main::Click);
        w2->SetPosition(Ogre::Vector3(0.4, 0.35, 0.0));
        w2->SetScale(Ogre::Vector3(0.2, 0.1, 0.0));

        dt::Node* w3 = scene->AddChildNode(new dt::Node("w3"));
        dt::GuiWidgetComponent* b3 = w3->AddComponent(new dt::GuiWidgetComponent("Button", "Button", "b3"));
        b3->GetWidget<MyGUI::Button>()->setCaption("Options");
        b3->GetWidget<MyGUI::Button>()->eventMouseButtonClick += MyGUI::newDelegate(this, &Main::Click);
        w3->SetPosition(Ogre::Vector3(0.4, 0.55, 0.0));
        w3->SetScale(Ogre::Vector3(0.2, 0.1, 0.0));

        dt::Node* w4 = scene->AddChildNode(new dt::Node("w4"));
        dt::GuiWidgetComponent* b4 = w4->AddComponent(new dt::GuiWidgetComponent("Button", "Button", "b4"));
        b4->GetWidget<MyGUI::Button>()->setCaption("Exit");
        b4->GetWidget<MyGUI::Button>()->eventMouseButtonClick += MyGUI::newDelegate(this, &Main::Click);
        w4->SetPosition(Ogre::Vector3(0.4, 0.75, 0.0));
        w4->SetScale(Ogre::Vector3(0.2, 0.1, 0.0));

    }
Exemplo n.º 7
0
void OBSBasic::on_tabAddSceneBtn_clicked()
{
	QString format{ QTStr("Basic.Main.DefaultSceneName.Text") };

	QString sceneName = format.arg(m_curNewSceneNameIndex++);

	{
		std::string name = QT_TO_UTF8(sceneName);
		obs_scene_t *scene = obs_scene_create(name.c_str());

		obs_source_t *source = obs_scene_get_source(scene);
		AddScene(source);
		SetCurrentScene(source);
		obs_scene_release(scene);
	}
}
Exemplo n.º 8
0
void Main::OnInitialize() {
    dt::Scene* scene = AddScene(new dt::Scene("testscene"));

    dt::ResourceManager::Get()->AddResourceLocation("sinbad.zip","Zip", true);
    dt::ResourceManager::Get()->AddResourceLocation("gui","FileSystem", true);
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    dt::Node* camnode = scene->AddChildNode(new dt::Node("camnode"));
    camnode->SetPosition(Ogre::Vector3(0, 5, 10));
    camnode->AddComponent(new dt::CameraComponent("cam"))->LookAt(Ogre::Vector3(0, 0, 0));;

    dt::Node* meshnode = scene->AddChildNode(new dt::Node("meshnode"));
    dt::MeshComponent* mesh = new dt::MeshComponent("Sinbad.mesh");
    meshnode->AddComponent(mesh);
    mesh->SetAnimation("Dance");
    mesh->SetLoopAnimation(true);
    mesh->PlayAnimation();

    // GUI
    dt::GuiRootWindow& win = dt::GuiManager::Get()->GetRootWindow();

    dt::GuiButton* button1 = win.CreateChild<dt::GuiButton>("b1");
    button1->SetCaption("Campaign");
    button1->SetPosition(10, 10);
    button1->SetSize(200, 30);
    dynamic_cast<MyGUI::Button*>(button1->GetMyGUIWidget())->eventMouseButtonClick += MyGUI::newDelegate(this, &Main::Click);

    dt::GuiButton* button2 = win.CreateChild<dt::GuiButton>("b2");
    button2->SetCaption("Tutorial");
    button2->SetPosition(10, 50);
    button2->SetSize(200, 30);
    dynamic_cast<MyGUI::Button*>(button2->GetMyGUIWidget())->eventMouseButtonClick += MyGUI::newDelegate(this, &Main::Click);

    dt::GuiButton* button3 = win.CreateChild<dt::GuiButton>("b3");
    button3->SetCaption("Options");
    button3->SetPosition(10, 90);
    button3->SetSize(200, 30);
    dynamic_cast<MyGUI::Button*>(button3->GetMyGUIWidget())->eventMouseButtonClick += MyGUI::newDelegate(this, &Main::Click);

    dt::GuiButton* button4 = win.CreateChild<dt::GuiButton>("b4");
    button4->SetCaption("Exit");
    button4->SetPosition(10, 130);
    button4->SetSize(200, 30);
    dynamic_cast<MyGUI::Button*>(button4->GetMyGUIWidget())->eventMouseButtonClick += MyGUI::newDelegate(this, &Main::Click);
}
Exemplo n.º 9
0
    void OnInitialize() {
        dt::Scene* scene = AddScene(new dt::Scene("testscene"));

        dt::ResourceManager::Get()->AddResourceLocation("", "FileSystem", true);
        Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
        Ogre::FontManager::getSingleton().load("DejaVuSans", "General");

        dt::Node* camnode = scene->AddChildNode(new dt::Node("camnode"));
        dt::CameraComponent* cam = camnode->AddComponent(new dt::CameraComponent("cam"));
        camnode->SetPosition(Ogre::Vector3(0, 0, 10));
        cam->LookAt(Ogre::Vector3(0, 0, 0));

        dt::Node* node1 = scene->AddChildNode(new dt::Node("node1"));
        dt::TextComponent* text1 = node1->AddComponent(new dt::TextComponent("Hello World", "text1"));
        text1->SetBackgroundMaterial("TextOverlayBackground");
        text1->SetColor(Ogre::ColourValue::White);
        text1->SetFont("DejaVuSans");
        text1->SetFontSize(24);
        text1->SetPadding(Ogre::Vector2(20, 20));


        dt::Node* node2 = scene->AddChildNode(new dt::Node("node2"));
        node2->SetPosition(Ogre::Vector3(10, 10, 0));
        dt::TextComponent* text2 = node2->AddComponent(new dt::TextComponent("Hi there", "text2"));
        text2->SetColor(Ogre::ColourValue(0.5, 0.0, 1.0));
        text2->SetFont("DejaVuSans");
        text2->SetFontSize(32);

        // place test node behind the camera
        dt::Node* node3 = scene->AddChildNode(new dt::Node("node3"));
        node3->SetPosition(Ogre::Vector3(0, 0, 10));
        dt::TextComponent* text3 = node3->AddComponent(new dt::TextComponent("This text should never be visible", "text3"));
        text3->SetColor(Ogre::ColourValue::Red);
        text3->SetFont("DejaVuSans");
        text3->SetFontSize(32);
    }
Exemplo n.º 10
0
BOOL CNucAge::ProcessState(E_STATE eState, DWORD dwCurrTick)
{
    switch (eState.dwStateID) {
        case ES_STARTENGINE:
            // init resources
            AddResource("data\\cursor.dat", "cursor");
            AddResource("data\\sand.dat", "sand");
            AddResource("data\\actor.dat", "actor");
            AddResource("data\\gamegui.dat", "gamegui");

            // init scenes
            AddScene("scenes\\gamegui.scn", "gamegui", "gamegui");
            AddScene("scenes\\level.scn", "level", "sand");
            AddScene("scenes\\actor.scn", "actor", "actor");

            // create game objects
            g_pLevel = new CLevel();
            g_pRlPlayer = new CPlayer();
            g_pShPlayer = new CPlayer();
            g_pGtm = new CGameTime();
            g_pKeys = new CKeys();
            g_pMenu = new CGameMenu();
			g_pHelp = new CHelpDlg();
			g_pOptions = new COptionsDlg();

            // set players name
            strcpy(g_pRlPlayer->m_szName, "rlplayer");
            strcpy(g_pShPlayer->m_szName, "shplayer");
            g_pRlPlayer->m_bIsReal = TRUE;
            g_pShPlayer->m_bIsReal = FALSE;

            // add mouse support
            CreateMouse("cursor");

            // add listeners
            GetScene("level")->AddListener(g_pLevel, "main");
            GetScene("actor")->AddListener(g_pRlPlayer, g_pRlPlayer->m_szName);
            GetScene("actor")->AddListener(g_pShPlayer, g_pShPlayer->m_szName);
            GetScene("gamegui")->AddListener(g_pGtm, "time");
            GetScene("gamegui")->AddListener(g_pKeys, "keys");
			GetScene("gamegui")->AddListener(g_pMenu, "main");
			GetScene("gamegui")->AddListener(g_pHelp, "help");
			GetScene("gamegui")->AddListener(g_pOptions, "options");

            GetScene("level")->SetVisible(FALSE);
            GetScene("actor")->SetVisible(FALSE);

			// create fonts
			GetScene("gamegui")->GetStringManager()->CreateFont("fonts\\fonts.fnt", "greenfnt");
			GetScene("gamegui")->GetStringManager()->CreateFont("fonts\\fonts.fnt", "buttonfnt");
			GetScene("gamegui")->GetStringManager()->CreateFont("fonts\\fonts.fnt", "redfnt");
			GetScene("gamegui")->GetStringManager()->CreateFont("fonts\\fonts.fnt", "labelfnt");

			// init string table
			GetStringTable()->Init("strings.dat");
			GetStringTable()->SetLocale("en");

			// init audio
			GetAudio()->LoadGroup("sfx\\sound.sfx", "sound");

			// we start game from menu screen
			SetRTIntVar(NA_RT_GAME_STATE, GS_MENU);

			// create game variable object
			AddVars("game.ini", "config");

			// get world size value
			int iLevel, iWorldSize;
			GetVars("config")->GetInt(L_GROUP, "config", "worldsize", 0, &iWorldSize);
			if (iWorldSize <= 0 || iWorldSize > 25) iWorldSize = 25;
			SetRTIntVar(NA_RT_WORLD_SIZE, iWorldSize);

			// get current level value
			GetVars("config")->GetInt(L_GROUP, "config", "curlvl", 0, &iLevel);
			if (iLevel >= NA_NUM_WORLDS*iWorldSize) iLevel = NA_NUM_WORLDS*iWorldSize - 1;
			SetRTIntVar(NA_RT_CURR_LEVEL_NUMBER, iLevel);
			SetRTIntVar(NA_RT_MINI_LEVEL_NUMBER, iLevel);

			// get maximum achieved number of levels
			GetVars("config")->GetInt(L_GROUP, "config", "maxlvl", 0, &iLevel);
			if (iLevel >= NA_NUM_WORLDS*iWorldSize) iLevel = NA_NUM_WORLDS*iWorldSize - 1;
			SetRTIntVar(NA_RT_MAX_LEVEL_NUMBER, iLevel);

			// sync current level with max level
			if (GetRTIntVar(NA_RT_CURR_LEVEL_NUMBER) > iLevel)
			{
				SetRTIntVar(NA_RT_CURR_LEVEL_NUMBER, iLevel);
				SetRTIntVar(NA_RT_MINI_LEVEL_NUMBER, iLevel);
			}

			// update audio
			int iSndVol, iMusVol;
			BOOL fMute;
			GetVars("config")->GetInt(L_GROUP, "config", "mute", 0, &fMute);
			GetVars("config")->GetInt(L_GROUP, "config", "sndvol", 0, &iSndVol);
			GetVars("config")->GetInt(L_GROUP, "config", "musvol", 0, &iMusVol);

			GetAudio()->SetSFXVolume(iSndVol);
			GetAudio()->SetMusicVolume("backlogo", iMusVol);
			GetAudio()->SetMute(fMute);

			SetRTStringVar(NA_RT_BACK_MUSIC, "backlogo");
			GetAudio()->PlayMusic("backlogo");

			//turn on music check
			PostState(ES_ENGINE_CHECKMUSIC, 0, 0);
			break;
		case ES_ENGINE_CHECKMUSIC:
			//check if back music stop then play it again
			if (!GetAudio()->IsMusicPlay(GetRTStringVar(NA_RT_BACK_MUSIC))) {
				GetAudio()->StopMusic(GetRTStringVar(NA_RT_BACK_MUSIC));
				GetAudio()->PlayMusic(GetRTStringVar(NA_RT_BACK_MUSIC));
			}
			return FALSE;
	}
	return TRUE;
}
Exemplo n.º 11
0
void CShooterGame::Initialize()
{
    // Must call base class initializations first
    CGame::Initialize();

    #ifdef DEBUG
    cout << "CShooterGame::Initialize() called" << endl;
    #endif

    auto& renderer = CSingleton<CRenderer>::Instance();

    SDL_WM_SetCaption("Space Attackers!", "Space Attackers!");

    auto screen = renderer->GetScreen();
    m_iScreenW = screen->w;
    m_iScreenH = screen->h;

    // Create global mutex using Factory pattern
    {
        // Prepare Mutex singleton for access from multiple threads at the same time
        MutexFactory::Instance()->Initialize( RESOURCE::MUTEX_MAINAPP );
    }

    // Prepare rand() for multithreaded execution
    {
        CSingleton<CRandom>::Instance()->nextNumber();
    }

    // Load window icon using Factory pattern
    {
        ImageColorkeyFactory::Instance()->Get( RESOURCE::WINDOW_ICON )->Load( "Assets/Icon/icon.bmp" );
        ImageColorkeyFactory::Instance()->Get( RESOURCE::WINDOW_ICON )->SetColorKeyRGB( 0, 255, 255 );
        SDL_WM_SetIcon( ImageColorkeyFactory::Instance()->Get( RESOURCE::WINDOW_ICON )->GetSurface(), 0 );
    }

    // Load sprites using Factory pattern
    {
        ImageAlphaFactory::Instance()->Get( RESOURCE::PLAYER_PLANE )->Load( "Assets/Sprites/player_plane.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::PLAYER_PLANE_HIT )->Load( "Assets/Sprites/player_plane_hit.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::PLAYER_PLANE_SHADOW )->Load( "Assets/Sprites/player_plane_shadow_0.5x.png" );
        AnimationFactory::Instance()->Get( RESOURCE::PLAYER_PLANE )->LoadAnimation( "Assets/Sprites/player_plane.anim" );
        AnimationFactory::Instance()->Get( RESOURCE::PLAYER_PLANE_SHADOW )->LoadAnimation( "Assets/Sprites/player_plane_shadow_0.5x.anim" );

        ImageAlphaFactory::Instance()->Get( RESOURCE::PLAYER_PROJECTILE )->Load( "Assets/Sprites/plasma_up_yellow.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::PLAYER_PROJECTILE_GUIDED )->Load( "Assets/Sprites/plasma_ball_blue.png" );

        ImageAlphaFactory::Instance()->Get( RESOURCE::ENEMY_PROJECTILE_SLOW )->Load( "Assets/Sprites/plasma_ball_green.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::ENEMY_PROJECTILE_FAST )->Load( "Assets/Sprites/plasma_ball_red.png" );

        ImageAlphaFactory::Instance()->Get( RESOURCE::ENEMY_PLANE_GREEN )->Load( "Assets/Sprites/plane_green_down.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::ENEMY_PLANE_RED )->Load( "Assets/Sprites/plane_red_down.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::ENEMY_PLANE_GREEN_HIT )->Load( "Assets/Sprites/plane_green_down_hit.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::ENEMY_PLANE_RED_HIT )->Load( "Assets/Sprites/plane_red_down_hit.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::ENEMY_PLANE_SHADOW )->Load( "Assets/Sprites/plane_down_shadow_0.5x.png" );

        ImageAlphaFactory::Instance()->Get( RESOURCE::EXPLOSION )->Load( "Assets/Sprites/explosion.png" );
        AnimationFactory::Instance()->Get( RESOURCE::EXPLOSION )->LoadAnimation( "Assets/Sprites/explosion.anim" );
    }

    // Create interpolation sets for intro screen and level start message
    {
        auto& introOverTime = InterpolationSetFactory::Instance()->Get( RESOURCE::IS_INTRO_SHOW );
        introOverTime->AddValue( 0.0f, 0 );
        introOverTime->AddValue( 0.5f, 255, Math::Interpolation::easeOutCirc<float,float> );
        introOverTime->AddValue( 3.5f, 255 );
        introOverTime->AddValue( 5.0f, 0, Math::Interpolation::easeInCirc<float,float> );

        auto& levelStartOverTime = InterpolationSetFactory::Instance()->Get( RESOURCE::IS_LEVEL_START );
        levelStartOverTime->AddValue( 0.0f, m_iScreenH );
        levelStartOverTime->AddValue( 1.5f, m_iScreenH/2 - 32, Math::Interpolation::easeOutCirc<float,float> );
        levelStartOverTime->AddValue( 3.5f, m_iScreenH/2 - 32 );
        levelStartOverTime->AddValue( 5.0f, -64, Math::Interpolation::easeInCirc<float,float> );

    }

    // Load menu sprites using Factory pattern
    {
        ImageAlphaFactory::Instance()->Get( RESOURCE::MENU_TEXT )->Load( "Assets/Menu/texts.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::MENU_TEXT_SELECTED )->Load( "Assets/Menu/texts_selected.png" );
        AnimationFactory::Instance()->Get( RESOURCE::MENU_TEXT )->LoadAnimation( "Assets/Menu/texts.anim" );
    }

    // load backgrounds using Factory pattern
    {
        ImageAlphaFactory::Instance()->Get( RESOURCE::BACKGROUND_INTRO )->Load( "Assets/Backgrounds/intro_screen.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::BACKGROUND_TITLE )->Load( "Assets/Backgrounds/title_screen.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::BACKGROUND_DEATH )->Load( "Assets/Backgrounds/death.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::BACKGROUND_HELP1 )->Load( "Assets/Backgrounds/help1.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::BACKGROUND_HELP2 )->Load( "Assets/Backgrounds/help2.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::BACKGROUND_MOONSURFACE )->Load( "Assets/Backgrounds/moon.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::BACKGROUND_CLOUDS1 )->Load( "Assets/Backgrounds/clouds1_tr50.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::BACKGROUND_CLOUDS2 )->Load( "Assets/Backgrounds/clouds2_tr50.png" );
        ImageAlphaFactory::Instance()->Get( RESOURCE::BACKGROUND_MOONSURFACE )->SetAlpha(255);
        ImageAlphaFactory::Instance()->Get( RESOURCE::BACKGROUND_CLOUDS1 )->SetAlpha(0);
        ImageAlphaFactory::Instance()->Get( RESOURCE::BACKGROUND_CLOUDS2 )->SetAlpha(0);
        // Create layers and set the bitmaps
        ScrollingBackgroundFactory::Instance()->Get( RESOURCE::SCROLLING_MOONSURFACE )->Initialize(1);
        ScrollingBackgroundFactory::Instance()->Get( RESOURCE::SCROLLING_CLOUDS )->Initialize(2);

        auto& moonSurfaceLayer = ScrollingBackgroundFactory::Instance()->Get( RESOURCE::SCROLLING_MOONSURFACE );
        moonSurfaceLayer->SetLayer( 0, RESOURCE::BACKGROUND_MOONSURFACE );
        moonSurfaceLayer->SetLayerSpeed( 0, 8, 8 );    // 1:15 movement speed
        moonSurfaceLayer->SetSpeed( 0, -250 );

        auto& cloudsLayers = ScrollingBackgroundFactory::Instance()->Get( RESOURCE::SCROLLING_CLOUDS );
        cloudsLayers->SetLayer( 0, RESOURCE::BACKGROUND_CLOUDS1 );
        cloudsLayers->SetLayer( 1, RESOURCE::BACKGROUND_CLOUDS2 );
        cloudsLayers->SetLayerSpeed( 0, 4, 4 );     // 1:7 movement speed
        cloudsLayers->SetLayerSpeed( 1, 1, 1 );     // 1:1 movement speed
        cloudsLayers->SetSpeed( 0, -250 );
    }

    // Load fonts using Factory pattern
    {
        FontFactory::Instance()->Get( RESOURCE::FONT_INFO )->Load( "Assets/Fonts/failed.ttf", 24 );
        FontFactory::Instance()->Get( RESOURCE::FONT_SCORE )->Load( "Assets/Fonts/digital-7_mono.ttf", 32 );
        FontFactory::Instance()->Get( RESOURCE::FONT_SMALL )->Load( "Assets/Fonts/ProFontWindows.ttf", 9 );
        FontFactory::Instance()->Get( RESOURCE::FONT_MENU )->Load( "Assets/Fonts/impact.ttf", 35 );
    }

    // Load sounds using Factory pattern
    {
        SoundFactory::Instance()->Get( RESOURCE::SOUND_INTRO_AMIGADISKFX )->Load( "Assets/Sounds/intro_disksound.ogg" );
        SoundFactory::Instance()->Get( RESOURCE::SOUND_PLAYER_FIRE )->Load( "Assets/Sounds/laser.ogg" );
        SoundFactory::Instance()->Get( RESOURCE::SOUND_ENEMY_FIRE )->Load( "Assets/Sounds/machinegun2.ogg" );
        SoundFactory::Instance()->Get( RESOURCE::SOUND_EXPLOSION1 )->Load( "Assets/Sounds/explosion_1.ogg" );
        SoundFactory::Instance()->Get( RESOURCE::SOUND_EXPLOSION2 )->Load( "Assets/Sounds/explosion_2.ogg" );
    }

    // Preload musics using Factory pattern
    {
        MusicFactory::Instance()->Get( RESOURCE::MUSIC_SPLASH )->Load( "Assets/Musics/cdk_-_Song_Of_Peace.ogg" );
        MusicFactory::Instance()->Get( RESOURCE::MUSIC_INGAME )->Load( "Assets/Musics/Astroboy_Sprung-160.ogg" );
        MusicFactory::Instance()->Get( RESOURCE::MUSIC_GAMEOVER )->Load( "Assets/Musics/Syenta_-_Cytheres_Reves_(Cytheres_Dreams)_2.ogg" );
    }

    // Create texts using Factory pattern
    {
        auto& fontSmall = FontFactory::Instance()->Get( RESOURCE::FONT_SMALL );
        auto& fontInfo = FontFactory::Instance()->Get( RESOURCE::FONT_INFO );
        auto& fontMenu = FontFactory::Instance()->Get( RESOURCE::FONT_MENU );
        TextFactory::Instance()->Get( RESOURCE::TEXT_BETA_BUILD_NOTE )->Create( fontSmall, "Space Attackers : Beta build, not for distribution! // Programming by Mika Luoma-aho <*****@*****.**>", 80, 128, 75, 64 );
        TextFactory::Instance()->Get( RESOURCE::TEXT_STARTGAME )->Create( fontInfo, "< Press space to start a new game or ESC to quit >" );
        TextFactory::Instance()->Get( RESOURCE::TEXT_SPACE_TO_CONTINUE )->Create( fontInfo, "< Press space to continue >" );
        TextFactory::Instance()->Get( RESOURCE::TEXT_ENTER_TO_CONTINUE )->Create( fontInfo, "< Press enter to continue >" );
        TextFactory::Instance()->Get( RESOURCE::TEXT_HIGHSCORES )->Create( fontMenu, "< HI-SCORES >" );
        TextFactory::Instance()->Get( RESOURCE::TEXT_LEVEL_STARTING )->Create( fontMenu, "Get ready for" );
        TextFactory::Instance()->Get( RESOURCE::TEXT_GAMEOVER_SCORE )->Create( fontMenu, "SCORE" );
        TextFactory::Instance()->Get( RESOURCE::TEXT_GAMEOVER_ENTERYOURNAME )->Create( fontMenu, "ENTER YOUR NAME", 255, 220, 100 );
        TextFactory::Instance()->Get( RESOURCE::TEXT_GAMEOVER_NAME )->Create( fontMenu, "" );
        TextFactory::Instance()->Get( RESOURCE::TEXT_GAMEOVER_NAME_PROMPT )->Create( fontMenu, "_" /*«*/ );
    }

    // Create particle effects
    {
        // Create Explosion
        {
            auto& velocityOverTime = InterpolationSetFactory::Instance()->Get( RESOURCE::IS_EXPLOSION_VELOCITY );
            velocityOverTime->AddValue( 0.0f, 20.0f );
            velocityOverTime->AddValue( 0.7f, 10.5f, Math::Interpolation::easeOutCirc<float,float> );

            auto& alphaOverTime = InterpolationSetFactory::Instance()->Get( RESOURCE::IS_EXPLOSION_ALPHA );
            alphaOverTime->AddValue( 0.0f, 1.0f );
            alphaOverTime->AddValue( 1.0f, 0.0f, Math::Interpolation::linearTween<float,float> );

            auto& sizeOverTime = InterpolationSetFactory::Instance()->Get( RESOURCE::IS_EXPLOSION_SIZE );
            sizeOverTime->AddValue( 0.0f, 3.0f );
            sizeOverTime->AddValue( 1.0f, 1.0f, Math::Interpolation::linearTween<float,float> );

            // Flame colors
            // http://kuler.adobe.com/#themeID/177302
            //
            Math::Colors::HSV h1, h2, h3, h4, h5;
            h1 = { 41, 0.84f, 1.0f };
            h2 = { 43, 0.70f, 1.0f };
            h3 = { 63, 0.37f, 0.97f };
            h4 = { 30, 0.85f, 1.0f };
            h5 = { 17, 0.95f, 0.73f };

            auto& colorOverTime = SDLColorInterpolationSetFactory::Instance()->Get( RESOURCE::IS_EXPLOSION_COLOR );
            colorOverTime->AddValue( 0.0f, Math::Colors::HSV2SDLColor(h1) );
            colorOverTime->AddValue( 0.2f, Math::Colors::HSV2SDLColor(h2) );
            colorOverTime->AddValue( 0.4f, Math::Colors::HSV2SDLColor(h3) );
            colorOverTime->AddValue( 0.6f, Math::Colors::HSV2SDLColor(h4) );
            colorOverTime->AddValue( 0.8f, Math::Colors::HSV2SDLColor(h5) );

            // Set parameters
            auto& psExplosion = ExplosionSystemFactory::Instance()->Get( RESOURCE::PS_EXPLOSION );

            psExplosion->Initialize( 500 );
            psExplosion->SetVelocityOverTime( RESOURCE::IS_EXPLOSION_VELOCITY );
            psExplosion->SetAlphaOverTime( RESOURCE::IS_EXPLOSION_ALPHA );
            psExplosion->SetColorOverTime( RESOURCE::IS_EXPLOSION_COLOR );
            psExplosion->SetSizeOverTime( RESOURCE::IS_EXPLOSION_SIZE );
            psExplosion->SetPrimitiveType( 2 );
            psExplosion->SetTrails( false );
        }

        // Create Smoke
        {
            auto& velocityOverTime = InterpolationSetFactory::Instance()->Get( RESOURCE::IS_SMOKE_VELOCITY );
            velocityOverTime->AddValue( 0.0f, 15.0f );
            velocityOverTime->AddValue( 1.0f, 0.0f, Math::Interpolation::linearTween<float,float> );

            auto& alphaOverTime = InterpolationSetFactory::Instance()->Get( RESOURCE::IS_SMOKE_ALPHA );
            alphaOverTime->AddValue( 0.0f, 0.5f );
            alphaOverTime->AddValue( 1.0f, 0.1f, Math::Interpolation::easeInCirc<float,float> );

            auto& sizeOverTime = InterpolationSetFactory::Instance()->Get( RESOURCE::IS_SMOKE_SIZE );
            sizeOverTime->AddValue( 0.0f, 1.0f );
            sizeOverTime->AddValue( 1.0f, 3.0f, Math::Interpolation::linearTween<float,float> );

            // Smoke colors
            // http://kuler.adobe.com/#themeID/1262268
            //
            Math::Colors::HSV h1, h2, h3, h4;
            h1 = { 226, 0.25f, 0.16f };
            h2 = { 235, 0.07f, 0.34f };
            h3 = { 40, 0.08f, 0.41f };
            h4 = { 43, 0.15f, 0.53f };

            auto& colorOverTime = SDLColorInterpolationSetFactory::Instance()->Get( RESOURCE::IS_SMOKE_COLOR );
            colorOverTime->AddValue( 0.0f, Math::Colors::HSV2SDLColor(h1) );
            colorOverTime->AddValue( 0.3f, Math::Colors::HSV2SDLColor(h2) );
            colorOverTime->AddValue( 0.6f, Math::Colors::HSV2SDLColor(h3) );
            colorOverTime->AddValue( 1.0f, Math::Colors::HSV2SDLColor(h4) );

            // Set parameters
            auto& psSmoke = SmokeSystemFactory::Instance()->Get( RESOURCE::PS_SMOKE );

            psSmoke->Initialize( 300 );
            psSmoke->SetVelocityOverTime( RESOURCE::IS_SMOKE_VELOCITY );
            psSmoke->SetAlphaOverTime( RESOURCE::IS_SMOKE_ALPHA );
            psSmoke->SetColorOverTime( RESOURCE::IS_SMOKE_COLOR );
            psSmoke->SetSizeOverTime( RESOURCE::IS_SMOKE_SIZE );
            psSmoke->SetPrimitiveType( 2 );
            psSmoke->SetTrails( false );
        }
    }

    // Create explosion thread to be used in highscore screen
    {
        ExplosionThreadFactory::Instance()->Get( RESOURCE::THREAD_EXPLOSION )->SetExplosion( RESOURCE::PS_EXPLOSION );
    }

    // Create note
    {
        auto& noteText = TextFactory::Instance()->Get( RESOURCE::TEXT_BETA_BUILD_NOTE );
        m_noteImgWidth = noteText->GetSurface()->w;
    }

    // Load scenes into memory and set first scene as running
    {
        unique_ptr<CScene> SplashScene = unique_ptr<SceneSplashScreen>(new SceneSplashScreen);
        unique_ptr<CScene> Level1Scene = unique_ptr<SceneLevel>(new SceneLevel);
        unique_ptr<CScene> GameOverScene = unique_ptr<SceneGameOver>(new SceneGameOver);
        unique_ptr<CScene> HighscoresScene = unique_ptr<SceneHighscores>(new SceneHighscores);
        unique_ptr<CScene> HelpScene = unique_ptr<SceneHelp>(new SceneHelp);

        // Add scenes (order is also the render order!)
        AddScene( SCENE_0_Intro, SplashScene );
        AddScene( SCENE_1_Game, Level1Scene );
        AddScene( SCENE_2_GameOver, GameOverScene );
        AddScene( SCENE_3_Highscores, HighscoresScene );
        AddScene( SCENE_4_Help, HelpScene );
    }

    // Load and run the first scene
    //#ifdef DEBUG_SCENE1
    //LoadAndRunScene( SCENE_1_Game );
    //SetState( (int)STATE::GAME );
    auto& properties = CSingleton<CProperties>::Instance();
    #ifdef DEBUG_GAMEOVER
    properties->Property( "Player", "Name" ) = (std::string)"";
    properties->Property( "Player", "Score" ) = static_cast<int>(1234567);
    properties->Property( "Player", "Fired" ) = static_cast<int>(1000);
    properties->Property( "Player", "Kills" ) = static_cast<int>(20);
    properties->Property( "Player", "Accuracy" ) = static_cast<int>(98);
    properties->Property( "Player", "Level" ) = static_cast<int>(27);
    LoadAndRunScene( SCENE_2_GameOver );
    SetState( (int)STATE::GAME_OVER );
    #else
    properties->Property( "Player", "Name" ) = (std::string)"";
    LoadAndRunScene( SCENE_0_Intro );
    SetState( (int)STATE::SPLASH_SCREEN );
    #endif

    // Default to 60fps
    SDL_initFramerate( &m_fpsManager );
    SDL_setFramerate( &m_fpsManager, 60 );

    // Initialize state handlers
    InitHandlers();
}
Exemplo n.º 12
0
void Main::OnInitialize() {
    mScore1 = 0;
    mScore2 = 0;

    dt::Scene* scene = AddScene(new dt::Scene("testscene"));
    OgreProcedural::Root::getInstance()->sceneManager = scene->GetSceneManager();

    dt::ResourceManager::Get()->AddResourceLocation("","FileSystem", true);
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    Ogre::FontManager::getSingleton().load("DejaVuSans", "General");

    dt::Node* camnode = scene->AddChildNode(new dt::Node("camnode"));
    camnode->SetPosition(Ogre::Vector3(0, 0, 30));
    camnode->AddComponent(new dt::CameraComponent("cam"))->LookAt(Ogre::Vector3(0, 0, 0));

    dt::Node* lightnode = scene->AddChildNode(new dt::Node("lightnode"));
    lightnode->SetPosition(Ogre::Vector3(-20, 20, 10));
    lightnode->AddComponent(new dt::LightComponent("light"));

    // generate meshes
    OgreProcedural::BoxGenerator().setSizeX(FIELD_WIDTH + 1).setSizeY(FIELD_HEIGHT).setSizeZ(1.f).realizeMesh("Field");
    OgreProcedural::BoxGenerator().setSizeX(1.0).setSizeY(1.f).setSizeZ(1.f).realizeMesh("Ball");
    OgreProcedural::BoxGenerator().setSizeX(1.0).setSizeY(3.f).setSizeZ(1.f).realizeMesh("Paddle");

    mGameNode = scene->AddChildNode(new dt::Node("game"));

    mFieldNode = mGameNode->AddChildNode(new dt::Node("field"));
    mFieldNode->SetPosition(Ogre::Vector3(0, 0, -1));
    mFieldNode->AddComponent(new dt::MeshComponent("Field", "SimplePongField", "mesh"));

    mBallNode = mGameNode->AddChildNode(new dt::Node("ball"));
    mBallNode->SetPosition(Ogre::Vector3(0, 0, 0));
    mBallNode->AddComponent(new dt::MeshComponent("Ball", "SimplePongBall", "mesh"));

    mPaddle1Node = mGameNode->AddChildNode(new dt::Node("paddle1"));
    mPaddle1Node->SetPosition(Ogre::Vector3(- FIELD_WIDTH / 2 - 0.5, 0, 0));
    mPaddle1Node->AddComponent(new dt::MeshComponent("Paddle", "SimplePongPaddle", "mesh"));

    mPaddle2Node = mGameNode->AddChildNode(new dt::Node("paddle2"));
    mPaddle2Node->SetPosition(Ogre::Vector3(FIELD_WIDTH / 2 + 0.5, 0, 0));
    mPaddle2Node->AddComponent(new dt::MeshComponent("Paddle", "SimplePongPaddle", "mesh"));

    dt::Node* score1_node = mGameNode->AddChildNode(new dt::Node("score1"));
    score1_node->SetPosition(Ogre::Vector3(-10, FIELD_HEIGHT / 2 + 2, 0));
    mScore1Text = score1_node->AddComponent(new dt::TextComponent("0", "text"));
    mScore1Text->SetFont("DejaVuSans");
    mScore1Text->SetFontSize(64);

    dt::Node* score2_node = mGameNode->AddChildNode(new dt::Node("score2"));
    score2_node->SetPosition(Ogre::Vector3(10, FIELD_HEIGHT / 2 + 2, 0));
    mScore2Text = score2_node->AddComponent(new dt::TextComponent("0", "text"));
    mScore2Text->SetFont("DejaVuSans");
    mScore2Text->SetFontSize(64);

    dt::Node* info_node = scene->AddChildNode(new dt::Node("info"));
    info_node->SetPosition(Ogre::Vector3(0, - FIELD_HEIGHT / 2 - 3, 0));
    dt::TextComponent* info_text = info_node->AddComponent(new dt::TextComponent("Left player: W/S -- Right player: Up/Down", "text"));
    info_text->SetFont("DejaVuSans");
    info_text->SetFontSize(20);

    ResetBall();
}
Exemplo n.º 13
0
void SceneManager::SetActiveScene( Scene* scenePtr )
{
	AddScene(scenePtr); //add the scene to the map
	m_ActiveScene = scenePtr; //set the newly added scene as active
}