finish doing that

This commit is contained in:
Tobin
2026-04-21 15:24:33 -04:00
parent 155da173bc
commit 8fa69f4f98
+31 -22
View File
@@ -64,7 +64,9 @@ struct entity
int y;
int width;
int height;
unsigned int color; /* replace this with sprite TODO */
unsigned char r; /* replace this with sprite TODO */
unsigned char g;
unsigned char b;
float vx;
float vy;
float ax;
@@ -74,8 +76,8 @@ struct entity
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 +86,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 +128,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;
}
}
@@ -163,31 +167,33 @@ 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_fill(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_fill(1, 1, e->x, e->y, e->width, e->height, e->r, e->g, e->b);
/* if out of bounds do not draw */
}
void erase_entities(void)
{
/* TODO more than just player entity */
erase_entity(/*player*/);
erase_entity(get_player());
}
void draw_entities(void)
{
/* TODO more than just player entity */
draw_entity(/*player*/);
draw_entity(get_player());
}
static long last_sec = 0;
@@ -197,10 +203,11 @@ 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;
}
void tick(void)
@@ -218,13 +225,14 @@ void tick(void)
/* code to run every tick goes here */
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;
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();
}
@@ -242,6 +250,7 @@ int main(int argc, char** argv)
cat_play_wav("etc/example.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);
while (1) game_loop();
return 0;
}