6 #include "./platforms.h"
11 #define SCREEN_WIDTH 800
12 #define SCREEN_HEIGHT 600
15 /* LT module adapter for SDL_Quit */
16 static void SDL_Quit_lt(void* ignored)
22 static void print_usage(FILE *stream)
24 fprintf(stream, "Usage: nothing <level-file>\n");
27 int main(int argc, char *argv[])
29 lt_t *const lt = create_lt();
36 if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
37 print_error_msg(ERROR_TYPE_SDL2, "Could not initialize SDL");
40 PUSH_LT(lt, 42, SDL_Quit_lt);
42 SDL_Window *const window = PUSH_LT(
44 SDL_CreateWindow("Nothing", 100, 100, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN),
48 print_error_msg(ERROR_TYPE_SDL2, "Could not create SDL window");
52 SDL_Renderer *const renderer = PUSH_LT(
54 SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
56 if (renderer == NULL) {
57 print_error_msg(ERROR_TYPE_SDL2, "Could not create SDL renderer");
60 if (SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND) < 0) {
61 print_error_msg(ERROR_TYPE_SDL2, "Could not set up blending mode for the renderer");
65 SDL_Joystick *the_stick_of_joy = NULL;
67 if (SDL_NumJoysticks() > 0) {
68 the_stick_of_joy = PUSH_LT(lt, SDL_JoystickOpen(0), SDL_JoystickClose);
70 if (the_stick_of_joy == NULL) {
71 print_error_msg(ERROR_TYPE_SDL2, "Could not open 0th Stick of the Joy: %s\n");
75 printf("Opened Joystick 0\n");
76 printf("Name: %s\n", SDL_JoystickNameForIndex(0));
77 printf("Number of Axes: %d\n", SDL_JoystickNumAxes(the_stick_of_joy));
78 printf("Number of Buttons: %d\n", SDL_JoystickNumButtons(the_stick_of_joy));
79 printf("Number of Balls: %d\n", SDL_JoystickNumBalls(the_stick_of_joy));
81 SDL_JoystickEventState(SDL_ENABLE);
83 fprintf(stderr, "[WARNING] Could not find any Sticks of the Joy\n");
86 // ------------------------------
88 game_t *const game = PUSH_LT(lt, create_game(argv[1]), destroy_game);
90 print_current_error_msg("Could not create the game object");
94 const Uint8 *const keyboard_state = SDL_GetKeyboardState(NULL);
95 const Uint32 delay_ms = (Uint32) roundf(1000.0f / GAME_FPS);
97 while (!game_over_check(game)) {
98 while (!game_over_check(game) && SDL_PollEvent(&e)) {
99 if (game_event(game, &e) < 0) {
100 print_current_error_msg("Failed handling event");
105 if (game_input(game, keyboard_state, the_stick_of_joy) < 0) {
106 print_current_error_msg("Failed handling input");
110 if (game_update(game, delay_ms) < 0) {
111 print_current_error_msg("Failed handling updating");
115 if (game_render(game, renderer) < 0) {
116 print_current_error_msg("Failed rendering the game");