-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathiMain.cpp
More file actions
311 lines (252 loc) · 8.71 KB
/
iMain.cpp
File metadata and controls
311 lines (252 loc) · 8.71 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#include "iGraphics.h"
#include "menu.hpp"
#include "character.hpp"
#include "pause.hpp"
#include "ai.hpp"
#include "arcade.hpp"
Character captainAmericaP1;
Character captainAmericaP2;
int loadingScreen;
// Loading screen variables
int loadingBarWidth = 0;
bool loadingDone = false;
bool goToMainMenu = false;
bool blinkTextWhite = true;
static bool assetsLoaded = false;
int previousScreen = -1; // To track screen transitions
// had to declare the function definition here otherwise it was not working
void loadingScreenText();
void iDraw()
{
iClear();
if (!goToMainMenu)
{
// Show loading screen
iShowImage(0, 10, SCREEN_WIDTH, SCREEN_HEIGHT, loadingScreen);
startMainMenuMusic(); // Starting Main Menu Music
// Loading bar frame and fill
iSetColor(255, 60, 60);
iRectangle(390, 35, 500, 25);
iFilledRectangle(390, 35, loadingBarWidth, 25);
loadingScreenText();
}
else
{
// Show the actual menu screen after loading
showMenu();
// On the gameplay screen, render Character
if (currentScreen == 20){
showArenaImages();
if(selectedCharacterIndexP1 == 2) captainAmericaP1.draw();
if(selectedCharacterIndexP2 == 2) captainAmericaP2.draw();
// paused button
iShowImage(pauseButton.x, pauseButton.y, pauseButton.width, pauseButton.height, pauseButtonImage);
// If the game is paused, show the pause menu
if (currentGameState == PAUSED) {
showPauseMenu();
}
}
else if (currentScreen == 30){
showDynamicArenaBG();
if (selectedCharacterIndexP1 == 2) captainAmericaP1.draw();
drawArcadeAI();
// paused button
iShowImage(pauseButton.x, pauseButton.y, pauseButton.width, pauseButton.height, pauseButtonImage);
// If the game is paused, show the pause menu
if (currentGameState == PAUSED) {
showPauseMenu();
}
}
}
}
void iMouseMove(int mx, int my)
{
}
void iPassiveMouseMove(int mx, int my)
{
if (goToMainMenu) {
// If in game and paused, handle pause menu hover
if ((currentScreen == 20 || currentScreen == 30) && currentGameState == PAUSED) {
handlePauseHoverAnimation(mx, my);
}
else {
// Handle main menu hover Animation
handleHoverAnimation(mx, my);
}
}
}
void iMouse(int button, int state, int mx, int my)
{
if (goToMainMenu) {
if (currentScreen == 20) { // Clicks inside the 1v1 arena screen
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
if (currentGameState == PAUSED) {
// If paused, check for clicks on the pause menu
int clickedButtonIndex = handlePauseMenuClick(mx, my);
if (clickedButtonIndex == 0) { // Resume
currentGameState = PLAYING;
}
else if (clickedButtonIndex == 1) { // Restart
resetCharacters(captainAmericaP1, captainAmericaP2);
currentGameState = PLAYING;
}
else if (clickedButtonIndex == 2) { // Character Selection
resetCharacters(captainAmericaP1, captainAmericaP2);
currentScreen = 10; // Go back to character selection
currentGameState = PLAYING; // Reset state for next time
}
}
else {
// If playing, check for clicks on the main pause button
if (mx >= pauseButton.x && mx <= pauseButton.x + pauseButton.width &&
my >= pauseButton.y && my <= pauseButton.y + pauseButton.height) {
currentGameState = PAUSED;
}
}
}
}
// Clicks inside the Arcade Mode arena screen
else if (currentScreen == 30) {
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
if (currentGameState == PAUSED) {
// If paused, check for clicks on the pause menu
int clickedButtonIndex = handlePauseMenuClick(mx, my);
if (clickedButtonIndex == 0) { // Resume
currentGameState = PLAYING;
}
else if (clickedButtonIndex == 1) { // Restart
resetArcadePlayer(captainAmericaP1, arcadeAI);
currentGameState = PLAYING;
}
else if (clickedButtonIndex == 2) { // Character Selection
resetArcadePlayer(captainAmericaP1, arcadeAI);
currentScreen = 11; // Go back to arcade character selection
currentGameState = PLAYING; // Reset state for next time
}
}
else {
// If playing, check for clicks on the main pause button
if (mx >= pauseButton.x && mx <= pauseButton.x + pauseButton.width &&
my >= pauseButton.y && my <= pauseButton.y + pauseButton.height) {
currentGameState = PAUSED;
}
}
}
}
else {
// Handle menu clicks only after the loading screen
handleMenuClick(button, state, mx, my);
}
}
}
// This function runs at a fixed interval
// Special Keys:
// GLUT_KEY_F1, GLUT_KEY_F2, GLUT_KEY_F3, GLUT_KEY_F4, GLUT_KEY_F5, GLUT_KEY_F6, GLUT_KEY_F7, GLUT_KEY_F8, GLUT_KEY_F9, GLUT_KEY_F10, GLUT_KEY_F11, GLUT_KEY_F12,
// GLUT_KEY_LEFT, GLUT_KEY_UP, GLUT_KEY_RIGHT, GLUT_KEY_DOWN, GLUT_KEY_PAGE UP, GLUT_KEY_PAGE DOWN, GLUT_KEY_HOME, GLUT_KEY_END, GLUT_KEY_INSERT
void fixedUpdate() {
if (!goToMainMenu || currentGameState == PAUSED) return;
// Versus Mode (screen 20) - Both players
if (currentScreen == 20) {
// Player 1 controls (WASD + FEQ)
handleInputMovement(captainAmericaP1, isKeyPressed('d'), isKeyPressed('a'));
handleDefaultState(captainAmericaP1, isKeyPressed('d'), isKeyPressed('a'));
handleJump(captainAmericaP1, isKeyPressed('w'));
handleAttack(captainAmericaP1, isKeyPressed('f'));
handleUltimate(captainAmericaP1, isKeyPressed('q'));
// Player 2 controls (Arrow keys + )
handleInputMovement(captainAmericaP2, isSpecialKeyPressed(GLUT_KEY_RIGHT), isSpecialKeyPressed(GLUT_KEY_LEFT));
handleDefaultState(captainAmericaP2, isSpecialKeyPressed(GLUT_KEY_RIGHT), isSpecialKeyPressed(GLUT_KEY_LEFT));
handleJump(captainAmericaP2, isSpecialKeyPressed(GLUT_KEY_UP));
handleAttack(captainAmericaP2, isSpecialKeyPressed(GLUT_KEY_DOWN));
handleUltimate(captainAmericaP2, isKeyPressed('0'));
}
// Arcade Mode (screen 30) - Only Player 1
else if (currentScreen == 30) {
handleInputMovement(captainAmericaP1, isKeyPressed('d'), isKeyPressed('a'));
handleDefaultState(captainAmericaP1, isKeyPressed('d'), isKeyPressed('a'));
handleJump(captainAmericaP1, isKeyPressed('w'));
handleAttack(captainAmericaP1, isKeyPressed('f'));
handleUltimate(captainAmericaP1, isKeyPressed('q'));
updateBackgroundScroll(captainAmericaP1);
// AI Controls
handleJump(arcadeAI, false);
handleAI(arcadeAI, captainAmericaP1);
}
}
// Handles the loading bar animation on loading screen
void loadingBar(){
if (!loadingDone){
loadingBarWidth += 15;
if (loadingBarWidth >= 500){
loadingBarWidth = 500;
loadingDone = true;
}
}
else{
if (isKeyPressed(' ')){
goToMainMenu = true;
// Load menu
if (mainMenuScreen == -1){
loadMenuAssets();
loadCharacterSelectionAssets();
loadCharacterSelectionAssetsForArcade();
loadArenaAssets();
loadPauseAssets();
loadDynamicArenaBG();
}
}
}
}
void loadingScreenText(){
// If loading done, show text prompt
if (loadingDone){
if (blinkTextWhite) {
iSetColor(255, 255, 255); // white
}
else {
iSetColor(0, 0, 0); // black
}
iText(530, 80, "Press SPACE to continue", GLUT_BITMAP_HELVETICA_18);
}
else{
iSetColor(255, 255, 255);
iText(390, 70, "Loading...", GLUT_BITMAP_HELVETICA_18);
}
}
void toggleBlinkColor() {
blinkTextWhite = !blinkTextWhite;
}
void updateCharacters() {
// Only update character animations if the game is playing
if (currentScreen == 20 && currentGameState == PLAYING){
if(selectedCharacterIndexP1 == 2) captainAmericaP1.update();
if(selectedCharacterIndexP2 == 2) captainAmericaP2.update();
// ironMan.update();
}
else if (currentScreen == 30 && currentGameState == PLAYING){
if (selectedCharacterIndexP1 == 2) captainAmericaP1.update();
updateArcadeCharacters();
}
}
int main()
{
// Initialize graphics window
iInitialize(SCREEN_WIDTH, SCREEN_HEIGHT, "Marvel Mayhem");
//loading screen background image
loadingScreen = iLoadImage("BG/loading3.png");
loadArcadeCharacters();
loadCaptainAmerica(captainAmericaP1);
loadCaptainAmerica(captainAmericaP2);
captainAmericaP1.moveX = 200; // Player 1 starts on the left
captainAmericaP1.facingRight = true; // Player 1 faces right
captainAmericaP2.moveX = 980; // Player 2 starts on the right
captainAmericaP2.facingRight = false; // Player 2 faces left
iSetTimer(350, toggleBlinkColor); // 350 ms = 0.35 sec toggle
iSetTimer(10, loadingBar);
iSetTimer(25, fixedUpdate);
iSetTimer(100, updateCharacters);
iSetTimer(100, loadArenaAssets);
iSetTimer(100, loadDynamicArenaBG);
iStart(); // Start the graphics engine
return 0;
}