-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
150 lines (118 loc) · 4.48 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
150
/* png example for KOS 1.1.x
* hacked up to shit by futurepr0n
*/
#include <kos.h>
#include <iostream>
#include <png/png.h>
#include <zlib/zlib.h>
#include <mp3/sndserver.h>
#include <modplug/stdafx.h>
#include <modplug/sndfile.h>
#include "loadobj.hpp"
#include "initstorysplash.hpp"
#include "blitobj.hpp"
#include "movement.hpp"
#include "audio_system.h"
#include "renderer.hpp"
#include "game_utils.hpp"
#include "menu_system.hpp"
#include "name_selection.hpp"
#include "game_state.hpp"
#include "game_constants.hpp"
#include "endgamesplash.hpp"
#include <cmath>
#include <chrono>
int mybullets = 0;
int main(int argc, char **argv) {
/* init kos */
pvr_init_defaults();
while(1) { // Main game loop
resetGameState();
cleanupTextures();
int done = 0;
gameCompleted = false; // Reset game completion flag
/* controller initialization */
maple_device_t *cont;
cont_state_t *state;
load_font_texture();
/* init splash screen */
initSplash();
std::string playerName = showMainMenu();
GameState::getInstance().setPlayerName(playerName);
GameState::getInstance().resetScore();
std::cout << "Debug - Player name set to: " << GameState::getInstance().getPlayerName() << std::endl;
initStorySplash();
// Load enemy textures before loading character data
loadEnemyTextures();
loadPlayerTextures();
loadEnemyBattlestarTextures();
loadCharacterData(); // loadobj.cpp
if (!g_audioSystem.initialize("/rd/mrdeath.xm")) {
printf("Failed to initialize audio system\n");
return 1;
}
while(!gameCompleted) {
draw_scene();
cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
if(cont) {
state = (cont_state_t *)maple_dev_status(cont);
if(state) {
bool moving_diagonal = false;
float dx = 0.0f;
float dy = 0.0f;
float current_speed = BASE_PLAYER_SPEED * player.speed_multiplier;
// Handle joystick input with deadzone and normalized movement
if (abs(state->joyx) > 10 || abs(state->joyy) > 10) {
float joy_x = state->joyx / 128.0f;
float joy_y = state->joyy / 128.0f;
if (fabsf(joy_x) < 0.1f) joy_x = 0.0f;
if (fabsf(joy_y) < 0.1f) joy_y = 0.0f;
if (joy_x != 0.0f && joy_y != 0.0f) {
moving_diagonal = true;
}
dx = joy_x * current_speed;
dy = joy_y * current_speed;
}
else {
if (state->buttons & CONT_DPAD_LEFT) dx = -current_speed;
if (state->buttons & CONT_DPAD_RIGHT) dx = current_speed;
if (state->buttons & CONT_DPAD_UP) dy = -current_speed;
if (state->buttons & CONT_DPAD_DOWN) dy = current_speed;
if (dx != 0.0f && dy != 0.0f) {
moving_diagonal = true;
}
}
if (moving_diagonal) {
dx *= DIAGONAL_COMPENSATION;
dy *= DIAGONAL_COMPENSATION;
}
float new_x = player.x + dx;
float new_y = player.y + dy;
if (new_x >= player.imgX/2 && new_x <= 640 - player.imgX/2) {
player.x = new_x;
}
if (new_y >= player.imgY/2 && new_y <= 480 - player.imgY/2) {
player.y = new_y;
}
if (state->buttons & CONT_A) {
player.speed_multiplier = BOOST_MULTIPLIER;
} else {
player.speed_multiplier = 1.0f;
}
if(state->buttons & CONT_B)
shootChain();
}
}
g_audioSystem.update();
updateEnemyWaves();
timer_spin_sleep(10);
}
g_audioSystem.cleanup();
// Unload textures
unloadEnemyTextures();
unloadPlayerTextures();
unloadEnemyBattlestarTextures();
showVictoryScreen();
}
return 0;
}