void ChoosePowerState::Init() { std::vector<FreePositions> dummyVar; List<EnemyWithStates> dummyList; Entity dummyEnt = _builder->EntityC().Create(); _allPowers.push_back(new LockOnStrike(_builder, dummyEnt, &dummyList)); _allPowers.push_back(new RandomBlink(_builder, dummyEnt, dummyVar)); _allPowers.push_back(new CharmPower(_builder, dummyEnt, &dummyList)); _allPowers.push_back(new TimeStopper(_builder, dummyEnt, &dummyList)); _allPowers.push_back(new RegenPower(_builder, nullptr, dummyEnt)); _allPowers.push_back(new LifeDrain(_builder, dummyEnt, &dummyList, nullptr)); size_t firstPower = rand() % _allPowers.size(); size_t secondPower = (firstPower + 1) % _allPowers.size(); auto options = System::GetOptions(); float pctX = options->GetScreenResolutionWidth() / 100.0f; float pctY = options->GetScreenResolutionHeight() / 100.0f; float midX = options->GetScreenResolutionWidth() / 2.0f; float midY = options->GetScreenResolutionHeight() / 2.0f; _choice2 = _builder->CreateOverlay(XMFLOAT3(midX - 30.0f * pctX, midY - 20.0f * pctY, 0.0f), 28.0f * pctX, 40.0f * pctY, "Assets/Textures/menuthing.png"); _choice1 = _builder->CreateOverlay(XMFLOAT3(midX + 2.0f * pctX, midY - 20.0f * pctY, 0.0f), 28.0f * pctX, 40.0f * pctY, "Assets/Textures/menuthing.png"); _choice2Text = _builder->CreateLabel(XMFLOAT3(midX + 4.0f * pctX, midY - 18.0f * pctY, 0.0f), _allPowers[firstPower]->GetDescription(40),20, XMFLOAT4(0.8f, 0.8f, 0.5f, 1.0f), 1.0f, 1.0f, ""); _choice1Text = _builder->CreateLabel(XMFLOAT3(midX - 29.0f * pctX, midY - 18.0f * pctY, 0.0f), _allPowers[secondPower]->GetDescription(40), 20, XMFLOAT4(0.8f, 0.8f, 0.5f, 1.0f), 1.0f, 1.0f, ""); _powerLabel = _builder->CreateLabel(XMFLOAT3(midX - 30.0f * pctX, midY - 10.0f * pctY - 20.0f * pctY, 0.0f), "Choose your powers", 35, XMFLOAT4(0.8f, 0.8f, 0.4f, 1.0f), 60.0f * pctX, 8.0f * pctY, ""); GameState* gstate = (GameState*)this->_savedState; auto i = System::GetInput(); i->HideCursor(false); i->LockMouseToCenter(false); _builder->Event()->BindEvent(_choice1, EventManager::EventType::LeftClick, [this, i, firstPower, gstate]() { _powerToGive = _allPowers[firstPower]->GetType(); i->LockMouseToCenter(true); _controller->ReleaseEntity(_choice1); _controller->ReleaseEntity(_choice2); _controller->ReleaseEntity(_powerLabel); _controller->ReleaseEntity(_choice1Text); _controller->ReleaseEntity(_choice2Text); i->HideCursor(true); gstate->ProgressNoNextLevel(_powerToGive); System::GetAudio()->PlaySoundEffect(L"choosepower.wav", 1.0f); ChangeStateTo(StateChange(gstate, false, true, false)); }); _builder->Event()->BindEvent(_choice2, EventManager::EventType::LeftClick, [this, i, secondPower, gstate]() { _powerToGive = _allPowers[secondPower]->GetType(); i->LockMouseToCenter(true); i->LockMouseToWindow(true); _controller->ReleaseEntity(_choice1); _controller->ReleaseEntity(_choice2); _controller->ReleaseEntity(_powerLabel); _controller->ReleaseEntity(_choice1Text); _controller->ReleaseEntity(_choice2Text); i->HideCursor(true); gstate->ProgressNoNextLevel(_powerToGive); System::GetAudio()->PlaySoundEffect(L"choosepower.wav", 1.0f); ChangeStateTo(StateChange(gstate, false, true, false)); }); _camera = _builder->CreateCamera(XMVectorSet(0.0f, 0.0f, 0.0f, 1.0f)); _builder->Transform()->SetDirection(_camera, XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f)); _backgroundObject = _builder->CreateObject(XMVectorSet(0.0f, 0.0f, 3.0f, 1.0f), XMVectorSet(0, 0, 0, 0), XMVectorSet(32.0f, 32.0f, 1.0f, 0.0f), "Assets/Models/cube.arf", "Assets/Textures/Dungeon/0/Wall_Dif.png", "Assets/Textures/Dungeon/0/Wall_NM.png", "Assets/Textures/Dungeon/0/Wall_Disp.png", "Assets/Textures/Dungeon/0/Wall_Roughness.png", "Assets/Textures/Dungeon/0/Wall_Glossiness.png"); _builder->Material()->SetMaterialProperty(_backgroundObject, "ParallaxScaling", 0.04f, "Shaders/GBuffer.hlsl"); _builder->Material()->SetMaterialProperty(_backgroundObject, "ParallaxBias", -0.03f, "Shaders/GBuffer.hlsl"); _builder->Material()->SetMaterialProperty(_backgroundObject, "TexCoordScaleU", 32.0f, "Shaders/GBuffer.hlsl"); _builder->Material()->SetMaterialProperty(_backgroundObject, "TexCoordScaleV", 32.0f, "Shaders/GBuffer.hlsl"); _light = _builder->EntityC().Create(); _builder->Light()->BindPointLight(_light, XMFLOAT3(3.0f, 3.0f, 1.0f), 10.0f, XMFLOAT3(1.0f, 1.0f, 1.0f), 4.0f); }
Window::Window(std::string title, int sizeX, int sizeY, bool fullScreen) { renderer = NULL; window = this; forceQuit = false; init = false; mouseLeftWindow = false; lockMouse = false; showMouse = true; this->fullScreen = fullScreen; size.x = (float)sizeX; size.y = (float)sizeY; fullScreen ? position.x = 0.0f : position.x = 100.0f; fullScreen ? position.y = 0.0f : position.y = 100.0f; HINSTANCE hInstance = GetModuleHandle( NULL ); //This creates the console window AllocConsole(); int consoleHandle; long stdHandle; FILE *file; // redirect stdout stdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE); consoleHandle = _open_osfhandle(stdHandle, _O_TEXT); file = _fdopen( consoleHandle, "w" ); *stdout = *file; setvbuf( stdout, NULL, _IONBF, 0 ); // redirect stdin stdHandle = (long)GetStdHandle(STD_INPUT_HANDLE); file = _fdopen( consoleHandle, "r" ); *stdin = *file; setvbuf( stdin, NULL, _IONBF, 0 ); // WNDCLASSEX windowClass; ZeroMemory(&windowClass, sizeof(WNDCLASSEX)); if(!GetClassInfoEx(hInstance,WINDOWCLASS,&windowClass)) { windowClass.cbSize = sizeof(WNDCLASSEX); windowClass.style = CS_HREDRAW | CS_VREDRAW; windowClass.lpfnWndProc = (WNDPROC)WindowProc; windowClass.hInstance = hInstance; windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); windowClass.hbrBackground = (HBRUSH)COLOR_WINDOW; windowClass.lpszClassName = WINDOWCLASS; if(!RegisterClassEx(&windowClass)) { std::cout << "Window::Window(): Failed to register class!" << std::endl; return; } } if(fullScreen) { DEVMODE dmScreenSettings; // Device Mode memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure dmScreenSettings.dmPelsWidth = sizeX; // Selected Screen Width dmScreenSettings.dmPelsHeight = sizeY; // Selected Screen Height dmScreenSettings.dmBitsPerPel = 32; // Selected Bits Per Pixel dmScreenSettings.dmDisplayFrequency = 60; dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT|DM_DISPLAYFREQUENCY; if(ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) { std::cout << "Window::Window(): Failed to switch to fullscreen!" << std::endl; return; } } windowHandle = CreateWindowEx(fullScreen ? WS_EX_TOPMOST : NULL, WINDOWCLASS, // name of the window class title.c_str(), // title of the window fullScreen ? WS_POPUP|WS_VISIBLE : WS_OVERLAPPEDWINDOW|WS_POPUP|WS_VISIBLE|WS_SYSMENU|WS_MAXIMIZEBOX|WS_MINIMIZEBOX, // window style (int)position.x, // x-position of the window (int)position.y, // y-position of the window (int)size.x, // width of the window (int)size.y, // height of the window NULL, // No parent window! NULL, // No Menus! hInstance, // application handle NULL); // No multiple windows! if(!windowHandle) { std::cout << "Window::Window(): Failed to create window!" << std::endl; return; } if(!keyboard) { keyboard = new Keyboard(windowHandle); } if(!mouse) { mouse = new Mouse(windowHandle); } //if(!timer) { timer = new GameTimer(); //} elapsedMS = timer->GetMS(); Window::GetMouse()->SetAbsolutePositionBounds((unsigned int)size.x,(unsigned int)size.y); POINT pt; GetCursorPos(&pt); ScreenToClient(window->windowHandle, &pt); Window::GetMouse()->SetAbsolutePosition(pt.x,pt.y); LockMouseToWindow(lockMouse); ShowOSPointer(showMouse); init = true; }
void PauseState::Init() { auto i = System::GetInput(); auto o = System::GetOptions(); float width = (float)o->GetScreenResolutionWidth(); float height = (float)o->GetScreenResolutionHeight(); auto c = _controller; auto a = System::GetInstance()->GetAudio(); float widthPercentOfDefault = (1.0f / 1920.0f) * width; float heightPercentOfDefault = (1.0f / 1080.0f) * height; float fontSize = 40 ; XMFLOAT4 TextColor = XMFLOAT4(41.0f / 255.0f, 127.0f / 255.0f, 185.0f / 255.0f, 1.0f); // Radiant text Entity text = _builder->CreateLabel( XMFLOAT3(width / 2.0f - 110.0f, 25.0f, 0.0f), "Game Paused", fontSize, TextColor, 250.0f, 45.0f, ""); _builder->Transform()->SetPosition(text, XMFLOAT3(width / 2.0f - _builder->Text()->GetLength(text) / 2.0f, 25.0f, 0.0f)); // Resume button Entity b1 = _builder->CreateButton( XMFLOAT3(width / 2.0f - 110.0f, height/4.0f, 0.0f), "Resume Game", fontSize, TextColor, "", []() { }); _builder->Transform()->SetPosition(b1, XMFLOAT3(width / 2.0f - _builder->Text()->GetLength(b1) / 2.0f, height / 1.5f, 0.0f)); //Main menu button Entity b5 = _builder->CreateButton( XMFLOAT3(width / 2.0f - 110.0f, height / 4.0f, 0.0f), "Main Menu", fontSize, TextColor, "", [i, a]() { a->PlaySoundEffect(L"menuclick.wav", 1); ChangeStateTo(StateChange(new MenuState())); }); _builder->Transform()->SetPosition(b5, XMFLOAT3(width / 2.0f - _builder->Text()->GetLength(b5) / 2.0f, height / 1.5f + 55.0f, 0.0f)); // Exit button Entity b2 = _builder->CreateButton( XMFLOAT3(width / 2.0f - 110.0f, height / 4.0f + 55.0f, 0.0f), "Exit to desktop", fontSize, TextColor, "", [a]() { a->PlaySoundEffect(L"menuclick.wav", 1); ExitApplication; }); _builder->Transform()->SetPosition(b2, XMFLOAT3(width / 2.0f - _builder->Text()->GetLength(b2)/2.0f, height / 1.5f + 110.0f, 0.0f)); _controller->BindEvent(b1, EventManager::EventType::LeftClick, [i, a, this, text, b1, b2, b5]() { _controller->ReleaseEntity(text); _controller->ReleaseEntity(b1); _controller->ReleaseEntity(b2); _controller->ReleaseEntity(b5); i->LockMouseToCenter(true); i->LockMouseToWindow(true); i->HideCursor(true); i->MouseUp(VK_LBUTTON); a->PlaySoundEffect(L"menuclick.wav", 1); ChangeStateTo(StateChange(_savedState,false,true,true)); _savedState = nullptr; }); _controller->BindEvent(b1, EventManager::EventType::Update, [i, a, this, text, b1, b2, b5]() { if (i->IsKeyPushed(VK_ESCAPE)) { _controller->ReleaseEntity(text); _controller->ReleaseEntity(b1); _controller->ReleaseEntity(b2); _controller->ReleaseEntity(b5); i->LockMouseToCenter(true); i->LockMouseToWindow(true); i->HideCursor(true); i->MouseUp(VK_LBUTTON); a->PlaySoundEffect(L"menuclick.wav", 1); ChangeStateTo(StateChange(_savedState, false, true, true)); _savedState = nullptr; } }); }