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-06 22:02:37 +02:00
|
|
|
|
|
|
|
#define USB_FEATURE 1
|
|
|
|
|
|
|
|
#if USB_FEATURE==1
|
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-07 18:22:39 +02:00
|
|
|
#if !defined(FXCG50) && defined(COLOR2BIT)
|
|
|
|
#define GRAYMODEOK
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef 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-08 15:55:06 +02:00
|
|
|
/* Game data (defined in "game.h")*/
|
|
|
|
Game game = {
|
|
|
|
&map_level0,
|
|
|
|
{10, 5, 0, 0, 100}
|
|
|
|
};
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2023-07-06 22:49:29 +02:00
|
|
|
/* some global variables */
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2023-07-08 16:57:04 +02:00
|
|
|
/* Set to true when asked for exit */
|
|
|
|
bool exittoOS = false;
|
|
|
|
|
|
|
|
/* Set to true when screenshot is required */
|
|
|
|
bool screenshot = false;
|
|
|
|
|
|
|
|
/* Set to true when recording a video of the screen is required */
|
|
|
|
bool record = false;
|
|
|
|
|
|
|
|
/* How many ms the frame already took. */
|
|
|
|
long int frame_duration;
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2023-07-06 22:49:29 +02:00
|
|
|
/* Key management */
|
2023-07-06 22:02:37 +02:00
|
|
|
|
|
|
|
static void get_inputs( void )
|
|
|
|
{
|
|
|
|
key_event_t ev;
|
2023-07-07 14:20:13 +02:00
|
|
|
while((ev = pollevent()).type != KEYEV_NONE){
|
2023-07-06 22:02:37 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
/* Key binding for the Player action */
|
|
|
|
|
|
|
|
/*************************************/
|
2023-07-06 22:02:37 +02:00
|
|
|
|
|
|
|
if(keydown(KEY_EXIT)) exittoOS = true;
|
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
/* Player actions - Prototypes in player.h and implementation in player.c */
|
2023-07-08 15:55:06 +02:00
|
|
|
if(keydown(KEY_LEFT)) player_move(game.map_level, &game.player, D_LEFT);
|
|
|
|
if(keydown(KEY_RIGHT)) player_move(game.map_level, &game.player, D_RIGHT);
|
|
|
|
if(keydown(KEY_UP)) player_move(game.map_level, &game.player, D_UP);
|
|
|
|
if(keydown(KEY_DOWN)) player_move(game.map_level, &game.player, D_DOWN);
|
|
|
|
if(keydown(KEY_SHIFT)) player_action(&game.player);
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
/* if USB is enabled - keybinding for screencapture */
|
2023-07-06 22:02:37 +02:00
|
|
|
|
|
|
|
#if USB_FEATURE==1
|
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
if(keydown(KEY_7)) screenshot = true;
|
|
|
|
if(keydown(KEY_8)) record = !record;
|
2023-07-06 22:02:37 +02:00
|
|
|
|
|
|
|
#endif //USB_FEATURE
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-06 22:49:29 +02:00
|
|
|
/* screen capture management code */
|
|
|
|
|
2023-07-06 22:02:37 +02:00
|
|
|
#if USB_FEATURE==1
|
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
void USB_feature( void )
|
|
|
|
{
|
|
|
|
if (screenshot && usb_is_open()) {
|
2023-07-07 18:22:39 +02:00
|
|
|
|
|
|
|
#ifdef 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
|
|
|
|
|
|
|
|
usb_fxlink_screenshot(false); // else we just let the usual screeshot function
|
|
|
|
screenshot = false;
|
2023-07-07 14:20:13 +02:00
|
|
|
}
|
|
|
|
|
2023-07-07 18:22:39 +02:00
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
if (record && usb_is_open()) {
|
2023-07-07 18:22:39 +02:00
|
|
|
|
|
|
|
#ifdef GRAYMODEOK
|
|
|
|
|
|
|
|
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-07 14:50:30 +02:00
|
|
|
int main(void) {
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
#if USB_FEATURE==1
|
|
|
|
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-07 18:22:39 +02:00
|
|
|
#ifdef GRAYMODEOK
|
2023-07-07 14:20:13 +02:00
|
|
|
dgray( DGRAY_ON );
|
|
|
|
#endif
|
2023-07-06 22:49:29 +02:00
|
|
|
|
2023-07-05 23:22:15 +02:00
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
/* 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-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 */
|
|
|
|
#if USB_FEATURE==1
|
|
|
|
USB_feature();
|
|
|
|
#endif
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
/* Management of the inputs */
|
|
|
|
get_inputs();
|
2023-07-06 22:02:37 +02:00
|
|
|
|
2023-07-07 14:20:13 +02:00
|
|
|
}
|
|
|
|
while (exittoOS == false); // 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-07 18:22:39 +02:00
|
|
|
#ifdef GRAYMODEOK
|
2023-07-07 14:20:13 +02:00
|
|
|
dgray( DGRAY_OFF );
|
|
|
|
#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 */
|
|
|
|
#if USB_FEATURE==1
|
|
|
|
usb_close();
|
|
|
|
#endif
|
2023-07-06 22:02:37 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|