Compare commits

..

10 Commits

Author SHA1 Message Date
Tobin 936cd30cac shared struct and enum definitions file (maybe not the best idea) 2026-04-27 14:34:47 -04:00
Tobin 6e54eee066 empty rendering.c 2026-04-27 14:25:43 -04:00
Tobin 4393ebd958 clean up old makefile thing 2026-04-27 14:22:38 -04:00
Tobin ed4777344c kinda stops on the edge 2026-04-27 14:13:42 -04:00
Tobin 2a9ee28f93 wireframe! and music! 2026-04-27 14:08:07 -04:00
Tobin e0eb69fd64 notes 2026-04-27 12:47:29 -04:00
Tobin d46a436303 comments mostly 2026-04-25 14:46:52 -04:00
Tobin 6bd50b041c draw and erase all entities 2026-04-25 14:46:02 -04:00
Tobin d944a57d23 add beepbox music! 2026-04-24 12:06:00 -04:00
Tobin 8fa69f4f98 finish doing that 2026-04-21 15:24:33 -04:00
8 changed files with 137 additions and 43 deletions
+18
View File
@@ -0,0 +1,18 @@
- v2: https://www.beepbox.co/#9n31sbk0l00e05t1ja7g0fj07r1i0o432T1v1ub4f20o72laq011d23A5F4B3Q0001Pfca8E362963479T1v2ub5f0q0x10o51d23A5F4B6Q0001PecaaE4b262963979T1v1ub5f0q0x10o51d23A5F4B6Q0001PecaaE4b262963979T2v1u15f10w4qw02d03w0E0b5yd50000000id3g00000018Qd00000004h400000000p23bAqq_7jhWttlh7llCoCCnKJdlU9SQ5NuhnhnAix7wenORKrwld5CoCO_uqw4R_td7wbXGqaqXsyDxfgs0HTcjFHKjgsRg5Jwn0978-9UO0GG8WGI1N3Co1dlW8ndHWISwxi6h48pjy7124aMgwAh26g48tKzE4jo4cmYgraScwhhF4gm0462CRZl1nOuJnn8qlk30WRtBg00
# PLOT
act I: little guy falls down well to very bottom, is dark
cats help get shaft of light to little guy
act II: get little guy out along the light path
# types of cat
- void cats (bend)
- wormhole cats
- mirror cats (black with white bellies)
- splitter (in spot multiple out spots)
- component colors; only one color can go thru top half, another bottom color, join on other side
- joiners
- amplifier?
- latern for lighting up work space
+25
View File
@@ -1,3 +1,14 @@
/* yields
cat_init();
cat_create_window();
cat_pixel();
cat_fill();
cat_render();
cat_play_wav();
cat_stop_audio();
cat_get_event();
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
@@ -122,6 +133,20 @@ void cat_fill(int layer, int visible, int x, int y, int w, int h, unsigned char
cat_pixel(layer, visible, cx + x, cy + y, r, g, b); cat_pixel(layer, visible, cx + x, cy + y, r, g, b);
} }
void cat_wireframe(int layer, int visible, int x, int y, int w, int h, unsigned char r, unsigned char g, unsigned char b)
{
int cx; for (cx = 0; cx < w; cx++)
{
cat_pixel(layer, visible, x + cx, y, r, g, b);
cat_pixel(layer, visible, x + cx, y+h, r, g, b);
}
int cy; for (cy = 0; cy < h; cy++)
{
cat_pixel(layer, visible, x, y + cy, r, g, b);
cat_pixel(layer, visible, x + w, y + cy, r, g, b);
}
}
/* TODO: cat bresenham */ /* TODO: cat bresenham */
/* audio... */ /* audio... */
Binary file not shown.
Binary file not shown.
+56 -39
View File
@@ -1,6 +1,14 @@
#include "cat_api.h" #include "cat_api.h"
#include "shared.h"
#include "rendering.c"
#include <time.h> #include <time.h>
/* TODO:
- *forces* as linked list struct? entity can have a list of forces acting on it
if force is 0N cleanup remove from list every tick.
or every few ticks do a cleanup routine that also frees memory and stuff
*/
void bye(void) void bye(void)
{ {
printf("bye!\n"); printf("bye!\n");
@@ -56,26 +64,11 @@ int is_held(char k)
return 0; return 0;
} }
struct entity
{
int is_player;
int is_static;
int x;
int y;
int width;
int height;
unsigned int color; /* replace this with sprite TODO */
float vx;
float vy;
float ax;
float ay;
struct entity* next;
};
struct entity* first_entity = NULL; struct entity* first_entity = NULL;
void add_entity(int is_player, int is_static, int x, int y, int width, int height, unsigned int color, void add_entity(int is_player, int is_static, int x, int y, int width, int height, unsigned char r,
float vx, float vy, float ax, float ay) unsigned char g, unsigned char b, float vx, float vy, float ax, float ay)
{ {
struct entity* new = malloc(sizeof(struct entity)); struct entity* new = malloc(sizeof(struct entity));
new->is_player = is_player; new->is_player = is_player;
@@ -84,7 +77,9 @@ void add_entity(int is_player, int is_static, int x, int y, int width, int heigh
new->y = y; new->y = y;
new->width = width; new->width = width;
new->height = height; new->height = height;
new->color = color; new->r = r;
new->g = g;
new->b = b;
new->vx = vx; new->vx = vx;
new->vy = vy; new->vy = vy;
new->ax = ax; new->ax = ax;
@@ -124,8 +119,8 @@ void key_up(char k)
printf("%c un-pressed\n", k); printf("%c un-pressed\n", k);
switch (k) switch (k)
{ {
case 'a': player_ax = 0; break; case 'a': get_player()->ax = 0; break;
case 'd': player_ax = 0; break; case 'd': get_player()->ax = 0; break;
} }
} }
@@ -153,6 +148,7 @@ void mouse_up(unsigned char button)
void process_input(void) void process_input(void)
{ {
/* mode switch game or menus */
struct cat_event* e = cat_get_event(); struct cat_event* e = cat_get_event();
if (e == NULL) return; if (e == NULL) return;
if (e->type == QUIT) bye(); if (e->type == QUIT) bye();
@@ -163,31 +159,36 @@ void process_input(void)
else if (e->type == MOUSEUP) mouse_up(e->mouse_button); else if (e->type == MOUSEUP) mouse_up(e->mouse_button);
} }
void erase_entity(/*struct entity*/) void erase_entity(struct entity* e)
{ {
/* get sprite info, etc */ /* get sprite info, etc */
/* FIXME */ /* FIXME */
cat_fill(1, 0, player_x, player_y, 50, 50, 0, 0, 0); if (e->x < 0 || e->y < 0 || e->x >= screen_width || e->y >= screen_height) return;
cat_wireframe(1, 0, e->x, e->y, e->width, e->height, 0, 0, 0);
} }
void draw_entity(/* struct entity */) void draw_entity(struct entity* e)
{ {
/* get sprite info, etc */ /* get sprite info, etc */
/* FIXME */ /* FIXME */
cat_fill(1, 1, player_x, player_y, 50, 50, 115, 72, 6); if (e->x < 0 || e->y < 0 || e->x >= screen_width || e->y >= screen_height) return;
cat_wireframe(1, 1, e->x, e->y, e->width, e->height, e->r, e->g, e->b);
render_entity(e);
/* if out of bounds do not draw */ /* if out of bounds do not draw */
} }
void erase_entities(void) void erase_entities(void)
{ {
/* TODO more than just player entity */ struct entity* head;
erase_entity(/*player*/); for (head = first_entity; head != NULL; head = head->next)
erase_entity(head);
} }
void draw_entities(void) void draw_entities(void)
{ {
/* TODO more than just player entity */ struct entity* head;
draw_entity(/*player*/); for (head = first_entity; head != NULL; head = head->next)
draw_entity(head);
} }
static long last_sec = 0; static long last_sec = 0;
@@ -197,12 +198,15 @@ static long last_nsec = 0;
void apply_friction(void) /* FIXME */ void apply_friction(void) /* FIXME */
{ {
if (get_player()->vx > 0) get_player()->vx -= 1; struct entity* p = get_player();
else if (get_player()->vx < 0) get_player()->vx += 1; if (p->vx > 0) p->vx -= 1;
if (get_player()->vy > 0) get_player()->vy -= 1; else if (p->vx < 0) p->vx += 1;
else if (get_player()->vy < 0) get_player()->vy += 1; if (p->vy > 0) p->vy -= 1;
else if (p->vy < 0) p->vy += 1;
} }
/* FIXME */ static int tick_count = 0;
void tick(void) void tick(void)
{ {
/* run every N milliseconds... nanoseconds? idk */ /* run every N milliseconds... nanoseconds? idk */
@@ -215,16 +219,23 @@ void tick(void)
/* do a tick */ /* do a tick */
yes: last_sec = t.tv_sec; yes: last_sec = t.tv_sec;
last_nsec = t.tv_nsec; last_nsec = t.tv_nsec;
printf("tick %d!\n", tick_count++);
/* code to run every tick goes here */ /* code to run every tick goes here */
/* something like "for i in fns_to_run_per_tick (linked list) run ->fn()
and somewhere there's an add_fn_to_run_every_tick() thing... or every n ticks... idk */
erase_entities(); erase_entities();
if (is_held(' ')) get_player()->ay = -5; struct entity* p = get_player();
else get_player()->ay = 9.81; if (is_held(' ')) p->ay = -5;
get_player()->vx += get_player()->ax; else p->ay = 9.81;
get_player()->vy += get_player()->ay; p->vx += p->ax;
p->vy += p->ay;
/* FIXME */
if (p->y >= screen_height - 100 && p->vy > 0) p->vy = 0;
/* end fixme */
apply_friction(); /* FIXME */ apply_friction(); /* FIXME */
get_player()->x += (int)get_player()->vx; p->x += (int)p->vx;
get_player()->y += (int)get_player()->vy; p->y += (int)p->vy;
draw_entities(); draw_entities();
} }
@@ -232,6 +243,7 @@ void game_loop(void)
{ {
cat_render(); cat_render();
process_input(); process_input();
/* mode check for in game or in menu */
tick(); tick();
} }
@@ -239,9 +251,14 @@ int main(int argc, char** argv)
{ {
cat_init(); cat_init();
cat_create_window(1920, 1080); cat_create_window(1920, 1080);
cat_play_wav("etc/example.wav"); //cat_play_wav("etc/example.wav");
//cat_play_wav("etc/cat_quick.wav");
//cat_play_wav("etc/cat_beep_box.wav");
cat_play_wav("etc/cat_beep_slower.wav");
/* layer, visibility, x, y, width, height, r, g, b */ /* layer, visibility, x, y, width, height, r, g, b */
cat_fill(0, 1, 0, 0, screen_width - 1, screen_height - 1, 132, 155, 132); cat_fill(0, 1, 0, 0, screen_width - 1, screen_height - 1, 132, 155, 132);
/* create the player */ add_entity(1, 0, 0, 0, 50, 50, 100, 50, 0, 0, 0, 0, 0);
/* create a random entity */ add_entity(0, 0, 20, 20, 50, 50, 100, 100, 50, 0, 0, 0, 0);
while (1) game_loop(); while (1) game_loop();
return 0; return 0;
} }
-4
View File
@@ -4,7 +4,3 @@ all:
run: all run: all
bin/cfhfg bin/cfhfg
audio:
cc -o bin/audio etc/audio.c -lSDL2
bin/audio
+13
View File
@@ -0,0 +1,13 @@
/* all of the stuff like texturing the wireframes of entities will go here */
void render_entity(struct entity* e)
{
switch (e->texture)
{
case VOID_CAT:
/* TODO draw a bunch of black blobs around the hitbox */
printf("TODO: apply void cat texture to entity \n");
break;
default: /* error */
}
}
+25
View File
@@ -0,0 +1,25 @@
enum textures /* or call this skin? */
{
VOID_CAT
};
struct entity
{
int is_player;
int is_static;
int in_freefall;
float x;
float y;
int width; /**/
int height; /**/
unsigned char r; /* replace this with sprite TODO */
unsigned char g; /**/
unsigned char b; /**/
float vx;
float vy;
float ax;
float ay;
enum textures texture; /* or skin? */
struct entity* next;
};