diff options
Diffstat (limited to 'src/wall.c')
| -rw-r--r-- | src/wall.c | 70 |
1 files changed, 36 insertions, 34 deletions
@@ -2,18 +2,18 @@ #include "rodeo.h" static rodeo_collision_2d_world_t collision_wall_world; -rodeo_texture_2d_t wall_texture; -rodeo_texture_2d_t floor_texture; -rodeo_texture_2d_t goat_texture; -rodeo_texture_2d_t logo_texture; +rodeo_gfx_texture_2d_t wall_texture; +rodeo_gfx_texture_2d_t floor_texture; +rodeo_gfx_texture_2d_t goat_texture; +rodeo_gfx_texture_2d_t logo_texture; void init_wall(void) { - wall_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/walls.png")); - floor_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/floor.png")); - goat_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/goat_on_a_pole.png")); - logo_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/tojam2023_tagline_header_clear.png")); + wall_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/walls.png")); + floor_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/floor.png")); + goat_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/goat_on_a_pole.png")); + logo_texture = rodeo_gfx_texture_2d_create_from_path(cstr_lit("assets/tojam2023_tagline_header_clear.png")); uint16_t window_width = 1600; uint16_t window_height = 900; collision_wall_world = rodeo_collision_2d_world_create(); @@ -47,10 +47,10 @@ void deinit_wall(void) { rodeo_collision_2d_world_destroy(&collision_wall_world); - rodeo_texture_2d_destroy(&wall_texture); - rodeo_texture_2d_destroy(&floor_texture); - rodeo_texture_2d_destroy(&goat_texture); - rodeo_texture_2d_destroy(&logo_texture); + rodeo_gfx_texture_2d_destroy(wall_texture); + rodeo_gfx_texture_2d_destroy(floor_texture); + rodeo_gfx_texture_2d_destroy(goat_texture); + rodeo_gfx_texture_2d_destroy(logo_texture); } rodeo_collision_2d_world_t * @@ -71,10 +71,12 @@ new_wall( &collision_wall_world, (rodeo_collision_2d_world_item_t) { - .x = x, - .y = y, - .width = width, - .height = height + .rect = { + .x = x, + .y = y, + .width = width, + .height = height + } }); } @@ -85,8 +87,8 @@ coords_inside_wall( ) { c_foreach(i, cvec_collision_2d_world_item, collision_wall_world) { - if (x >= i.ref->x && x <= i.ref->x + i.ref->width && - y >= i.ref->y && y <= i.ref->y + i.ref->height) { + if (x >= i.ref->rect.x && x <= i.ref->rect.x + i.ref->rect.width && + y >= i.ref->rect.y && y <= i.ref->rect.y + i.ref->rect.height) { return true; } } @@ -101,25 +103,25 @@ moving_wall_resolver( { rodeo_collision_2d_world_item_t *p = obj_collision; rodeo_collision_2d_world_item_t *w = wall_collision; - rodeo_collision_2d_world_item_t step = (rodeo_collision_2d_world_item_t){ - .x = p->x + p->dx * rodeo_frame_time_get() / (1000.0f/60.0f), - .y = p->y + p->dy * rodeo_frame_time_get() / (1000.0f/60.0f), - .width = p->width, - .height = p->height + rodeo_rectangle_t step = { + .x = p->rect.x + p->dx * rodeo_gfx_frame_time_get() / (1000.0f/60.0f), + .y = p->rect.y + p->dy * rodeo_gfx_frame_time_get() / (1000.0f/60.0f), + .width = p->rect.width, + .height = p->rect.height }; - rodeo_rectangle_t intersection = rodeo_collision_2d_get_collision_rect(&step, w); + rodeo_rectangle_t intersection = rodeo_collision_2d_get_collision_rect(step, w->rect); // left collision if (intersection.width < intersection.height) { // colliding left/right // if x equal push right if (intersection.x == step.x) { - p->x = w->x + w->width; + p->rect.x = w->rect.x + w->rect.width; if (p->dx < 0) { p->dx = 0; } // else push left } else { - p->x = w->x - p->width; + p->rect.x = w->rect.x - p->rect.width; if (p->dx > 0) { p->dx = 0; } @@ -129,13 +131,13 @@ moving_wall_resolver( // colliding up/down // if y equal push down if (intersection.y == step.y) { - p->y = w->y + w->height; + p->rect.y = w->rect.y + w->rect.height; if (p->dy < 0) { p->dy = 0; } // else push up } else { - p->y = w->y - p->height; + p->rect.y = w->rect.y - p->rect.height; if (p->dy > 0) { p->dy = 0; } @@ -143,7 +145,7 @@ moving_wall_resolver( } // tunneled into a hitbox // don't allow movement - else if (p->width == w->width && p->height == w->height) { + else if (p->rect.width == w->rect.width && p->rect.height == w->rect.height) { p->dx = 0; p->dy = 0; } @@ -156,10 +158,10 @@ draw_level(void) rodeo_rectangle_t logo_size = (rodeo_rectangle_t){0,0,1024,400}; rodeo_rectangle_t logo_dest = (rodeo_rectangle_t){1600-(1024*0.25f),10,1024*0.25f,400*0.25f}; rodeo_rectangle_t goat_size = (rodeo_rectangle_t){0,0,529,1038}; - rodeo_rectangle_t goat_dest = (rodeo_rectangle_t){(1600.0f/2)-(529/2*0.07f),(900.0f/2)-(1038/2*0.07f),529*0.07f,1038*0.07f}; - rodeo_texture_2d_draw(&rect, &rect, &(rodeo_color_RGBAFloat_t){ .array = {0.96f, 0.41f, 0.1f, 1.0f} }, &wall_texture); - rodeo_texture_2d_draw(&rect, &rect, &(rodeo_color_RGBAFloat_t){ .array = {0.52f, 0.31f, 0.73f, 0.33f} }, &floor_texture); - rodeo_texture_2d_draw(&goat_dest, &goat_size, &(rodeo_color_RGBAFloat_t){ .array = {1,1,1,1} }, &goat_texture); - rodeo_texture_2d_draw(&logo_dest, &logo_size, &(rodeo_color_RGBAFloat_t){ .array = {1,1,1,1} }, &logo_texture); + rodeo_rectangle_t goat_dest = (rodeo_rectangle_t){(1600.0f/2)-(529.0f/2*0.07f),(900.0f/2)-(1038.0f/2*0.07f),529*0.07f,1038*0.07f}; + rodeo_gfx_texture_2d_draw(rect, rect, (rodeo_color_RGBAFloat_t){ .array = {0.96f, 0.41f, 0.1f, 1.0f} }, wall_texture); + rodeo_gfx_texture_2d_draw(rect, rect, (rodeo_color_RGBAFloat_t){ .array = {0.52f, 0.31f, 0.73f, 0.33f} }, floor_texture); + rodeo_gfx_texture_2d_draw(goat_dest, goat_size, (rodeo_color_RGBAFloat_t){ .array = {1,1,1,1} }, goat_texture); + rodeo_gfx_texture_2d_draw(logo_dest, logo_size, (rodeo_color_RGBAFloat_t){ .array = {1,1,1,1} }, logo_texture); } |
