true 16-bit color... glorious

This commit is contained in:
asrael 2025-11-28 14:41:35 -06:00
parent 3dccce8a81
commit b1e8525c3e
30 changed files with 678 additions and 652 deletions

View file

@ -3,6 +3,8 @@
#include <stdlib.h>
#include <string.h>
#define PXL8_RANDF() ((f32)rand() / (f32)RAND_MAX)
struct pxl8_particles {
pxl8_particle* particles;
u32 alive_count;
@ -26,7 +28,7 @@ struct pxl8_particles {
};
void pxl8_vfx_plasma(pxl8_gfx* gfx, f32 time, f32 scale1, f32 scale2, u8 palette_offset) {
if (!gfx || !pxl8_gfx_get_framebuffer(gfx)) return;
if (!gfx || !pxl8_gfx_get_framebuffer_indexed(gfx)) return;
for (i32 y = 0; y < pxl8_gfx_get_height(gfx); y++) {
for (i32 x = 0; x < pxl8_gfx_get_width(gfx); x++) {
@ -51,6 +53,8 @@ void pxl8_vfx_raster_bars(pxl8_gfx* gfx, pxl8_raster_bar* bars, u32 bar_count, f
for (u32 i = 0; i < bar_count; i++) {
pxl8_raster_bar* bar = &bars[i];
if (bar->height <= 1) continue;
f32 y = bar->base_y + bar->amplitude * sinf(time * bar->speed + bar->phase);
i32 y_int = (i32)y;
@ -75,7 +79,7 @@ void pxl8_vfx_raster_bars(pxl8_gfx* gfx, pxl8_raster_bar* bars, u32 bar_count, f
}
void pxl8_vfx_rotozoom(pxl8_gfx* gfx, f32 angle, f32 zoom, i32 cx, i32 cy) {
if (!gfx || !pxl8_gfx_get_framebuffer(gfx)) return;
if (!gfx || !pxl8_gfx_get_framebuffer_indexed(gfx)) return;
f32 cos_a = cosf(angle);
f32 sin_a = sinf(angle);
@ -83,7 +87,7 @@ void pxl8_vfx_rotozoom(pxl8_gfx* gfx, f32 angle, f32 zoom, i32 cx, i32 cy) {
u8* temp_buffer = (u8*)malloc(pxl8_gfx_get_width(gfx) * pxl8_gfx_get_height(gfx));
if (!temp_buffer) return;
memcpy(temp_buffer, pxl8_gfx_get_framebuffer(gfx), pxl8_gfx_get_width(gfx) * pxl8_gfx_get_height(gfx));
memcpy(temp_buffer, pxl8_gfx_get_framebuffer_indexed(gfx), pxl8_gfx_get_width(gfx) * pxl8_gfx_get_height(gfx));
for (i32 y = 0; y < pxl8_gfx_get_height(gfx); y++) {
for (i32 x = 0; x < pxl8_gfx_get_width(gfx); x++) {
@ -97,7 +101,7 @@ void pxl8_vfx_rotozoom(pxl8_gfx* gfx, f32 angle, f32 zoom, i32 cx, i32 cy) {
i32 sy = (i32)src_y;
if (sx >= 0 && sx < pxl8_gfx_get_width(gfx) && sy >= 0 && sy < pxl8_gfx_get_height(gfx)) {
pxl8_gfx_get_framebuffer(gfx)[y * pxl8_gfx_get_width(gfx) + x] = temp_buffer[sy * pxl8_gfx_get_width(gfx) + sx];
pxl8_gfx_get_framebuffer_indexed(gfx)[y * pxl8_gfx_get_width(gfx) + x] = temp_buffer[sy * pxl8_gfx_get_width(gfx) + sx];
}
}
}
@ -106,7 +110,7 @@ void pxl8_vfx_rotozoom(pxl8_gfx* gfx, f32 angle, f32 zoom, i32 cx, i32 cy) {
}
void pxl8_vfx_tunnel(pxl8_gfx* gfx, f32 time, f32 speed, f32 twist) {
if (!gfx || !pxl8_gfx_get_framebuffer(gfx)) return;
if (!gfx || !pxl8_gfx_get_framebuffer_indexed(gfx)) return;
f32 cx = pxl8_gfx_get_width(gfx) / 2.0f;
f32 cy = pxl8_gfx_get_height(gfx) / 2.0f;
@ -210,8 +214,8 @@ void pxl8_particles_emit(pxl8_particles* particles, u32 count) {
pxl8_particle* p = &particles->particles[j];
p->life = 1.0f;
p->max_life = 1.0f;
p->x = particles->x + (((f32)rand() / RAND_MAX) - 0.5f) * particles->spread_x;
p->y = particles->y + (((f32)rand() / RAND_MAX) - 0.5f) * particles->spread_y;
p->x = particles->x + ((PXL8_RANDF()) - 0.5f) * particles->spread_x;
p->y = particles->y + ((PXL8_RANDF()) - 0.5f) * particles->spread_y;
p->z = 0;
p->vx = p->vy = p->vz = 0;
p->ax = particles->gravity_x;
@ -312,15 +316,15 @@ void pxl8_vfx_explosion(pxl8_particles* particles, i32 x, i32 y, u32 color, f32
for (u32 i = 0; i < 50 && i < particles->max_count; i++) {
pxl8_particle* p = &particles->particles[i];
f32 angle = ((f32)rand() / RAND_MAX) * 6.28f;
f32 speed = force * (0.5f + ((f32)rand() / RAND_MAX) * 0.5f);
f32 angle = (PXL8_RANDF()) * 6.28f;
f32 speed = force * (0.5f + (PXL8_RANDF()) * 0.5f);
p->x = x;
p->y = y;
p->vx = cosf(angle) * speed;
p->vy = sinf(angle) * speed;
p->life = 1.0f;
p->max_life = 1.0f + ((f32)rand() / RAND_MAX);
p->max_life = 1.0f + (PXL8_RANDF());
p->color = color;
p->flags = 1;
}
@ -331,9 +335,9 @@ static void fire_spawn(pxl8_particle* p, void* userdata) {
p->start_color = palette_start + 6 + (rand() % 3);
p->end_color = palette_start;
p->color = p->start_color;
p->max_life = 1.5f + ((f32)rand() / RAND_MAX) * 1.5f;
p->vy = -80.0f - ((f32)rand() / RAND_MAX) * 120.0f;
p->vx = (((f32)rand() / RAND_MAX) - 0.5f) * 40.0f;
p->max_life = 1.5f + (PXL8_RANDF()) * 1.5f;
p->vy = -80.0f - (PXL8_RANDF()) * 120.0f;
p->vx = ((PXL8_RANDF()) - 0.5f) * 40.0f;
}
static void fire_update(pxl8_particle* p, f32 dt, void* userdata) {
@ -378,7 +382,7 @@ static void rain_spawn(pxl8_particle* p, void* userdata) {
p->end_color = 29;
p->color = p->start_color;
p->max_life = 2.0f;
p->vy = 200.0f + ((f32)rand() / RAND_MAX) * 100.0f;
p->vy = 200.0f + (PXL8_RANDF()) * 100.0f;
}
void pxl8_vfx_rain(pxl8_particles* particles, i32 width, f32 wind) {
@ -401,10 +405,10 @@ static void smoke_spawn(pxl8_particle* p, void* userdata) {
p->start_color = base_color;
p->end_color = base_color + 4;
p->color = p->start_color;
p->max_life = 3.0f + ((f32)rand() / RAND_MAX) * 2.0f;
p->vy = -20.0f - ((f32)rand() / RAND_MAX) * 30.0f;
p->vx = (((f32)rand() / RAND_MAX) - 0.5f) * 20.0f;
p->size = 1.0f + ((f32)rand() / RAND_MAX) * 2.0f;
p->max_life = 3.0f + (PXL8_RANDF()) * 2.0f;
p->vy = -20.0f - (PXL8_RANDF()) * 30.0f;
p->vx = ((PXL8_RANDF()) - 0.5f) * 20.0f;
p->size = 1.0f + (PXL8_RANDF()) * 2.0f;
}
void pxl8_vfx_smoke(pxl8_particles* particles, i32 x, i32 y, u8 color) {
@ -429,8 +433,8 @@ static void snow_spawn(pxl8_particle* p, void* userdata) {
p->end_color = 10;
p->color = p->start_color;
p->max_life = 4.0f;
p->vx = (((f32)rand() / RAND_MAX) - 0.5f) * 20.0f;
p->vy = 30.0f + ((f32)rand() / RAND_MAX) * 20.0f;
p->vx = ((PXL8_RANDF()) - 0.5f) * 20.0f;
p->vy = 30.0f + (PXL8_RANDF()) * 20.0f;
}
void pxl8_vfx_snow(pxl8_particles* particles, i32 width, f32 wind) {
@ -453,10 +457,10 @@ static void sparks_spawn(pxl8_particle* p, void* userdata) {
p->start_color = base_color;
p->end_color = base_color > 2 ? base_color - 2 : 0;
p->color = p->start_color;
p->max_life = 0.5f + ((f32)rand() / RAND_MAX) * 1.0f;
p->max_life = 0.5f + (PXL8_RANDF()) * 1.0f;
f32 angle = ((f32)rand() / RAND_MAX) * 6.28f;
f32 speed = 100.0f + ((f32)rand() / RAND_MAX) * 200.0f;
f32 angle = (PXL8_RANDF()) * 6.28f;
f32 speed = 100.0f + (PXL8_RANDF()) * 200.0f;
p->vx = cosf(angle) * speed;
p->vy = sinf(angle) * speed - 50.0f;
}
@ -488,9 +492,9 @@ void pxl8_vfx_starfield(pxl8_particles* particles, f32 speed, f32 spread) {
for (u32 i = 0; i < particles->max_count; i++) {
pxl8_particle* p = &particles->particles[i];
p->x = ((f32)rand() / RAND_MAX) * spread * 2.0f - spread;
p->y = ((f32)rand() / RAND_MAX) * spread * 2.0f - spread;
p->z = ((f32)rand() / RAND_MAX) * spread;
p->x = (PXL8_RANDF()) * spread * 2.0f - spread;
p->y = (PXL8_RANDF()) * spread * 2.0f - spread;
p->z = (PXL8_RANDF()) * spread;
p->vz = -speed;
p->life = 1000.0f;
p->max_life = 1000.0f;