2023-07-06 22:02:37 +02:00
|
|
|
|
2024-07-29 21:04:23 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "events.h"
|
|
|
|
#include "npc.h"
|
|
|
|
|
|
|
|
#include <fxlibc/printf.h>
|
2024-07-29 11:36:11 +02:00
|
|
|
#include <gint/cpu.h>
|
2023-07-05 23:22:15 +02:00
|
|
|
#include <gint/display.h>
|
|
|
|
#include <gint/keyboard.h>
|
2023-07-08 20:07:34 +02:00
|
|
|
#include <gint/timer.h>
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2023-07-08 20:07:34 +02:00
|
|
|
#if USB_FEATURE
|
2024-07-29 11:36:11 +02:00
|
|
|
#include <gint/usb-ff-bulk.h>
|
|
|
|
#include <gint/usb.h>
|
|
|
|
#endif // USB_FEATURE
|
2023-07-05 23:22:15 +02:00
|
|
|
|
2023-07-18 19:47:47 +02:00
|
|
|
#if GRAYMODEOK
|
2024-07-29 11:36:11 +02:00
|
|
|
#include <gint/gray.h>
|
|
|
|
#endif // GRAYMODEOK
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2024-07-29 21:04:23 +02:00
|
|
|
#include "dialogs.h"
|
2023-07-08 15:55:06 +02:00
|
|
|
#include "game.h"
|
2023-07-07 14:20:13 +02:00
|
|
|
#include "mapdata.h"
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2024-07-29 21:04:23 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2023-07-09 22:02:59 +02:00
|
|
|
|
|
|
|
extern bopti_image_t player_face_img;
|
|
|
|
|
2023-08-16 17:34:45 +02:00
|
|
|
extern Map *worldRPG[];
|
2023-08-08 09:46:07 +02:00
|
|
|
|
2023-07-08 15:55:06 +02:00
|
|
|
/* Game data (defined in "game.h")*/
|
2024-07-29 11:36:11 +02:00
|
|
|
Game game = {NULL,
|
|
|
|
{12 * PXSIZE, 36 * PXSIZE, 0, 0, 12 * PXSIZE, 36 * PXSIZE, 100,
|
|
|
|
SPEED, false, 0, false, false, true},
|
|
|
|
{{}, {}, 0},
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
0
|
|
|
|
|
|
|
|
/* debug variables*/
|
|
|
|
,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
100};
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2024-07-24 21:43:21 +02:00
|
|
|
/* screen capture management code. TODO: Clean this up! */
|
2023-07-06 22:49:29 +02:00
|
|
|
|
2023-07-18 19:47:47 +02:00
|
|
|
#if USB_FEATURE
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
void USB_feature(void) {
|
|
|
|
if(game.screenshot && usb_is_open()) {
|
2023-07-07 18:22:39 +02:00
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
#if GRAYMODEOK // This is a trick, if GRAYMODEOK is defined then
|
|
|
|
// we make the code accessible
|
2023-07-07 18:22:39 +02:00
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
if(dgray_enabled())
|
|
|
|
usb_fxlink_screenshot_gray(false);
|
|
|
|
else
|
2023-07-07 18:22:39 +02:00
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
#endif
|
2023-07-07 18:22:39 +02:00
|
|
|
|
2023-07-09 21:53:07 +02:00
|
|
|
// else we just let the usual screeshot function
|
2024-07-29 11:36:11 +02:00
|
|
|
usb_fxlink_screenshot(false);
|
|
|
|
game.screenshot = false;
|
|
|
|
}
|
2023-07-07 14:20:13 +02:00
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
if(game.record && usb_is_open()) {
|
2023-07-07 18:22:39 +02:00
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
#if GRAYMODEOK
|
2023-07-07 18:22:39 +02:00
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
if(dgray_enabled())
|
|
|
|
usb_fxlink_videocapture_gray(false);
|
|
|
|
else
|
2023-07-07 18:22:39 +02:00
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
#endif
|
2023-07-07 18:22:39 +02:00
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
usb_fxlink_videocapture(false);
|
|
|
|
}
|
2024-07-29 11:36:11 +02:00
|
|
|
}
|
2023-07-05 23:22:15 +02:00
|
|
|
|
2023-07-06 22:02:37 +02:00
|
|
|
#endif
|
2023-07-05 23:22:15 +02:00
|
|
|
|
2023-07-08 20:07:34 +02:00
|
|
|
/* Timer callback */
|
|
|
|
|
|
|
|
int update_time(void) {
|
|
|
|
game.frame_duration++;
|
|
|
|
return TIMER_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2023-07-07 14:50:30 +02:00
|
|
|
int main(void) {
|
2024-07-29 11:36:11 +02:00
|
|
|
|
2023-08-26 17:13:05 +02:00
|
|
|
__printf_enable_fp();
|
2024-07-29 11:36:11 +02:00
|
|
|
|
2023-07-08 20:07:34 +02:00
|
|
|
int timer;
|
|
|
|
timer = timer_configure(TIMER_TMU, 1000, GINT_CALL(update_time));
|
2024-07-29 11:36:11 +02:00
|
|
|
if(timer < 0) {
|
2023-07-08 20:07:34 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
timer_start(timer);
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2023-08-10 18:33:17 +02:00
|
|
|
game.map_level = worldRPG[0];
|
2024-07-20 16:53:13 +02:00
|
|
|
events_init_handler(&game.handler);
|
2024-07-29 11:36:11 +02:00
|
|
|
events_bind_variable(&game.handler, (int *)&game.player.life, "life");
|
2024-07-20 16:53:13 +02:00
|
|
|
events_bind_variable(&game.handler, &game.mana, "mana");
|
2023-08-10 16:22:31 +02:00
|
|
|
|
2023-08-26 17:13:05 +02:00
|
|
|
reload_npc(&game);
|
2023-08-10 16:22:31 +02:00
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
#if USB_FEATURE
|
|
|
|
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
|
|
|
|
usb_open(interfaces, GINT_CALL_NULL);
|
|
|
|
#endif
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
/* start grayscale engine */
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
#if GRAYMODEOK
|
|
|
|
dgray(DGRAY_ON);
|
|
|
|
#endif
|
2023-07-06 22:49:29 +02:00
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
do {
|
2024-07-30 17:49:40 +02:00
|
|
|
/*clears & renders everything */
|
2024-07-25 13:07:19 +02:00
|
|
|
game_draw(&game);
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2024-07-30 17:49:40 +02:00
|
|
|
dprint(0,30,0,"draw time : %d", game.frame_duration);
|
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
#if DEBUGMODE && GINT_RENDER_RGB
|
|
|
|
if(game.debug_map) {
|
|
|
|
dfont(NULL);
|
|
|
|
drect(5, 5, 390, 55, C_WHITE);
|
|
|
|
dprint(10, 10, C_RED, "Map[%d] : Xmn %d Ymn %d Xmx %d Ymx %d", 0,
|
|
|
|
worldRPG[0]->xmin, worldRPG[0]->ymin, worldRPG[0]->xmax,
|
|
|
|
worldRPG[0]->ymax);
|
|
|
|
dprint(10, 20, C_RED, "Map[%d] : Xmn %d Ymn %d Xmx %d Ymx %d", 1,
|
|
|
|
worldRPG[1]->xmin, worldRPG[1]->ymin, worldRPG[1]->xmax,
|
|
|
|
worldRPG[1]->ymax);
|
|
|
|
dprint(10, 30, C_RED, "Map[%d] : Xmn %d Ymn %d Xmx %d Ymx %d", 2,
|
|
|
|
worldRPG[2]->xmin, worldRPG[2]->ymin, worldRPG[2]->xmax,
|
|
|
|
worldRPG[2]->ymax);
|
|
|
|
dprint(10, 40, C_RED, "Map[%d] : Xmn %d Ymn %d Xmx %d Ymx %d", 3,
|
|
|
|
worldRPG[3]->xmin, worldRPG[3]->ymin, worldRPG[3]->xmax,
|
|
|
|
worldRPG[3]->ymax);
|
|
|
|
}
|
|
|
|
if(game.debug_player) {
|
|
|
|
dfont(NULL);
|
|
|
|
drect(5, 55, 390, 75, C_WHITE);
|
|
|
|
dprint(10, 60, C_BLUE, "X= %d - Y= %d / Wx= %d - Wy= %d",
|
|
|
|
game.player.x, game.player.y, game.player.wx,
|
|
|
|
game.player.wy);
|
|
|
|
}
|
|
|
|
if(game.debug_extra) {
|
|
|
|
dfont(NULL);
|
|
|
|
for(int i = 0; i < game.map_level->nbextradata; i++)
|
|
|
|
dprint(10, 90 + i * 15, C_RED,
|
|
|
|
"X= %d - Y= %d - T: %d - ID: %d - S: %c",
|
|
|
|
game.map_level->extradata[i].x,
|
|
|
|
game.map_level->extradata[i].y,
|
|
|
|
game.map_level->extradata[i].dialogID,
|
|
|
|
game.map_level
|
|
|
|
->dialogs[game.map_level->extradata[i].dialogID]
|
|
|
|
.ID,
|
|
|
|
game.map_level
|
|
|
|
->dialogs[game.map_level->extradata[i].dialogID]
|
|
|
|
.conclusion1[0]);
|
|
|
|
}
|
|
|
|
#endif
|
2023-08-10 16:22:31 +02:00
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
/* start the logic of the game */
|
2023-07-08 15:55:06 +02:00
|
|
|
game_logic(&game);
|
2023-07-06 22:49:29 +02:00
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
/* Screen blit */
|
|
|
|
dupdate();
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
/* Screen capture feature if enabled */
|
|
|
|
#if USB_FEATURE
|
|
|
|
USB_feature();
|
|
|
|
#endif
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
/* Management of the inputs */
|
2024-07-25 13:07:19 +02:00
|
|
|
game_get_inputs(&game);
|
2023-07-08 20:07:34 +02:00
|
|
|
/* Run the game at max. 50fps */
|
2024-07-29 11:36:11 +02:00
|
|
|
while(game.frame_duration < 20)
|
|
|
|
sleep();
|
2023-07-08 20:07:34 +02:00
|
|
|
/* Reset frame_duration for the next frame */
|
|
|
|
game.frame_duration = 0;
|
2024-07-29 11:36:11 +02:00
|
|
|
} while(!game.exittoOS); // want to exit ?
|
2023-07-06 21:16:07 +02:00
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
/* shutdown grayengine*/
|
|
|
|
#if GRAYMODEOK
|
|
|
|
dgray(DGRAY_OFF);
|
|
|
|
#endif
|
2023-07-06 22:49:29 +02:00
|
|
|
|
2024-07-29 11:36:11 +02:00
|
|
|
/* close USB */
|
|
|
|
#if USB_FEATURE
|
|
|
|
usb_close();
|
|
|
|
#endif
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2023-07-08 20:07:34 +02:00
|
|
|
timer_stop(timer);
|
2023-07-07 14:20:13 +02:00
|
|
|
return 1;
|
2023-07-05 23:22:15 +02:00
|
|
|
}
|