Skip to content

Commit

Permalink
Final bugfixes
Browse files Browse the repository at this point in the history
Fullscreen mode (Borderless)
New AI version
  • Loading branch information
Ohjurot committed Apr 17, 2023
1 parent f80e667 commit 1015b47
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 62 deletions.
96 changes: 67 additions & 29 deletions installer/ShipBattle.aip → ShipBattle.aip
Original file line number Diff line number Diff line change
@@ -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=<ProgramFiles>\<AppName>
MainExe=<InstallDir>\ShipBattle.exe
ProgramGroup=<AppName>
Uninstall=1
ShowAddRemove=1
ProductIcon=0
SilentUninstall=0
UninstallForce=0
UninstallRestart=0
Expand Down Expand Up @@ -63,12 +65,11 @@ AltInstallDir=<ProgramFiles>\<AppName>
DataExtractParam=-o"<InstallDir>" -aoa
UninstallFileName=Uninstall.exe
LangIDMethod=0
AllowInstallIfNoSpace=0
AllowInstallIfPrereqFailed=0
SetupParameters=
Theme=1
WizardBitmap=<AIDir>\Bitmaps\Wizard\02.bmp
HeaderBitmap=<AIDir>\Bitmaps\Header\03.bmp
WizardBitmap=<AIDir>\Bitmaps\Wizard\New.bmp
HeaderBitmap=<AIDir>\Bitmaps\Header\New.bmp
LogoBitmap=<AIDir>\Bitmaps\Logo\01.bmp
DialogWelcome=1
DialogLicense=1
Expand All @@ -81,30 +82,37 @@ 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=
CustomComboBox=0
CustomComboBoxName=
CustomComboBoxItems=
CustomComboDefItem=
ComboBoxDisableOnUpgrade=0
CustomComponents=0
CustomComponentsText=
CustomComponentsDesc=
Expand All @@ -117,19 +125,27 @@ LaunchFile=1
LaunchFileName=<InstallDir>\ShipBattle.exe
LaunchFileChecked=1
LaunchFileAdmin=0
FinishCurrentDir=1
CustomAction=0
CustomActionName=Visit Web Site
CustomActionCommand=<WebSite>
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
Expand All @@ -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 "<SetupExe>"

[Files]
0=<AIDir>\Uninstall.exe?<InstallDir>\Uninstall.exe?1?1
1=installer\LICENSE.txt?<InstallDir>\LICENSE.txt?1?1
2=bin\Release\ShipBattle.exe?<InstallDir>\ShipBattle.exe?1?1
3=bin\Release\shader\ImageQuadPS.cso?<InstallDir>\shader\ImageQuadPS.cso?1?1
4=bin\Release\shader\ImageQuadVS.cso?<InstallDir>\shader\ImageQuadVS.cso?1?1
5=bin\Release\shader\RootSignature.cso?<InstallDir>\shader\RootSignature.cso?1?1
6=bin\res\screen_play.png?<InstallDir>\res\screen_play.png?1?1
7=bin\res\screen_start.png?<InstallDir>\res\screen_start.png?1?1
8=bin\res\stat_game_lost.png?<InstallDir>\res\stat_game_lost.png?1?1
9=bin\res\stat_game_win.png?<InstallDir>\res\stat_game_win.png?1?1
10=bin\res\stat_hit.png?<InstallDir>\res\stat_hit.png?1?1
11=bin\res\stat_nohit.png?<InstallDir>\res\stat_nohit.png?1?1
12=bin\res\stat_place_fleet.png?<InstallDir>\res\stat_place_fleet.png?1?1
13=bin\res\stat_place_shot.png?<InstallDir>\res\stat_place_shot.png?1?1
14=bin\res\stat_shot_traveling.png?<InstallDir>\res\stat_shot_traveling.png?1?1
15=bin\res\stat_wait_enemy.png?<InstallDir>\res\stat_wait_enemy.png?1?1
16=bin\res\tilemap.png?<InstallDir>\res\tilemap.png?1?1
17=bin\res\tr0.bad?<InstallDir>\res\tr0.bad?1?1
18=bin\res\tr1.bad?<InstallDir>\res\tr1.bad?1?1
19=bin\res\tr2.bad?<InstallDir>\res\tr2.bad?1?1
20=bin\res\tr3.bad?<InstallDir>\res\tr3.bad?1?1
21=bin\res\tr4.bad?<InstallDir>\res\tr4.bad?1?1
22=bin\res\tr5.bad?<InstallDir>\res\tr5.bad?1?1

[Shortcuts]
0=<ProgramGroup>*?<AppName>*?<InstallDir>\ShipBattle.exe*?*?*?<InstallDir>*?*?0*?Normal
1=<Desktop>*?<AppName>*?<InstallDir>\ShipBattle.exe*?*?*?<InstallDir>*?*?0*?Normal
2=<ProgramGroup>*?Uninstall <AppName>*?<InstallDir>\Uninstall.exe*?*?*?<InstallDir>*?*?0*?Normal
0=<ProgramGroup>*?<AppName>*?<InstallDir>\ShipBattle.exe*?*?*?<InstallDir>*?*?0*?Normal*?No
1=<Desktop>*?<AppName>*?<InstallDir>\ShipBattle.exe*?*?*?<InstallDir>*?*?0*?Normal*?No
2=<ProgramGroup>*?Uninstall <AppName>*?<InstallDir>\Uninstall.exe*?*?*?<InstallDir>*?*?0*?Normal*?No

66 changes: 35 additions & 31 deletions src/game/tools/ShipFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/game/tools/ShipFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
42 changes: 41 additions & 1 deletion src/gfx/GWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/gfx/GWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/wWinMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BYTE, 1024 * 1024 * 32> uploadBuffer(ctx.getDevice(), D3D12_HEAP_TYPE_UPLOAD);
Expand Down

0 comments on commit 1015b47

Please sign in to comment.