void InputSystemFixture::Should_Not_Initialize_With_NULL_HWND() { InputSystem* inputSystem = new InputSystem(); CPPUNIT_ASSERT_THROW(inputSystem->Initialize(0), IntializeFailedException); delete inputSystem; }
void InputSystemFixture::Should_Initialize_Properly() { InputSystem* inputSystem = new InputSystem(); inputSystem->Initialize(0); delete inputSystem; }
virtual void update(EntityData &entity, float time, const ALLEGRO_EVENT &) { InputMovement *input = entity.getComponent<InputMovement>(); Velocity *vel = entity.getComponent<Velocity>(); Rotation *rotation = entity.getComponent<Rotation>(); Sprite *sprite = entity.getComponent<Sprite>(); InputSystem *sys = SystemManager::getInstance().getSystem<InputSystem>(); if (!sys) return; if (sys->isDown(ALLEGRO_KEY_W)) { vel->velocity.y += input->speed * time; sprite->animation = ResourceManager::getInstance().get<AnimationMedia>("herosWalkFront.anim"); } if (sys->isDown(ALLEGRO_KEY_S)) { vel->velocity.y -= input->speed * time; sprite->animation = ResourceManager::getInstance().get<AnimationMedia>("herosWalkBack.anim"); } if (sys->isDown(ALLEGRO_KEY_A)) { vel->velocity.x -= input->speed * time; rotation->rotation.y = 0.0f; sprite->animation = ResourceManager::getInstance().get<AnimationMedia>("herosWalkSide.anim"); } if (sys->isDown(ALLEGRO_KEY_D)) { vel->velocity.x += input->speed * time; rotation->rotation.y = -180.0f; sprite->animation = ResourceManager::getInstance().get<AnimationMedia>("herosWalkSide.anim"); } }
void GraphicsSystem::OnUpdate(const Event& event) { InputSystem* pIS = Program::Inst()->GetInputSystem(); sf::Event sfEvent; while (m_SfWindow.pollEvent(sfEvent)) { if (sfEvent.type == sf::Event::Closed) { m_SfWindow.close(); Program::Inst()->Exit(); } else if (sfEvent.type == sf::Event::Resized) { m_Width = sfEvent.size.width; m_Height = sfEvent.size.height; Dispatch(Event(EvtWindowResize, WindowResizeEventData(m_Width, m_Height))); } else { pIS->ProcessSfEvent(sfEvent); } } }
IntroState::IntroState(Engine* p_engine) : GameState(p_engine), m_totalMilliseconds(std::time_t(2000)), m_elapsedMilliseconds(0) { std::clog << "Entering intro state..." << std::endl; // do one input state capture just to hide the mouse cursor InputSystem* inputSystem = m_engine->getInputSystem(); inputSystem->capture(); // get the material by name std::clog << "Loading fade overlay material..." << std::endl; Ogre::ResourcePtr resptr = Ogre::MaterialManager::getSingleton(). getByName("Materials/FadeOverlay"); Ogre::Material* material = dynamic_cast<Ogre::Material*>(resptr.getPointer()); Ogre::Technique* tech = material->getTechnique(0); Ogre::Pass* pass = tech->getPass(0); m_textureUnitState = pass->getTextureUnitState(0); // get the overlay std::clog << "Loading fade overlay..." << std::endl; m_fadeOverlay = Ogre::OverlayManager::getSingleton().getByName("Overlays/FadeOverlay"); m_alpha = 1.0; m_fadeOverlay->show(); }
void InputSystemFixture::Should_Throw_Given_Already_Initialized() { InputSystem* inputSystem = new InputSystem(); inputSystem->Initialize(0); CPPUNIT_ASSERT_THROW(inputSystem->Initialize(0), AlreadyInitializedException); delete inputSystem; }
int InputSystem::Script_MapMouseButton(lua_State* L) { InputSystem* pInputSystem = (InputSystem*)lua_tointeger(L, 1); string input = lua_tostring(L, 2); Mouse::Button button = (Mouse::Button)lua_tointeger(L, 3); pInputSystem->MapMouseButton(input, button); return 0; }
int InputSystem::Script_MapKey(lua_State* L) { InputSystem* pInputSystem = (InputSystem*)lua_tointeger(L, 1); string input = lua_tostring(L, 2); Keyboard::Key key = (Keyboard::Key)lua_tointeger(L, 3); pInputSystem->MapKey(input, key); return 0; }
bool Game1::Initialize(SDL_Window* pWin) { InputSystem* tInput = new InputSystem("InputSystem"); VelocitySystem* tVel = new VelocitySystem("VelocitySystem"); AttachSystem* tAtt = new AttachSystem("AttachSystem"); PhysicSystem* tPhysics = new PhysicSystem("PhysicSystem"); RenderSystem* tRender = new RenderSystem("RenderSystem"); TriggerSystem* tTrigger = new TriggerSystem("TriggerSystem"); SoundSystem* tSound = new SoundSystem("SoundSystem"); ScoreSystem* tScore = new ScoreSystem("ScoreSystem"); MenuSystem* tMenu = new MenuSystem("MenuSystem"); PowerUpSystem* tPowerUps = new PowerUpSystem("PowerUpSystem"); ShipGunSystem* tGunSystem = new ShipGunSystem("ShipGunSystem"); EnemySystem* tEnemy = new EnemySystem("EnemySystem"); WaveSystem* tWave= new WaveSystem("WaveSystem"); tRender->Initialize(); tRender->Initialize(pWin); tInput->Initialize(); tVel->Initialize(); tAtt->Initialize(); tPhysics->Initialize(); tTrigger->Initialize(); tSound->Initialize(); tScore->Initialize(); tMenu->Initialize(); tPowerUps->Initialize(); tEnemy->Initialize(); tGunSystem->Initialize(); tWave->Initialize(); //set systems to game here mSystems.push_back(tInput); mSystems.push_back(tVel); mSystems.push_back(tPhysics); mSystems.push_back(tTrigger); mSystems.push_back(tGunSystem); mSystems.push_back(tAtt); mSystems.push_back(tSound); mSystems.push_back(tScore); mSystems.push_back(tPowerUps); mSystems.push_back(tWave); mSystems.push_back(tMenu); mSystems.push_back(tEnemy); mSystems.push_back(tRender); GameStateClass::GetInstance()->SetGameState(GameState::MenuScreen); return true; }
int InputSystem::Script_GetMappedMouseButton(lua_State* L) { InputSystem* pInputSystem = (InputSystem*)lua_tointeger(L, 1); string input = lua_tostring(L, 2); Mouse::Button button = pInputSystem->GetMappedMouseButton(input); lua_pushinteger(L, button); return 1; }
int InputSystem::Script_GetMappedKey(lua_State* L) { InputSystem* pInputSystem = (InputSystem*)lua_tointeger(L, 1); string input = lua_tostring(L, 2); Keyboard::Key key = pInputSystem->GetMappedKey(input); lua_pushinteger(L, key); return 1; }
void Camera::UpdatePosition(float dt) { InputSystem* inputSystem = EngineStatics::getInputSystem(); //HydraManager* hydra = inputSystem->getHydra(); float speedScalar = 14.0f * mMaxSpeed; Vector3 forwardOffset = mDirection * speedScalar * dt; Vector3 sidewaysOffset = Cross(mDirection, Vector3(0.0f, 1.0f, 0.0f)) * speedScalar * dt; if (!mFreeRoam) { //Add to position based on direction //XMStoreFloat3(&mPosition, XMLoadFloat3(&mPosition) + forwardOffset); if (inputSystem->getKeyboardState()->IsKeyPressed(KeyboardKey::KEY_W)) { mVelocity *= powf(2.0f, dt * 2.0f); } if (inputSystem->getKeyboardState()->IsKeyPressed(KeyboardKey::KEY_S)) { mVelocity *= powf(0.5f, dt * 2.0f); } } else { if (inputSystem->getKeyboardState()->IsKeyPressed(KeyboardKey::KEY_W)) { mVelocity += forwardOffset; //mPosition += forwardOffset; } if (inputSystem->getKeyboardState()->IsKeyPressed(KeyboardKey::KEY_S)) { mVelocity -= forwardOffset; //mPosition -= forwardOffset; } if (inputSystem->getKeyboardState()->IsKeyPressed(KeyboardKey::KEY_A)) { mVelocity -= sidewaysOffset; //mPosition -= sidewaysOffset; } if (inputSystem->getKeyboardState()->IsKeyPressed(KeyboardKey::KEY_D)) { mVelocity += sidewaysOffset; //mPosition += sidewaysOffset; } } if (Length(mVelocity) > mMaxSpeed) { mVelocity = Normalize(mVelocity); mVelocity *= mMaxSpeed; } mPosition += mVelocity * dt; mVelocity *= powf(0.01f, dt); }
void InputRemapperSystem::startup() { InputSystem* pInput = getSystem<InputSystem>(); for (int x = 0; x < GameButtons::BUTTON_COUNT; x++) { mButtons[x] = new InputButton(); pInput->addButton(mButtons[x]); } mButtons[GameButtons::BUTTON_leftAxisX]->setup(GameButtons::BUTTON_leftAxisX); mButtons[GameButtons::BUTTON_leftAxisY]->setup(GameButtons::BUTTON_leftAxisY); mButtons[GameButtons::BUTTON_rightAxisX]->setup(GameButtons::BUTTON_rightAxisX); mButtons[GameButtons::BUTTON_rightAxisY]->setup(GameButtons::BUTTON_rightAxisY); mButtons[GameButtons::BUTTON_shoot]->setup(GameButtons::BUTTON_shoot, 0.0f, 1.0f); mButtons[GameButtons::BUTTON_target]->setup(GameButtons::BUTTON_target, 0.0f, 1.0f); mButtons[GameButtons::BUTTON_special]->setup(GameButtons::BUTTON_special, 0.0f, 1.0f); }
//---------------------------------------------------------------------------- void Player::ProcessInput() { Application* pApplication = Application::GetApplication(); InputSystem* pInputSystem = pApplication->GetInputSystem(); if (!pInputSystem) { return; } if (pInputSystem->GetMainDevicesCount() == 0) { return; } const MainInputDevice* pInputDevice = pInputSystem->GetMainDevice(0); // Checking minimum capabilities if (!pInputDevice->HasCapability(AnalogPad::TYPE, true) && !pInputDevice-> HasCapability(DigitalPad::TYPE, true)) { return; } if (!pInputDevice->HasCapability(IR::TYPE, true)) { return; } if (!pInputDevice->HasCapability(Buttons::TYPE, true)) { return; } // Processing analog/digital pad // if (pInputDevice->HasCapability(AnalogPad::TYPE, true)) { const AnalogPad* pAnalogPad = DynamicCast<const AnalogPad>(pInputDevice-> GetCapability(AnalogPad::TYPE, true)); WIRE_ASSERT(pAnalogPad); if (pAnalogPad->GetUp() > 0) { MoveForward(); } else if (pAnalogPad->GetDown() > 0) { MoveBackward(); } if (pAnalogPad->GetRight() > 0) { StrafeRight(); } else if (pAnalogPad->GetLeft() > 0) { StrafeLeft(); } } else { const DigitalPad* pDigitalPad = DynamicCast<const DigitalPad>(pInputDevice-> GetCapability(DigitalPad::TYPE, false)); WIRE_ASSERT(pDigitalPad); if (pDigitalPad->GetUp()) { MoveForward(); } else if (pDigitalPad->GetDown()) { MoveBackward(); } if (pDigitalPad->GetLeft()) { StrafeLeft(); } else if (pDigitalPad->GetRight()) { StrafeRight(); } } // Processing buttons // const Buttons* pButtons = DynamicCast<const Buttons>(pInputDevice-> GetCapability(Buttons::TYPE, false)); WIRE_ASSERT(pButtons); // 'A' button makes the player shoot if (pButtons->GetButton(Buttons::BUTTON_A)) { if (mpGun && mpGun->Culling == Spatial::CULL_DYNAMIC) { ShootGun(); } } // 'B' button makes the player jump if (pButtons->GetButton(Buttons::BUTTON_B)) { Jump(); } // If there's a nunchuk, start reading its buttons instead if (pInputDevice->HasExtension(Nunchuk::TYPE)) { pButtons = DynamicCast<const Buttons>(pInputDevice->GetExtension(Nunchuk::TYPE)-> GetCapability(Buttons::TYPE)); WIRE_ASSERT(pButtons); } // 'Z' button makes the player run if (pButtons->GetButton(Buttons::BUTTON_Z)) { SetMoveSpeed(8.0F); } else { SetMoveSpeed(4.0F); } // get the main device tilt (win32: mouse wheel) (in degrees) const Tilt* pTilt = DynamicCast<const Tilt>(pInputDevice-> GetCapability(Tilt::TYPE, false)); if (pTilt) { Float tilt = MathF::DEG_TO_RAD * (pTilt->GetLeft()); if (mRolls.GetQuantity() == mRolls.GetMaxQuantity()) { for (UInt i = 1; i < mRolls.GetQuantity(); i++) { mRolls[i-1] = mRolls[i]; } mRolls[mRolls.GetQuantity()-1] = tilt; } else { mRolls.Append(tilt); } } }
int main() { new EventSystem; new GraphicsSystem; InputSystem* input = new InputSystem(); EventSystem::ptr()->registerListener(input); new EntityManager; new PhysicsSystem(9.81f); EventSystem::ptr()->registerListener(GraphicsSystem::ptr()); EventSystem::ptr()->registerListener(EntityManager::ptr()); // THE GROUND ////////////////////////////////// GraphicsSystem::ptr()->loadTexture("brick", "2DGame.jpg"); GraphicsSystem::ptr()->loadTexture("box", "box.png"); GraphicsSystem::ptr()->loadTexture("mario", "mario.jpg"); Entity* ent = new Entity(); b2PolygonShape* shape = new b2PolygonShape(); shape->SetAsBox(25.0f, 2.5f); ent->init(Vec2(50.0f, 5.0f), Vec2(20, 25), shape, true); EntityManager::ptr()->addEntity(ent); ent->setTexture("brick"); ent->getBody()->GetFixtureList()->SetFriction(0.3f); Player* karl = new Player(); EventSystem::ptr()->registerListener(karl); b2PolygonShape* boxs = new b2PolygonShape(); boxs->SetAsBox(0.5f, 0.5f); for (int i = 0; i < 20; i++) { Entity* box = new Entity(); box->init(Vec2(1.0, 1.0), Vec2(10.0, -5.0*i), boxs); EntityManager::ptr()->addEntity(box); box->getBody()->GetFixtureList()[0].SetDensity(i*100.0); box->setTexture("box"); } ////////// SETUP float32 timeStep = 1.0f / 60.0f; int32 velocityIterations = 8; int32 positionIterations = 3; // while (GraphicsSystem::ptr()->getRenderWindow()->isOpen()) { input->update(*GraphicsSystem::ptr()->getRenderWindow()); GraphicsSystem::ptr()->update(); PhysicsSystem::ptr()->getWorld()->Step(timeStep, velocityIterations, positionIterations); EntityManager::ptr()->update(); } EventSystem::release(); return 0; }
int main( int argc , char* argv[] ) { // Create access to the InputSystem and an SDL_Window InputSystem* input = InputSystem::Get_Instance(); SDL_Window window; // Define the window. If the window definition fails, return a failure flag. if ( !window.Define_Window( WINDOW_WIDTH , WINDOW_HEIGHT , 32 , false , "MenuDialog System (build 0001)" ) ) return -1; // Initialize SDL_Mixer if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ) { char* error = SDL_GetError(); return -2; } music = Mix_LoadMUS( "Sounds/Mario - Star.wav" ); // Create a Menu Dialog. If the dialog creation fails, return a failure flag. test_dialog = MenuDialog::CreateMenuDialog( "TestMenuDialog" ); if (test_dialog == NULL) return -3; test_dialog->Load_Bitmap_Font("Arial"); MenuElement_CheckBox* check_box_test = dynamic_cast<MenuElement_CheckBox*>(test_dialog->Get_Element("CheckBoxTest")); if (check_box_test) { check_box_test->Set_Check_Event(&Set_Text_Block); } MenuElement_TextureButton* texture_button_test = dynamic_cast<MenuElement_TextureButton*>(test_dialog->Get_Element("TextureButtonTest")); if (texture_button_test) { texture_button_test->Set_Click_Event(&Set_Text_Block); } MenuElement_TextButton* text_button_test = dynamic_cast<MenuElement_TextButton*>(test_dialog->Get_Element("TextButtonTest")); if (text_button_test != NULL) { text_button_test->Set_Text("The quick red fox jumped over the lazy brown dog. Testing!"); text_button_test->Set_Click_Event(&Set_Text_Block); } MenuElement_DropDown* drop_down_test = dynamic_cast<MenuElement_DropDown*>(test_dialog->Get_Element("DropDownTest")); if (drop_down_test != NULL) { drop_down_test->Add_Item("TestString1"); drop_down_test->Add_Item("TestString2"); drop_down_test->Add_Item("TestString3"); drop_down_test->Set_Selection_Event(&Set_Text_Block); } MenuElement_TextBlock* text_block_test = dynamic_cast<MenuElement_TextBlock*>(test_dialog->Get_Element("TextBlockTest")); if (text_block_test != NULL) { text_block_test->Set_Text("This is a test of the string parsing functionality of the text block menu element. These words should parse down to multiple strings that render in lines downward."); } MenuElement_ListBox* list_box_test = dynamic_cast<MenuElement_ListBox*>(test_dialog->Get_Element("ListBoxTest")); if (list_box_test != NULL) { list_box_test->Add_Item("TestString2"); list_box_test->Add_Item("TestString3"); list_box_test->Add_Item("TestString4"); list_box_test->Add_Item("TestString5"); list_box_test->Add_Item("TestString6"); list_box_test->Add_Item("TestString7"); list_box_test->Add_Item("TestString8"); list_box_test->Add_Item("TestString9"); list_box_test->Add_Item("TestString10"); list_box_test->Set_Selection_Event(&Set_Text_Block); } MenuElement_EditBox* edit_box_test = dynamic_cast<MenuElement_EditBox*>(test_dialog->Get_Element("EditBoxTest")); if (edit_box_test != NULL) { edit_box_test->Set_Text("Testing"); } // Set up the general information for the rendering of the window through OpenGL glClearColor(0.4f, 0.4f, 0.4f, 1.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_BLEND); glEnable(GL_ALPHA_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glAlphaFunc(GL_GREATER, 0.02f); // Process any events from the Operating System while (SDL_ProcessEvents( input )) { if (input->Get_Key(27)) break; // 27 : ESCAPE // Get the time slice static float time_slice; static int elapsed_time[2]; elapsed_time[0] = SDL_GetTicks(); time_slice = std::max(std::min((float)(elapsed_time[0] - elapsed_time[1]) / 1000.0f, 1.0f), 0.1f); elapsed_time[1] = elapsed_time[0]; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Initiate the 2D Rendering Context glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, (GLdouble)WINDOW_WIDTH, (GLdouble)WINDOW_HEIGHT, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); test_dialog->Input( input ); test_dialog->Update( time_slice ); test_dialog->Render(); SDL_GL_SwapBuffers(); input->Invalidate_Old_Input(); } Mix_FreeMusic( music ); Mix_CloseAudio(); return 0; }