added key input + support for USB screenshots/record

This commit is contained in:
SlyVTT 2023-07-06 22:02:37 +02:00
parent 5195cdba49
commit 25bc00e311
5 changed files with 173 additions and 7 deletions

View file

@ -10,7 +10,7 @@ find_package(Gint 2.9 REQUIRED)
find_package(LibProf 2.4 REQUIRED)
#set the color mode either to 1bit or 2bits
set(COLORMODE 1b)
set(COLORMODE 2b)
fxconv_declare_converters(assets-fx/converters.py)
@ -34,6 +34,7 @@ add_custom_command(
set(SOURCES
src/main.c
src/map.c
src/player.c
# ...
)
# Shared assets, fx-9860G-only assets and fx-CG-50-only assets

View file

@ -1,33 +1,141 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include "map.h"
#define USB_FEATURE 1
#if USB_FEATURE==1
#include <gint/usb-ff-bulk.h>
#include <gint/usb.h>
#endif //USB_FEATURE
#ifdef COLOR2BIT
#include <gint/gray.h>
#endif
#endif //COLOR2BIT
#include <stdint.h>
#include <stdbool.h>
#include "map.h"
#include "player.h"
struct Player MyPlayer = { 10, 5, 100 };
bool exittoOS = false;
bool screenshot = false;
bool record = false;
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;
if(keydown(KEY_LEFT)) PlayerLeft();
if(keydown(KEY_RIGHT)) PlayerRight();
if(keydown(KEY_UP)) PlayerUp();
if(keydown(KEY_DOWN)) PlayerDown();
if(keydown(KEY_SHIFT)) PlayerAction();
#if USB_FEATURE==1
if(keydown(KEY_7)) screenshot = true;
if(keydown(KEY_8)) record = !record;
#endif //USB_FEATURE
}
#if USB_FEATURE==1
void USB_feature( void )
{
if (screenshot && usb_is_open()) {
if (!dgray_enabled())
usb_fxlink_screenshot(false);
else
usb_fxlink_screenshot_gray(false);
screenshot = false;
}
if (record && usb_is_open()) {
if (!dgray_enabled())
usb_fxlink_videocapture(false);
else
usb_fxlink_videocapture_gray(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
dclear(C_WHITE);
#ifdef COLOR2BIT
dgray( DGRAY_ON );
#endif
RenderMap();
dupdate();
do
{
RenderMap();
dupdate();
#if USB_FEATURE==1
USB_feature();
#endif
get_inputs();
}
while (exittoOS == false);
getkey();
#ifdef COLOR2BIT
dgray( DGRAY_OFF );
#endif
#if USB_FEATURE==1
usb_close();
#endif
return 1;
}

View file

@ -5,7 +5,7 @@ extern struct Map map_level0;
struct Map *map_level = &map_level0;
void RenderMap(void)
void RenderMap( void )
{
for (int u = 0; u < map_level->nblayers; u++)
{

30
src/player.c Normal file
View file

@ -0,0 +1,30 @@
#include "player.h"
#include "map.h"
extern struct player;
extern struct Map *map_level;
void PlayerLeft( void )
{
}
void PlayerRight( void )
{
}
void PlayerUp( void )
{
}
void PlayerDown( void )
{
}
void PlayerAction( void )
{
}

27
src/player.h Normal file
View file

@ -0,0 +1,27 @@
#ifndef PLAYER_H
#define PLAYER_H
#include <stdint.h>
struct Player
{
uint16_t x, y;
uint16_t life;
};
void PlayerLeft( void );
void PlayerRight( void );
void PlayerUp( void );
void PlayerDown( void );
void PlayerAction( void );
#endif