diff --git a/installer/ShipBattle.aip b/ShipBattle.aip similarity index 57% rename from installer/ShipBattle.aip rename to ShipBattle.aip index 8b474da..cb43321 100644 --- a/installer/ShipBattle.aip +++ b/ShipBattle.aip @@ -1,36 +1,38 @@ [Setup] -AIVersion=8.2 +AIVersion=9.3 AIEdition=0 GUID={6D782483-B6AC-498E-AB2F-172813AEEF05} AppName=Ship Battle -AppVersion=1.0 +AppVersion=1.1 AppDescription=Play a classic ship battle against the computer CompanyName=Ludwig Füchsl WebSite=https://github.com/Ohjurot SupportLink=https://github.com/Ohjurot InstallLevel=3 UpgradeMode=0 -IfInstalled=0 +IfInstalled=2 RunAsAdmin=1 Windows 10=1 +Windows 11=1 SystemType=1 Internet=0 CloseApp=0 CloseAppFile=File.exe CloseAppText=App Name VisualCpp=1 -VisualCppVersion=5 +VisualCppVersion=6 LinkVisualCpp=https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads PackageType=0 -SetupFolder=D:\Dev\cpp\speedcoding\ShipBattle -SetupFileName=ShipBattle_V1_0_Setup +SetupFolder=F:\Dev\30_OpenSource\ShipBattle +SetupFileName=ShipBattle_V1_1_Setup IconFile=Default -SourceDir=D:\Dev\cpp\speedcoding\ShipBattle\dist +SourceDir= InstallDir=\ MainExe=\ShipBattle.exe ProgramGroup= Uninstall=1 ShowAddRemove=1 +ProductIcon=0 SilentUninstall=0 UninstallForce=0 UninstallRestart=0 @@ -63,12 +65,11 @@ AltInstallDir=\ DataExtractParam=-o"" -aoa UninstallFileName=Uninstall.exe LangIDMethod=0 -AllowInstallIfNoSpace=0 AllowInstallIfPrereqFailed=0 SetupParameters= Theme=1 -WizardBitmap=\Bitmaps\Wizard\02.bmp -HeaderBitmap=\Bitmaps\Header\03.bmp +WizardBitmap=\Bitmaps\Wizard\New.bmp +HeaderBitmap=\Bitmaps\Header\New.bmp LogoBitmap=\Bitmaps\Logo\01.bmp DialogWelcome=1 DialogLicense=1 @@ -81,23 +82,29 @@ DialogFinish=1 ShowPublisher=1 HideFileNames=0 Beep=0 -License=D:\Dev\cpp\speedcoding\ShipBattle\installer\LICENSE.txt +License=installer\LICENSE.txt Readme= AcceptAgreement=1 Languages=English, DefaultLanguage=English AutoDetectLanguage=0 -InfoUserName=0 -InfoUserNameReq=0 -InfoCompany=0 -InfoCompanyReq=0 -InfoCustom=0 -InfoCustomReq=0 -InfoCustomName= -InfoCustomType=0 -InfoSerial=0 -InfoSerialReq=0 -SerialsCount=0 +HideOtherLanguages=0 +QueryText=0 +QueryTextName= +QueryTextReq=0 +QueryTextHide=0 +QueryCustom=0 +QueryCustomName= +QueryCustomReq=0 +QueryCustomHide=0 +QueryCustomType=0 +QueryCustomMustExists=0 +QueryKey=0 +QueryKeyName= +QueryKeyReq=0 +QueryKeyHide=0 +QueryKeyHideReg=0 +KeysCount=0 InfoCustomBox=0 InfoCustomBoxReq=0 InfoCustomBoxName= @@ -105,6 +112,7 @@ CustomComboBox=0 CustomComboBoxName= CustomComboBoxItems= CustomComboDefItem= +ComboBoxDisableOnUpgrade=0 CustomComponents=0 CustomComponentsText= CustomComponentsDesc= @@ -117,19 +125,27 @@ LaunchFile=1 LaunchFileName=\ShipBattle.exe LaunchFileChecked=1 LaunchFileAdmin=0 +FinishCurrentDir=1 CustomAction=0 CustomActionName=Visit Web Site CustomActionCommand= CustomActionChecked=0 CustomActionAdmin=0 -FinishCurrentDir=1 -TotalFiles=1 +TotalFiles=23 +SourceDirFiles=0 +SourceDirSize=0 [GUI] +FontName=Tahoma +LogoMode=1 +LogoOffset=0 +LogoIconSize=2 +Theme=0 +LogoAlignClient=1 LogoAutoSize=0 -LogoTransparent=0 LogoStretch=0 LogoProportional=0 +LogoTransparent=0 [Options] OptionUpdateFileVersion=0 @@ -142,16 +158,38 @@ OptionExcludeHiddenFiles=1 OptionExcludeEmptyFolders=1 OptionExcludeExtensions= OptionNoTreeView=0 -OptionRelativePath=0 +OptionRelativePath=1 OptionSignFile=0 OptionSignFileAll=0 OptionSignCommand=/K signtool sign /f MyCert.pfx "" [Files] 0=\Uninstall.exe?\Uninstall.exe?1?1 +1=installer\LICENSE.txt?\LICENSE.txt?1?1 +2=bin\Release\ShipBattle.exe?\ShipBattle.exe?1?1 +3=bin\Release\shader\ImageQuadPS.cso?\shader\ImageQuadPS.cso?1?1 +4=bin\Release\shader\ImageQuadVS.cso?\shader\ImageQuadVS.cso?1?1 +5=bin\Release\shader\RootSignature.cso?\shader\RootSignature.cso?1?1 +6=bin\res\screen_play.png?\res\screen_play.png?1?1 +7=bin\res\screen_start.png?\res\screen_start.png?1?1 +8=bin\res\stat_game_lost.png?\res\stat_game_lost.png?1?1 +9=bin\res\stat_game_win.png?\res\stat_game_win.png?1?1 +10=bin\res\stat_hit.png?\res\stat_hit.png?1?1 +11=bin\res\stat_nohit.png?\res\stat_nohit.png?1?1 +12=bin\res\stat_place_fleet.png?\res\stat_place_fleet.png?1?1 +13=bin\res\stat_place_shot.png?\res\stat_place_shot.png?1?1 +14=bin\res\stat_shot_traveling.png?\res\stat_shot_traveling.png?1?1 +15=bin\res\stat_wait_enemy.png?\res\stat_wait_enemy.png?1?1 +16=bin\res\tilemap.png?\res\tilemap.png?1?1 +17=bin\res\tr0.bad?\res\tr0.bad?1?1 +18=bin\res\tr1.bad?\res\tr1.bad?1?1 +19=bin\res\tr2.bad?\res\tr2.bad?1?1 +20=bin\res\tr3.bad?\res\tr3.bad?1?1 +21=bin\res\tr4.bad?\res\tr4.bad?1?1 +22=bin\res\tr5.bad?\res\tr5.bad?1?1 [Shortcuts] -0=*?*?\ShipBattle.exe*?*?*?*?*?0*?Normal -1=*?*?\ShipBattle.exe*?*?*?*?*?0*?Normal -2=*?Uninstall *?\Uninstall.exe*?*?*?*?*?0*?Normal +0=*?*?\ShipBattle.exe*?*?*?*?*?0*?Normal*?No +1=*?*?\ShipBattle.exe*?*?*?*?*?0*?Normal*?No +2=*?Uninstall *?\Uninstall.exe*?*?*?*?*?0*?Normal*?No diff --git a/src/game/tools/ShipFunctions.cpp b/src/game/tools/ShipFunctions.cpp index 3d56d99..d6ee0cf 100644 --- a/src/game/tools/ShipFunctions.cpp +++ b/src/game/tools/ShipFunctions.cpp @@ -3,10 +3,10 @@ bool ShipFunctions::shipCheckBounds(Ship* ptrShip) { if (ptrShip->isVertical) { - return ((ptrShip->posy + ptrShip->length) < 10); + return ((ptrShip->posy + ptrShip->length) <= 10); } else { - return ((ptrShip->posx + ptrShip->length) < 10); + return ((ptrShip->posx + ptrShip->length) <= 10); } } @@ -45,35 +45,8 @@ bool ShipFunctions::shipCheckCollision(Ship* arrShips, Ship* checker, unsigned i Ship* otherShip = &arrShips[i]; // Only for other ships - if (i != index) { - // Overlap [Vertical | Vertical] - if (otherShip->isVertical && placeShip->isVertical && - otherShip->posx == placeShip->posx && - ((placeShip->posy + placeShip->length >= otherShip->posy) || (otherShip->posy + otherShip->length >= placeShip->posy)) - ) { - return false; - } - // Overlap [Horizontal | Horizontal] - if (!otherShip->isVertical && !placeShip->isVertical && - otherShip->posy == placeShip->posy && - ((placeShip->posx + placeShip->length >= otherShip->posx) || (otherShip->posx + otherShip->length >= placeShip->posx)) - ) { - return false; - } - // Crossing other Vertical - if (otherShip->isVertical && - ((placeShip->posx <= otherShip->posx) && ((placeShip->posx + placeShip->length) >= otherShip->posx)) && - ((otherShip->posy <= placeShip->posy) && ((otherShip->posy + otherShip->length) >= placeShip->posy)) - ) { - return false; - } - // Crossing this Vertical - if (placeShip->isVertical && - ((otherShip->posx <= placeShip->posx) && ((otherShip->posx + otherShip->length) >= placeShip->posx)) && - ((placeShip->posy <= otherShip->posy) && ((placeShip->posy + placeShip->length) >= otherShip->posy)) - ) { - return false; - } + if (i != index && shipIntersect(placeShip, otherShip)) { + return false; } } @@ -150,3 +123,34 @@ void ShipFunctions::drawShips(Ship* arrShips, unsigned int count, QuadManger& ma } } } + +bool ShipFunctions::shipIntersect(Ship* s1, Ship* s2) +{ + // Line 1 + int l1x1 = s1->posx; + int l1y1 = s1->posy; + int l1x2 = s1->isVertical ? l1x1 : s1->posx + s1->length - 1; + int l1y2 = s1->isVertical ? s1->posy + s1->length - 1 : l1y1; + + // Line 2 + int l2x1 = s2->posx; + int l2y1 = s2->posy; + int l2x2 = s2->isVertical ? l2x1 : s2->posx + s2->length - 1; + int l2y2 = s2->isVertical ? s2->posy + s2->length - 1 : l2y1; + + /* + * Intersection test seen as AABB + * + * cs yo Conditions (or): + * xo a ------ o 1) b2 > a1 + * | s1 | 2) a2 > b1 + * | | + * o ------ b xo + * yo cs + */ + + // cs xo yo + if ((l2x2 < l1x1 && l2y2 < l1y1) || (l2x1 < l1x1 && l2x2 < l1x1) || (l2y1 < l1y1 && l2y2 < l1y1)) return false; + if ((l2x1 > l1x2 && l2y1 > l1y2) || (l2x1 > l1x2 && l2x2 > l1x2) || (l2y1 > l1y2 && l2y2 > l1y2)) return false; + return true; +} diff --git a/src/game/tools/ShipFunctions.h b/src/game/tools/ShipFunctions.h index f59ff06..40a07d1 100644 --- a/src/game/tools/ShipFunctions.h +++ b/src/game/tools/ShipFunctions.h @@ -15,4 +15,6 @@ class ShipFunctions { static void randomShips(Ship* arrShips, unsigned int count); static void drawShip(Ship* ship, QuadManger& manager); static void drawShips(Ship* arrShips, unsigned int count, QuadManger& manager); + + static bool shipIntersect(Ship* s1, Ship* s2); }; \ No newline at end of file diff --git a/src/gfx/GWindow.cpp b/src/gfx/GWindow.cpp index d9d937e..6def0c9 100644 --- a/src/gfx/GWindow.cpp +++ b/src/gfx/GWindow.cpp @@ -2,7 +2,7 @@ #include "GWindow.h" GWindow::GWindow(EasyHWND::WindowClass& wClass, ID3D12Device* ptrDevice, ID3D12CommandQueue* ptrQueue) - : EasyHWND::Window(wClass, L"Ship Battle V1.0 © Copyright 2021 by Ludwig Füchsl", 100, 100, 960, 540, WS_OVERLAPPEDWINDOW, WS_EX_OVERLAPPEDWINDOW), + : EasyHWND::Window(wClass, L"Ship Battle V1.1", 100, 100, 960, 540, WS_OVERLAPPEDWINDOW, WS_EX_OVERLAPPEDWINDOW | WS_EX_APPWINDOW), m_iostate({}) { HRESULT hr; @@ -115,6 +115,9 @@ bool GWindow::handleWindowMessage(LRESULT* ptrLRESULT, HWND hwnd, UINT msg, WPAR if (wParam == VK_RETURN) { m_iostate.enterIsDown = TRUE; } + else if (wParam == VK_F11) { + setFullscreen(!m_fullscreen); + } break; } @@ -242,6 +245,43 @@ GameIOState GWindow::getCurrentIOState() { return m_iostate; } +void GWindow::setFullscreen(bool fullscreen) +{ + // New styles + DWORD style = WS_OVERLAPPEDWINDOW | WS_VISIBLE, exStyle = WS_EX_OVERLAPPEDWINDOW | WS_EX_APPWINDOW; + if (fullscreen) + { + style = WS_POPUP | WS_VISIBLE; + exStyle = WS_EX_APPWINDOW; + } + + // Update style + SetWindowLong((HWND)*this, GWL_STYLE, (LONG)style); + SetWindowLong((HWND)*this, GWL_EXSTYLE, (LONG)exStyle); + + // Update bounds + if (fullscreen) + { + auto monitor = MonitorFromWindow((HWND)*this, MONITOR_DEFAULTTONEAREST); + MONITORINFO info{}; + info.cbSize = sizeof(MONITORINFO); + if (GetMonitorInfo(monitor, &info)) + { + AdjustWindowRectEx(&info.rcMonitor, style, false, exStyle); + SetWindowPos((HWND)*this, nullptr, info.rcMonitor.left, info.rcMonitor.top, info.rcMonitor.right - info.rcMonitor.left, info.rcMonitor.bottom - info.rcMonitor.top, SWP_NOZORDER); + } + } + else + { + ShowWindow((HWND)*this, SW_MAXIMIZE); + } + + // Update window + UpdateWindow((HWND)*this); + + m_fullscreen = fullscreen; +} + void GWindow::createDepthBuffer(ID3D12Device* device) { HRESULT hr; diff --git a/src/gfx/GWindow.h b/src/gfx/GWindow.h index 322b8fd..cd490f2 100644 --- a/src/gfx/GWindow.h +++ b/src/gfx/GWindow.h @@ -22,6 +22,8 @@ class GWindow : public EasyHWND::Window{ inline int getWidth() const { return m_width; } inline int getHeight() const { return m_height; } + void setFullscreen(bool fullscreen); + private: void createDepthBuffer(ID3D12Device* device); void destroyDepthBuffer(); @@ -33,6 +35,7 @@ class GWindow : public EasyHWND::Window{ GameIOState m_iostate; bool m_needsResize = false; + bool m_fullscreen = false; unsigned int m_heapIncrement = 0; diff --git a/src/wWinMain.cpp b/src/wWinMain.cpp index 136cc95..923d6ae 100644 --- a/src/wWinMain.cpp +++ b/src/wWinMain.cpp @@ -45,12 +45,13 @@ INT WINAPI wWinMain(HINSTANCE _In_ hInstance, HINSTANCE _In_opt_ hPrevInstance, GContext ctx; // Window - EasyHWND::WindowClass cls(L"ShipBattle_WND", CS_OWNDC); + EasyHWND::WindowClass cls(L"ShipBattle_WND", CS_OWNDC, LoadIcon(NULL, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW)); GWindow wnd(cls, ctx.getDevice(), ctx.getQueue()); wnd.setWindowVisibility(true); // Maximize ShowWindow((HWND)wnd, SW_MAXIMIZE); + wnd.setFullscreen(true); // Upload buffer GBuffer uploadBuffer(ctx.getDevice(), D3D12_HEAP_TYPE_UPLOAD);