Add getblockat function

This commit is contained in:
Miloslav Ciz 2023-08-08 20:34:21 +02:00
parent e678c68b66
commit 891d0f67a1
3 changed files with 95 additions and 21 deletions

44
game.h
View file

@ -3,4 +3,48 @@
#include "map.h"
#define LCR_KEY_UP 0x00
#define LCR_KEY_RIGHT 0x01
#define LCR_KEY_DOWN 0x02
#define LCR_KEY_LEFT 0x03
#define LCR_KEY_A 0x04 ///< confirm, restart race
#define LCR_KEY_B 0x05 ///< cancel, open menu
uint8_t LCR_keyPressed(uint8_t key);
void LCR_sleep(uint16_t timeMs);
void LCR_drawPixel(unsigned int x, unsigned int y, uint_fast16_t color);
/**
Call at the start of the program.
*/
void LCR_gameInit(void);
/**
Call right before program end.
*/
void LCR_gameEnd(void);
/**
Call this repeatedly in your main loop, pass the current time as the number
of milliseconds since program start. Returns 0 if program should end,
otherwise 1.
*/
uint8_t LCR_gameStep(uint32_t timeMs);
//------------------------------------------------------------------------------
void LCR_gameInit(void)
{
}
void LCR_gameEnd(void)
{
}
uint8_t LCR_gameStep(uint32_t time)
{
}
#endif // guard

21
main.c
View file

@ -1,21 +0,0 @@
#include <stdio.h>
#include "game.h"
#include "debug.h"
int main(void)
{
LCR_mapLoad(LCR_map0);
LCR_debugPrintCurrentMap();
uint8_t *b = LCR_getMapBlockAtCoordNumber(0);
if (!b)
printf("NO!\n");
else
printf("%d\n",(b - LCR_currentMap.blocks) / 4);
return 0;
}

51
main_sdl.c Normal file
View file

@ -0,0 +1,51 @@
#include <stdio.h>
#include "game.h"
#include "debug.h"
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *texture;
SDL_Surface *screenSurface;
const uint8_t *sdlKeyboardState;
int main(int argc, char *argv[])
{
uint8_t running = 1;
LCR_gameInit();
SDL_Init(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
window =
SDL_CreateWindow("Licar", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, SFG_SCREEN_RESOLUTION_X, SFG_SCREEN_RESOLUTION_Y,
SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(window,-1,0);
texture =
SDL_CreateTexture(renderer,SDL_PIXELFORMAT_RGB565,SDL_TEXTUREACCESS_STATIC,
SFG_SCREEN_RESOLUTION_X,SFG_SCREEN_RESOLUTION_Y);
screenSurface = SDL_GetWindowSurface(window);
sdlKeyboardState = SDL_GetKeyboardState(NULL);
//SDL_ShowCursor(0);
SDL_PumpEvents();
while (running)
{
running = sdlKeyboardState[SDL_SCANCODE_Q];
}
SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
LCR_gameEnd();
return 0;
}