Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 936cd30cac | |||
| 6e54eee066 | |||
| 4393ebd958 | |||
| ed4777344c | |||
| 2a9ee28f93 | |||
| e0eb69fd64 | |||
| d46a436303 | |||
| 6bd50b041c | |||
| d944a57d23 | |||
| 8fa69f4f98 |
@@ -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
|
||||
@@ -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 <stdlib.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);
|
||||
}
|
||||
|
||||
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 */
|
||||
|
||||
/* audio... */
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,14 @@
|
||||
#include "cat_api.h"
|
||||
#include "shared.h"
|
||||
#include "rendering.c"
|
||||
#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)
|
||||
{
|
||||
printf("bye!\n");
|
||||
@@ -56,26 +64,11 @@ int is_held(char k)
|
||||
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;
|
||||
|
||||
void add_entity(int is_player, int is_static, int x, int y, int width, int height, unsigned int color,
|
||||
float vx, float vy, float ax, float ay)
|
||||
void add_entity(int is_player, int is_static, int x, int y, int width, int height, unsigned char r,
|
||||
unsigned char g, unsigned char b, float vx, float vy, float ax, float ay)
|
||||
{
|
||||
struct entity* new = malloc(sizeof(struct entity));
|
||||
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->width = width;
|
||||
new->height = height;
|
||||
new->color = color;
|
||||
new->r = r;
|
||||
new->g = g;
|
||||
new->b = b;
|
||||
new->vx = vx;
|
||||
new->vy = vy;
|
||||
new->ax = ax;
|
||||
@@ -124,8 +119,8 @@ void key_up(char k)
|
||||
printf("%c un-pressed\n", k);
|
||||
switch (k)
|
||||
{
|
||||
case 'a': player_ax = 0; break;
|
||||
case 'd': player_ax = 0; break;
|
||||
case 'a': get_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)
|
||||
{
|
||||
/* mode switch game or menus */
|
||||
struct cat_event* e = cat_get_event();
|
||||
if (e == NULL) return;
|
||||
if (e->type == QUIT) bye();
|
||||
@@ -163,31 +159,36 @@ void process_input(void)
|
||||
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 */
|
||||
/* 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 */
|
||||
/* 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 */
|
||||
}
|
||||
|
||||
void erase_entities(void)
|
||||
{
|
||||
/* TODO more than just player entity */
|
||||
erase_entity(/*player*/);
|
||||
struct entity* head;
|
||||
for (head = first_entity; head != NULL; head = head->next)
|
||||
erase_entity(head);
|
||||
}
|
||||
|
||||
void draw_entities(void)
|
||||
{
|
||||
/* TODO more than just player entity */
|
||||
draw_entity(/*player*/);
|
||||
struct entity* head;
|
||||
for (head = first_entity; head != NULL; head = head->next)
|
||||
draw_entity(head);
|
||||
}
|
||||
|
||||
static long last_sec = 0;
|
||||
@@ -197,12 +198,15 @@ static long last_nsec = 0;
|
||||
|
||||
void apply_friction(void) /* FIXME */
|
||||
{
|
||||
if (get_player()->vx > 0) get_player()->vx -= 1;
|
||||
else if (get_player()->vx < 0) get_player()->vx += 1;
|
||||
if (get_player()->vy > 0) get_player()->vy -= 1;
|
||||
else if (get_player()->vy < 0) get_player()->vy += 1;
|
||||
struct entity* p = get_player();
|
||||
if (p->vx > 0) p->vx -= 1;
|
||||
else if (p->vx < 0) p->vx += 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)
|
||||
{
|
||||
/* run every N milliseconds... nanoseconds? idk */
|
||||
@@ -215,16 +219,23 @@ void tick(void)
|
||||
/* do a tick */
|
||||
yes: last_sec = t.tv_sec;
|
||||
last_nsec = t.tv_nsec;
|
||||
printf("tick %d!\n", tick_count++);
|
||||
|
||||
/* 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();
|
||||
if (is_held(' ')) get_player()->ay = -5;
|
||||
else get_player()->ay = 9.81;
|
||||
get_player()->vx += get_player()->ax;
|
||||
get_player()->vy += get_player()->ay;
|
||||
struct entity* p = get_player();
|
||||
if (is_held(' ')) p->ay = -5;
|
||||
else p->ay = 9.81;
|
||||
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 */
|
||||
get_player()->x += (int)get_player()->vx;
|
||||
get_player()->y += (int)get_player()->vy;
|
||||
p->x += (int)p->vx;
|
||||
p->y += (int)p->vy;
|
||||
draw_entities();
|
||||
}
|
||||
|
||||
@@ -232,6 +243,7 @@ void game_loop(void)
|
||||
{
|
||||
cat_render();
|
||||
process_input();
|
||||
/* mode check for in game or in menu */
|
||||
tick();
|
||||
}
|
||||
|
||||
@@ -239,9 +251,14 @@ int main(int argc, char** argv)
|
||||
{
|
||||
cat_init();
|
||||
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 */
|
||||
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();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,3 @@ all:
|
||||
|
||||
run: all
|
||||
bin/cfhfg
|
||||
|
||||
audio:
|
||||
cc -o bin/audio etc/audio.c -lSDL2
|
||||
bin/audio
|
||||
|
||||
+13
@@ -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 */
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user