2023-09-10 14:43:20 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
2024-09-28 01:47:05 +02:00
|
|
|
#define LCR_SETTING_LOG_LEVEL 2
|
2024-09-27 00:08:52 +02:00
|
|
|
|
2023-08-03 21:12:23 +02:00
|
|
|
#include "game.h"
|
2023-09-10 14:43:20 +02:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
SDL_Window *window;
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
SDL_Texture *texture;
|
|
|
|
SDL_Surface *screenSurface;
|
|
|
|
uint16_t screen[LCR_SETTING_RESOLUTION_X * LCR_SETTING_RESOLUTION_Y];
|
|
|
|
|
|
|
|
const uint8_t *keyboardState;
|
|
|
|
|
|
|
|
uint8_t LCR_keyPressed(uint8_t key)
|
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case LCR_KEY_UP: return
|
|
|
|
keyboardState[SDL_SCANCODE_W] | keyboardState[SDL_SCANCODE_UP]; break;
|
|
|
|
|
|
|
|
case LCR_KEY_RIGHT: return
|
|
|
|
keyboardState[SDL_SCANCODE_D] | keyboardState[SDL_SCANCODE_RIGHT]; break;
|
|
|
|
|
|
|
|
case LCR_KEY_DOWN: return
|
|
|
|
keyboardState[SDL_SCANCODE_S] | keyboardState[SDL_SCANCODE_DOWN]; break;
|
|
|
|
|
|
|
|
case LCR_KEY_LEFT: return
|
|
|
|
keyboardState[SDL_SCANCODE_A] | keyboardState[SDL_SCANCODE_LEFT]; break;
|
|
|
|
|
|
|
|
case LCR_KEY_A: return
|
|
|
|
keyboardState[SDL_SCANCODE_K] | keyboardState[SDL_SCANCODE_RETURN]; break;
|
|
|
|
|
|
|
|
case LCR_KEY_B: return
|
|
|
|
keyboardState[SDL_SCANCODE_L] | keyboardState[SDL_SCANCODE_ESCAPE]; break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LCR_sleep(uint16_t timeMs)
|
|
|
|
{
|
2023-09-17 13:21:19 +02:00
|
|
|
usleep(timeMs * 1000);
|
2023-09-10 14:43:20 +02:00
|
|
|
}
|
|
|
|
|
2024-07-22 01:16:16 +02:00
|
|
|
void LCR_drawPixel(unsigned long index, uint16_t color)
|
2023-09-10 14:43:20 +02:00
|
|
|
{
|
2024-07-22 01:16:16 +02:00
|
|
|
screen[index] = color;
|
2023-09-10 14:43:20 +02:00
|
|
|
}
|
|
|
|
|
2024-08-02 00:05:03 +02:00
|
|
|
void LCR_log(const char *str)
|
|
|
|
{
|
|
|
|
printf("LOG: %s\n",str);
|
|
|
|
}
|
|
|
|
|
2023-09-10 14:43:20 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
uint8_t running = 1;
|
|
|
|
LCR_gameInit();
|
|
|
|
|
|
|
|
SDL_Init(0);
|
|
|
|
|
|
|
|
window =
|
|
|
|
SDL_CreateWindow("Licar", SDL_WINDOWPOS_UNDEFINED,
|
|
|
|
SDL_WINDOWPOS_UNDEFINED, LCR_SETTING_RESOLUTION_X, LCR_SETTING_RESOLUTION_Y,
|
|
|
|
SDL_WINDOW_SHOWN);
|
|
|
|
|
2024-09-27 00:08:52 +02:00
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
fputs("ERROR: couldn't create window",stderr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-09-10 14:43:20 +02:00
|
|
|
renderer = SDL_CreateRenderer(window,-1,0);
|
|
|
|
|
2024-09-27 00:08:52 +02:00
|
|
|
if (!renderer)
|
|
|
|
{
|
|
|
|
fputs("ERROR: couldn't create renderer",stderr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-09-10 14:43:20 +02:00
|
|
|
texture =
|
|
|
|
SDL_CreateTexture(renderer,SDL_PIXELFORMAT_RGB565,SDL_TEXTUREACCESS_STATIC,
|
|
|
|
LCR_SETTING_RESOLUTION_X,LCR_SETTING_RESOLUTION_Y);
|
|
|
|
|
2024-09-27 00:08:52 +02:00
|
|
|
if (!texture)
|
|
|
|
{
|
|
|
|
fputs("ERROR: couldn't create texture",stderr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-09-10 14:43:20 +02:00
|
|
|
screenSurface = SDL_GetWindowSurface(window);
|
|
|
|
|
|
|
|
SDL_ShowCursor(0);
|
|
|
|
|
|
|
|
SDL_PumpEvents();
|
|
|
|
keyboardState = SDL_GetKeyboardState(NULL);
|
|
|
|
|
|
|
|
while (running)
|
|
|
|
{
|
|
|
|
SDL_PumpEvents();
|
|
|
|
keyboardState = SDL_GetKeyboardState(NULL);
|
|
|
|
running = !keyboardState[SDL_SCANCODE_Q];
|
|
|
|
|
|
|
|
running &= LCR_gameStep(SDL_GetTicks());
|
|
|
|
|
|
|
|
SDL_UpdateTexture(texture,NULL,screen,
|
|
|
|
LCR_SETTING_RESOLUTION_X * sizeof(uint16_t));
|
|
|
|
|
|
|
|
SDL_RenderClear(renderer);
|
|
|
|
SDL_RenderCopy(renderer,texture,NULL,NULL);
|
|
|
|
SDL_RenderPresent(renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_DestroyTexture(texture);
|
|
|
|
SDL_DestroyRenderer(renderer);
|
|
|
|
SDL_DestroyWindow(window);
|
|
|
|
|
|
|
|
LCR_gameEnd();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|