Added sprite, spritesheet and actor registries

This commit is contained in:
2024-12-17 22:13:10 -05:00
parent 583210360e
commit 1066f2a108
4 changed files with 61 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
#define SDL_MAIN_USE_CALLBACKS
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_properties.h>
#include <SDL3_image/SDL_image.h>
#include <SDL3_mixer/SDL_mixer.h>
#include <aklabs/exclib.h>
@@ -16,6 +17,7 @@
spritesheet actorsheet;
sprite littleguy;
actor player;
actor npc;
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
{
@@ -24,7 +26,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
spec.freq = MIX_DEFAULT_FREQUENCY;
spec.format = MIX_DEFAULT_FORMAT;
spec.channels = MIX_DEFAULT_CHANNELS;
exclib_name_exception(EXC_SDL_INIT, "SDL Initialization Failure");
exclib_name_exception(EXC_SDL_MUSICMIXER, "SDL Music Mixer Failure");
exclib_name_exception(EXC_GAME_UNDEFINED, "Undefined method or value");
@@ -32,6 +34,10 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
exclib_name_exception(EXC_TYPEERROR, "Type Error");
exclib_name_exception(EXC_KEYERROR, "Key Error");
registry_init_actor();
registry_init_sprite();
registry_init_spritesheet();
SDL_SetAppMetadata("SDL3-GameTest", "0.1", "net.aklabs.sdl3-gametest");
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO )) {
@@ -85,6 +91,17 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
return SDL_APP_FAILURE;
} ETRY;
TRY {
actor_new(&npc, "npc");
npc.curSprite = SDL_GetPointerProperty(REGISTRY_SPRITE, "little guy facing down", NULL);
THROW_ZERO(npc.curSprite, EXC_NULLPOINTER, "'little guy facing down' was not found in the sprite registry");
npc.x = 320;
npc.y = 240;
} CATCH(EXC_NULLPOINTER) {
SDL_Log("Attempting to setup npc: %s (%s)", EXCLIB_EXCEPTION->description, SDL_GetError());
return SDL_APP_FAILURE;
} ETRY;
/*
TRY {
//load_start_bgm("../assets/nutcracker.mid");
@@ -133,6 +150,7 @@ SDL_AppResult SDL_AppIterate(void *appstate)
//tilemap_draw_tileset(renderer, &gamemap, 0);
tilemap_draw(renderer, &gamemap, &viewport, 0);
actor_render(&player, renderer);
actor_render(&npc, renderer);
} ETRY;
SDL_RenderPresent(renderer);
return SDL_APP_CONTINUE;