-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
149 lines (116 loc) · 3.05 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "MYCLIENT.h"
MyClient *client = new MyClient();
#include <windows.h>
#include <windowsx.h>
#include <chrono>
#include "MainMenu.h"
#include "Instructions.h"
#include "Options.h"
#include "Backstory.h"
#include "Credits.h"
#include "Win.h"
#include "Lose.h"
#include "OnePlayer.h"
#include "TwoPlayer.h"
// external Device
IDirect3DDevice9 *Device = 0;
// external sound engine
Sound *SoundEngine = new Sound();
// external controller
Controller *controller = new Controller();
// external game states
GameState *currentState = 0;
GameState *previousState = 0;
GameState *menu = new MainMenu();
GameState *instructions = new Instructions();
GameState *options = new Options();
GameState *backstory = new Backstory();
GameState *credits = new Credits();
GameState *win = new Win();
GameState *lose = new Lose();
GameState *onePlayer = new OnePlayer();
GameState *twoPlayer = new TwoPlayer();
//----------------------
// Window Proc
//----------------------
LRESULT CALLBACK D3D::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
static HICON hIcon;
switch (msg) {
case WM_KEYDOWN:
if (wParam == VK_ESCAPE) {
PostQuitMessage(0);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
//----------------------
// Main Function
//----------------------
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR cmdLine, int showCmd) {
// variables for timer
std::chrono::time_point<std::chrono::system_clock> currentTime, lastTime;
std::chrono::duration<double> deltaTime;
// set current state
currentState = menu;
// Initialize Sound Engine
SoundEngine->Initialize();
// Initialize Direct3D
if (!D3D::InitD3D(hinstance))
return 0;
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
currentState->Enter();
while (msg.message != WM_QUIT) {
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE) && !IsDialogMessage(NULL, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
lastTime = std::chrono::system_clock::now();
}
else {
currentTime = std::chrono::system_clock::now();
deltaTime = lastTime - currentTime;
currentState->GameLoop((float)-deltaTime.count());
lastTime = currentTime;
srand(time(NULL));
}
}
Device->Release();
return (int)msg.wParam;
}
//----------------------
// Dialog Proc
//----------------------
INT_PTR CALLBACK Options::DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
Static_SetText(GetDlgItem(hwnd, IDC_STATIC1), "Server IP Address:");
Static_SetText(GetDlgItem(hwnd, IDC_IPADDRESS1), client->HOST_IP);
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
// get the ip address in the ip address control box and close the dialog
Static_GetText(GetDlgItem(hwnd, IDC_IPADDRESS1), client->HOST_IP, sizeof(client->HOST_IP) + 1);
EndDialog(hwnd, 0);
break;
case IDCANCEL:
EndDialog(hwnd, 0);
break;
default:
break;
}
break;
case WM_CLOSE:
EndDialog(hwnd, 0);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return FALSE;
}