gint_x_raylib_poc/src/main.c

76 lines
1.5 KiB
C

#ifdef FXCG50
#include <gint/display.h>
#include <gint/keyboard.h>
#endif
#ifdef USERAYLIB
#include <raylib.h>
#define DWIDTH 396
#define DHEIGHT 224
#define C_WHITE RAYWHITE
#define C_BLACK BLACK
#define keydown(x) IsKeyDown(x)
#define dclear(x) ClearBackground(x)
#define drect(x, y, w, h, c) DrawRectangle(x, y, (x) - (w), (y) - (h), c)
#endif
/* Disclaimer: this is a very dirty demo to show than it's possible.
* OFC if you want to this for real, create headers instead of putting
* everything in main. */
void init(void) {
#ifdef USERAYLIB
InitWindow(DWIDTH, DHEIGHT, "sample cross platform program");
SetTargetFPS(40);
#endif
}
void deinit(void) {
#ifdef USERAYLIB
CloseWindow();
#endif
}
void beginDrawing(void) {
#ifdef USERAYLIB
BeginDrawing();
#endif
}
void endDrawing(void) {
#ifdef USERAYLIB
EndDrawing();
#endif
}
#ifdef USERAYLIB
void clearevents(void) {};
void dupdate(void) {};
#endif
/* Program would actually start here! */
int main(void) {
init();
int player_x = DWIDTH / 2;
int player_y = DHEIGHT / 2;
do {
clearevents();
if (keydown(KEY_UP)) player_y -= 2;
if (keydown(KEY_DOWN)) player_y += 2;
if (keydown(KEY_LEFT)) player_x -= 2;
if (keydown(KEY_RIGHT)) player_x += 2;
beginDrawing();
dclear(C_WHITE);
drect(player_x, player_y, player_x + 16, player_y + 16, C_BLACK);
dupdate();
#ifdef FXCG50
} while(!keydown(KEY_EXIT));
#endif
endDrawing();
#ifdef USERAYLIB
} while(!WindowShouldClose());
#endif
deinit();
return 0;
}