#include #include #include #include #include #include "config.h" #include "npc.h" #include "events.h" #if USB_FEATURE #include #include #endif //USB_FEATURE #if GRAYMODEOK #include #endif //GRAYMODEOK #include #include #include "game.h" #include "mapdata.h" #include "dialogs.h" extern bopti_image_t player_face_img; extern Map *worldRPG[]; /* Game data (defined in "game.h")*/ Game game = { NULL, {12*PXSIZE, 36*PXSIZE, 0, 0, 12*PXSIZE, 36*PXSIZE, 100, SPEED, false, 0, false, false}, {{}, {}, 0}, false, false, false, 0 /* debug variables*/ , false, false, false, 100 }; /* screen capture management code */ #if USB_FEATURE void USB_feature( void ) { if (game.screenshot && usb_is_open()) { #if GRAYMODEOK // This is a trick, if GRAYMODEOK is defined then // we make the code accessible if (dgray_enabled()) usb_fxlink_screenshot_gray(false); else #endif // else we just let the usual screeshot function usb_fxlink_screenshot(false); game.screenshot = false; } if (game.record && usb_is_open()) { #if GRAYMODEOK if (dgray_enabled()) usb_fxlink_videocapture_gray(false); else #endif usb_fxlink_videocapture(false); } } #endif /* Timer callback */ int update_time(void) { game.frame_duration++; return TIMER_CONTINUE; } int main(void) { __printf_enable_fp(); int timer; timer = timer_configure(TIMER_TMU, 1000, GINT_CALL(update_time)); if(timer < 0){ return -1; } timer_start(timer); game.map_level = worldRPG[0]; events_init_handler(&game.handler); events_bind_variable(&game.handler, (int*)&game.player.life, "life"); events_bind_variable(&game.handler, &game.mana, "mana"); reload_npc(&game); #if USB_FEATURE usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL}; usb_open(interfaces, GINT_CALL_NULL); #endif /* start grayscale engine */ #if GRAYMODEOK dgray(DGRAY_ON); #endif do{ /* clear screen */ dclear(C_WHITE); /* render the map */ draw(&game); #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; inbextradata; 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 /* start the logic of the game */ game_logic(&game); /* Screen blit */ dupdate(); /* Screen capture feature if enabled */ #if USB_FEATURE USB_feature(); #endif /* Management of the inputs */ get_inputs(&game); /* Run the game at max. 50fps */ while(game.frame_duration < 20) sleep(); /* Reset frame_duration for the next frame */ game.frame_duration = 0; }while(!game.exittoOS); // want to exit ? /* shutdown grayengine*/ #if GRAYMODEOK dgray(DGRAY_OFF); #endif /* close USB */ #if USB_FEATURE usb_close(); #endif timer_stop(timer); return 1; }