Collab_RPG/src/main.c

164 lines
3.3 KiB
C

#include <gint/display.h>
#include <gint/keyboard.h>
#define USB_FEATURE 1
#if USB_FEATURE==1
#include <gint/usb-ff-bulk.h>
#include <gint/usb.h>
#endif //USB_FEATURE
#if !defined(FXCG50) && defined(COLOR2BIT)
#define GRAYMODEOK
#endif
#ifdef GRAYMODEOK
#include <gint/gray.h>
#endif //GRAYMODEOK
#include <stdint.h>
#include <stdbool.h>
#include "game.h"
#include "mapdata.h"
/* Game data (defined in "game.h")*/
Game game = {
&map_level0,
{10, 5, 0, 0, 100}
};
/* some global variables */
bool exittoOS = false; // set to true when asked for exit
bool screenshot = false; // set to true when screenshot is required
bool record = false; // set to true when
/* Key management */
static void get_inputs( void )
{
key_event_t ev;
while((ev = pollevent()).type != KEYEV_NONE){
}
/* Key binding for the Player action */
/*************************************/
if(keydown(KEY_EXIT)) exittoOS = true;
/* Player actions - Prototypes in player.h and implementation in player.c */
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);
/* if USB is enabled - keybinding for screencapture */
#if USB_FEATURE==1
if(keydown(KEY_7)) screenshot = true;
if(keydown(KEY_8)) record = !record;
#endif //USB_FEATURE
}
/* screen capture management code */
#if USB_FEATURE==1
void USB_feature( void )
{
if (screenshot && usb_is_open()) {
#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;
}
if (record && usb_is_open()) {
#ifdef GRAYMODEOK
if (dgray_enabled())
usb_fxlink_videocapture_gray(false);
else
#endif
usb_fxlink_videocapture(false);
}
}
#endif
int main(void) {
#if USB_FEATURE==1
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
usb_open(interfaces, GINT_CALL_NULL);
#endif
/* start grayscale engine */
#ifdef GRAYMODEOK
dgray( DGRAY_ON );
#endif
do
{
/* clear screen */
dclear(C_WHITE);
/* render the map */
draw(&game);
/* start the logic of the game */
game_logic(&game);
/* Screen blit */
dupdate();
/* Screen capture feature if enabled */
#if USB_FEATURE==1
USB_feature();
#endif
/* Management of the inputs */
get_inputs();
}
while (exittoOS == false); // want to exit ?
/* shutdown grayengine*/
#ifdef GRAYMODEOK
dgray( DGRAY_OFF );
#endif
/* close USB */
#if USB_FEATURE==1
usb_close();
#endif
return 1;
}