Guest User

Untitled

a guest
Feb 16th, 2012
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.58 KB | None | 0 0
  1. /*
  2.    Project CodeName NightLight
  3.    (C) 2011 NightLight Team
  4.  
  5.    This software is provided 'as-is', without any express or implied
  6.    warranty. In no event will the authors be held liable for any
  7.    damages arising from the use of this software.
  8.  
  9.    Permission is granted to anyone to use this software for any
  10.    purpose, including commercial applications, and to alter it and
  11.    redistribute it freely, subject to the following restrictions:
  12.  
  13.    1. The origin of this software must not be misrepresented; you
  14.       must not claim that you wrote the original software. If you use
  15.       this software in a product, an acknowledgment in the product
  16.       documentation would be appreciated but is not required.
  17.  
  18.    2. Altered source versions must be plainly marked as such, and
  19.       must not be misrepresented as being the original software.
  20.  
  21.    3. This notice may not be removed or altered from any source
  22.       distribution.
  23.  
  24.     Scorcher24
  25. */
  26. #include "stdafx.hpp"
  27. using namespace NightLight;
  28. #include "GameStateDemo.hpp"
  29. #include "Game.hpp"
  30.  
  31.  
  32. GameStateDemo::GameStateDemo( u32 id )
  33. : IGameState(id), m_controller(Controller())
  34. {}
  35.  
  36. GameStateDemo::GameStateDemo( u32 id, boost::any usrdata )
  37. : IGameState(id, usrdata), m_controller(Controller())
  38. {
  39.     boost::any_cast<Game>(m_usrdata).test();
  40. }
  41.  
  42. GameStateDemo::~GameStateDemo()
  43. {
  44.     delete m_batcher;
  45. }
  46.  
  47. void GameStateDemo::onEnterGameState( s32 old_state )
  48. {
  49.     // Load SpriteSheet
  50.     SpriteSheet* SpriteSheet = m_controller.getResourceManager().getSpriteSheet("SpriteSheet");
  51.  
  52.     // Load Shader
  53.     Shader* ShaderTexturedWithAlphaTest = m_controller.getResourceManager().getShader("TexturedWithAlphaTest");
  54.  
  55.     // Create Batcher
  56.     m_batcher = new SpriteBatcher(ShaderTexturedWithAlphaTest, SpriteSheet->getTexture());
  57.     m_batcher->insert(new BatchedSprite(glm::vec2(64, 64), glm::vec3(100, 100, LayerConstants::DYNAMIC_LAYER1), SpriteSheet->getTexCoordsByName("bohne_64") ));
  58.     m_batcher->createBatch();
  59.  
  60.     // Connect Events
  61.     m_controller.connectSignalRender(NLBindRenderSlot(GameStateDemo, renderObject));
  62.     m_controller.getTimerController().connectSignalLogicUpdate(NLBindUpdateLogicSlot(GameStateDemo, update));
  63. }
  64.  
  65. void GameStateDemo::onLeaveGameState( s32 new_state )
  66. {
  67. }
  68.  
  69. void GameStateDemo::renderObject( u32 delta, u32 time )
  70. {
  71.     m_batcher->renderObject();
  72. }
  73.  
  74. void GameStateDemo::update( u32 delta, u32 time )
  75. {
  76.  
  77. }
  78.  
  79. ///------------------------------------------
  80.  
  81.  
  82.  
  83. Game::Game()
  84. : m_controller(SystemController::getInstance())
  85. {
  86.     m_controller.setAppName("NightLightSandBox");
  87.     m_controller.setVendorName("Scorched Productions");
  88.     m_data_dir = m_controller.getUserDataDir();
  89.  
  90.     if ( m_controller.createUserDataDir() )
  91.     {
  92.         m_controller.createLog(m_data_dir + "/SandboxLog.html", LL_VERBOSE, new HtmlWriter);
  93.     }
  94.     else
  95.     {
  96.         throw Exception("SystemController::createUserDataDir() failed!");
  97.     }
  98. }
  99.  
  100. Game::~Game()
  101. {
  102. }
  103.  
  104. int Game::runGame()
  105. {
  106.     // Create Window
  107.     m_controller.createWindow(WINDOW_WINDOWED);
  108.     m_controller.getOpenGLContext()->setClearColor(Color4f(0.0, 0.0, 0.4f, 1.0f));
  109.  
  110.     // Load Resource File
  111.     m_controller.getResourceManager().loadResourceFile("../xml/examples.xml");
  112.  
  113.     // Create GameStateManager and add state
  114.     m_statemgr = new Util::GameStateManager();
  115.     m_statemgr->addGameState(new GameStateDemo(GS_DEMO, *this));
  116.     m_statemgr->changeToGameState(GS_DEMO);
  117.  
  118.     // Connect Event
  119.     m_controller.getWindow()->connectSignalQuit(NLBindQuitSlot(Game, quit));
  120.  
  121.     // Enter Loop
  122.     m_controller.enterLoop();
  123.  
  124.     // return ok
  125.     return 0;
  126. }
  127.  
  128. bool Game::quit()
  129. {
  130.     return true;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment