Initial commit

This commit is contained in:
Thomas
2026-02-28 18:00:58 +00:00
commit c66c12ae68
587 changed files with 239570 additions and 0 deletions

46
src/engine/parallax.h Normal file
View File

@@ -0,0 +1,46 @@
#ifndef JNR_PARALLAX_H
#define JNR_PARALLAX_H
#include <SDL2/SDL.h>
#include <stdbool.h>
#include "config.h"
/* Forward declarations */
typedef struct Camera Camera;
/* A single parallax layer */
typedef struct ParallaxLayer {
SDL_Texture *texture; /* the background image */
int tex_w, tex_h; /* texture dimensions in pixels */
float scroll_x; /* horizontal scroll factor (0=fixed, 1=full) */
float scroll_y; /* vertical scroll factor */
bool active; /* whether this layer is in use */
bool owns_texture; /* true if we generated it (must free) */
} ParallaxLayer;
/* Parallax background system — up to two layers */
typedef struct Parallax {
ParallaxLayer far_layer; /* distant background (stars) */
ParallaxLayer near_layer; /* mid-ground background (nebula) */
} Parallax;
/* Initialize parallax (zeroes everything) */
void parallax_init(Parallax *p);
/* Set a layer from an existing texture (loaded via assets) */
void parallax_set_far(Parallax *p, SDL_Texture *tex, float scroll_x, float scroll_y);
void parallax_set_near(Parallax *p, SDL_Texture *tex, float scroll_x, float scroll_y);
/* Generate procedural starfield texture (far layer) */
void parallax_generate_stars(Parallax *p, SDL_Renderer *renderer);
/* Generate procedural nebula/dust texture (near layer) */
void parallax_generate_nebula(Parallax *p, SDL_Renderer *renderer);
/* Render both layers (call before tile/entity rendering) */
void parallax_render(const Parallax *p, const Camera *cam, SDL_Renderer *renderer);
/* Free generated textures (not file-loaded ones — asset manager owns those) */
void parallax_free(Parallax *p);
#endif /* JNR_PARALLAX_H */