finish doing that
This commit is contained in:
@@ -64,7 +64,9 @@ struct entity
|
|||||||
int y;
|
int y;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
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 vx;
|
||||||
float vy;
|
float vy;
|
||||||
float ax;
|
float ax;
|
||||||
@@ -74,8 +76,8 @@ struct entity
|
|||||||
|
|
||||||
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 +86,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 +128,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,31 +167,33 @@ 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_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 */
|
/* 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_fill(1, 1, e->x, e->y, e->width, e->height, e->r, e->g, e->b);
|
||||||
/* 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 */
|
/* TODO more than just player entity */
|
||||||
erase_entity(/*player*/);
|
erase_entity(get_player());
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_entities(void)
|
void draw_entities(void)
|
||||||
{
|
{
|
||||||
/* TODO more than just player entity */
|
/* TODO more than just player entity */
|
||||||
draw_entity(/*player*/);
|
draw_entity(get_player());
|
||||||
}
|
}
|
||||||
|
|
||||||
static long last_sec = 0;
|
static long last_sec = 0;
|
||||||
@@ -197,10 +203,11 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tick(void)
|
void tick(void)
|
||||||
@@ -218,13 +225,14 @@ void tick(void)
|
|||||||
|
|
||||||
/* code to run every tick goes here */
|
/* code to run every tick goes here */
|
||||||
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;
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,6 +250,7 @@ int main(int argc, char** argv)
|
|||||||
cat_play_wav("etc/example.wav");
|
cat_play_wav("etc/example.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);
|
||||||
while (1) game_loop();
|
while (1) game_loop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user