2023-07-06 22:02:37 +02:00
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>
# include <gint/cpu.h>
2023-07-06 22:02:37 +02:00
2023-07-08 20:07:34 +02:00
# include "config.h"
2023-07-06 22:02:37 +02:00
2023-07-08 20:07:34 +02:00
# if USB_FEATURE
2023-07-07 14:20:13 +02:00
# include <gint/usb-ff-bulk.h>
# include <gint/usb.h>
2023-07-06 22:02:37 +02:00
# endif //USB_FEATURE
2023-07-05 23:22:15 +02:00
2023-07-18 19:47:47 +02:00
# if GRAYMODEOK
2023-07-07 14:20:13 +02:00
# include <gint/gray.h>
2023-07-07 18:22:39 +02:00
# endif //GRAYMODEOK
2023-07-06 22:02:37 +02:00
# include <stdint.h>
# include <stdbool.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
2023-07-09 22:02:59 +02:00
# include "dialogs.h"
extern bopti_image_t player_face_img ;
2023-08-08 09:46:07 +02:00
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")*/
Game game = {
2023-08-10 16:22:31 +02:00
NULL ,
2023-08-16 19:25:24 +02:00
{ 12 * PXSIZE , 36 * PXSIZE , 0 , 0 , 10 * PXSIZE , 48 * PXSIZE , 100 , SPEED , false , 0 , false } ,
2023-07-08 20:07:34 +02:00
false , false , false , 0
2023-08-10 16:22:31 +02:00
/* debug variables*/
2023-08-16 19:25:24 +02:00
, false , false , false
2023-08-10 16:22:31 +02:00
} ;
2023-07-06 22:02:37 +02:00
2023-07-06 22:49:29 +02:00
/* screen capture management code */
2023-07-18 19:47:47 +02:00
# if USB_FEATURE
2023-07-06 22:02:37 +02:00
2023-07-07 14:20:13 +02:00
void USB_feature ( void )
{
2023-07-08 20:07:34 +02:00
if ( game . screenshot & & usb_is_open ( ) ) {
2023-07-07 18:22:39 +02:00
2023-07-18 19:47:47 +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
if ( dgray_enabled ( ) )
usb_fxlink_screenshot_gray ( false ) ;
else
# endif
2023-07-09 21:53:07 +02:00
// else we just let the usual screeshot function
usb_fxlink_screenshot ( false ) ;
2023-07-08 20:07:34 +02:00
game . screenshot = false ;
2023-07-07 14:20:13 +02:00
}
2023-07-07 18:22:39 +02:00
2023-07-08 20:07:34 +02:00
if ( game . record & & usb_is_open ( ) ) {
2023-07-07 18:22:39 +02:00
2023-07-18 19:47:47 +02:00
# if GRAYMODEOK
2023-07-07 18:22:39 +02:00
if ( dgray_enabled ( ) )
usb_fxlink_videocapture_gray ( false ) ;
else
# endif
2023-07-07 14:20:13 +02:00
usb_fxlink_videocapture ( false ) ;
}
}
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 ) {
2023-07-08 20:07:34 +02:00
int timer ;
timer = timer_configure ( TIMER_TMU , 1000 , GINT_CALL ( update_time ) ) ;
if ( timer < 0 ) {
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 ] ;
2023-08-10 16:22:31 +02:00
2023-07-18 19:47:47 +02:00
# if USB_FEATURE
2023-07-07 14:20:13 +02:00
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
2023-07-18 19:47:47 +02:00
# if GRAYMODEOK
2023-07-08 20:07:34 +02:00
dgray ( DGRAY_ON ) ;
2023-07-07 14:20:13 +02:00
# endif
2023-07-06 22:49:29 +02:00
2023-08-18 20:56:44 +02:00
/*
2023-07-19 20:06:28 +02:00
showtext_dialog ( & game , & player_face_img , " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet. " , true , true ) ;
2023-08-10 16:22:31 +02:00
int in = showtext_dialog_ask ( & game , & player_face_img , " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet. " , true , false , " Lorem \0 Ipsum \0 Dolor " , 3 , 0 ) ;
if ( in = = 2 ) showtext_dialog ( & game , & player_face_img , " You choosed Dolor " , false , true ) ;
else if ( in = = 1 ) showtext_dialog ( & game , & player_face_img , " You choosed Ipsum " , false , true ) ;
2023-07-19 17:43:02 +02:00
else showtext_dialog ( & game , & player_face_img , " You choosed Lorem " , false , true ) ;
2023-08-18 20:56:44 +02:00
*/
2023-08-08 09:46:07 +02:00
2023-07-08 20:07:34 +02:00
do {
2023-07-07 14:20:13 +02:00
/* clear screen */
dclear ( C_WHITE ) ;
2023-07-06 22:49:29 +02:00
2023-07-07 14:20:13 +02:00
/* render the map */
2023-07-08 15:55:06 +02:00
draw ( & game ) ;
2023-07-06 22:02:37 +02:00
2023-08-11 08:54:04 +02:00
# if DEBUGMODE && FXCG50
2023-08-11 08:04:17 +02:00
if ( game . debug_map )
{
dfont ( NULL ) ;
drect ( 5 , 5 , 390 , 55 , C_WHITE ) ;
2023-08-18 15:41:19 +02:00
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 ) ;
2023-08-11 08:04:17 +02:00
}
if ( game . debug_player )
{
dfont ( NULL ) ;
drect ( 5 , 55 , 390 , 75 , C_WHITE ) ;
2023-08-18 15:41:19 +02:00
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 ) ;
2023-08-11 08:04:17 +02:00
}
2023-08-16 17:34:45 +02:00
if ( game . debug_extra )
{
dfont ( NULL ) ;
for ( int i = 0 ; i < game . map_level - > nbextradata ; i + + )
2023-08-18 15:41:19 +02:00
dprint ( 10 , 90 + i * 15 , C_RED , " X= %d - Y= %d - T: %s " ,
game . map_level - > extradata [ i ] . x ,
game . map_level - > extradata [ i ] . y ,
game . map_level - > extradata [ i ] . dialog ) ;
2023-08-16 17:34:45 +02:00
}
2023-08-11 08:04:17 +02:00
# 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
2023-07-07 14:20:13 +02:00
/* Screen capture feature if enabled */
2023-07-18 19:47:47 +02:00
# if USB_FEATURE
2023-07-07 14:20:13 +02:00
USB_feature ( ) ;
# endif
2023-07-06 22:02:37 +02:00
2023-07-07 14:20:13 +02:00
/* Management of the inputs */
2023-07-08 20:07:34 +02:00
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 ?
2023-07-05 23:22:15 +02:00
2023-07-06 21:16:07 +02:00
2023-07-07 14:20:13 +02:00
/* shutdown grayengine*/
2023-07-18 19:47:47 +02:00
# if GRAYMODEOK
2023-07-08 20:07:34 +02:00
dgray ( DGRAY_OFF ) ;
2023-07-07 14:20:13 +02:00
# endif
2023-07-06 21:16:07 +02:00
2023-07-06 22:49:29 +02:00
2023-07-07 14:20:13 +02:00
/* close USB */
2023-07-18 19:47:47 +02:00
# if USB_FEATURE
2023-07-07 14:20:13 +02:00
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
}
2023-07-08 16:57:04 +02:00