diff options
-rw-r--r-- | src/hvy_guns.c | 12 | ||||
-rw-r--r-- | src/player.c | 24 | ||||
-rw-r--r-- | src/tilemap.c | 12 | ||||
-rw-r--r-- | src/tilemap.h | 3 |
4 files changed, 31 insertions, 20 deletions
diff --git a/src/hvy_guns.c b/src/hvy_guns.c index 1eabbe2..106cea6 100644 --- a/src/hvy_guns.c +++ b/src/hvy_guns.c @@ -324,8 +324,16 @@ int hvy_chaingun(struct gun *self, struct entity *parent, struct entity *target) entities.projectiles++; if (self->counter > HVY_CHAINGUN_MIN_RELOAD) { self->counter--; + self->timer = self->counter; + } else { + // this allows the projectiles to keep cycling up and down + // without the fire rate getting all wonky + self->counter--; + self->timer = HVY_CHAINGUN_MIN_RELOAD; + if (self->counter <= HVY_CHAINGUN_MIN_RELOAD - 4) { + self->counter = HVY_CHAINGUN_MIN_RELOAD; + } } - self->timer = self->counter; } else { self->counter = HVY_CHAINGUN_RELOAD; } @@ -335,7 +343,7 @@ int hvy_chaingun(struct gun *self, struct entity *parent, struct entity *target) void hvy_chaingun_new(struct gun *self, int x, int y) { self->update = hvy_chaingun; self->timer = HVY_CHAINGUN_RELOAD; - self->counter = 0; + self->counter = HVY_CHAINGUN_RELOAD; self->x = to_fixed(x); self->y = to_fixed(y); } diff --git a/src/player.c b/src/player.c index 3605a6d..a28a6c9 100644 --- a/src/player.c +++ b/src/player.c @@ -78,10 +78,10 @@ static int slash_update(struct projectile *self) { } else { self->hp++; } - int x = from_fixed(self->x) + self->facing * sin(self->hp / 2) * SLASH_REACH_X; - int y = from_fixed(self->y) - cos(self->hp / 2) * SLASH_REACH_Y; - int xx = from_fixed(self->x) + self->facing * sin(self->hp / 2 + 1) * SLASH_REACH_X; - int yy = from_fixed(self->y) - cos(self->hp / 2 + 1) * SLASH_REACH_Y; + int x = from_fixed(self->x) + self->facing * sin(self->hp / 2.0) * SLASH_REACH_X; + int y = from_fixed(self->y) - cos(self->hp / 2.0) * SLASH_REACH_Y; + int xx = from_fixed(self->x) + self->facing * sin(self->hp / 2.0 + 1) * SLASH_REACH_X; + int yy = from_fixed(self->y) - cos(self->hp / 2.0 + 1) * SLASH_REACH_Y; self->hitbox = (struct hitbox) {.left = x - 2, .right = x + 2, .top = y - 2, .bottom = y + 2}; for (int i = 0, e = entities.enemies; i < 64 && e; i++) { if (entities.enemy[i].state) { @@ -118,18 +118,18 @@ static int slash_draw(struct projectile *self, int camX, int camY) { int const x = from_fixed(self->x) - camX, y = from_fixed(self->y) - camY; if (self->hp >= 0) { SDL_Vertex vertices[4] = { - {.position = {x + from_fixed(self->velocity.x) + self->facing * sin(self->hp / 2 - 1) * SLASH_REACH_X, y - cos(self->hp / 2 - 1) * SLASH_REACH_Y}, .color = {255, 191, 63, 255}}, - {.position = {x + self->facing * sin(self->hp / 2 + 0) * SLASH_REACH_X, y - cos(self->hp / 2 + 0) * SLASH_REACH_Y}, .color = {255, 127, 0, 255}}, - {.position = {x - from_fixed(self->velocity.x) + self->facing * sin(self->hp / 2 + 1) * SLASH_REACH_X, y - cos(self->hp / 2 + 1) * SLASH_REACH_Y}, .color = {255, 127, 0, 255}}, - {.position = {x - from_fixed(self->velocity.x * 2) + self->facing * sin(self->hp / 2 + 2) * SLASH_REACH_X, y - cos(self->hp / 2 + 2) * SLASH_REACH_Y}, .color = {255, 127, 0, 0}}, + {.position = {x + from_fixed(self->velocity.x) + self->facing * sin(self->hp / 2.0 - 1) * SLASH_REACH_X, y - cos(self->hp / 2.0 - 1) * SLASH_REACH_Y}, .color = {255, 191, 63, 255}}, + {.position = {x + self->facing * sin(self->hp / 2.0 + 0) * SLASH_REACH_X, y - cos(self->hp / 2.0 + 0) * SLASH_REACH_Y}, .color = {255, 127, 0, 255}}, + {.position = {x - from_fixed(self->velocity.x) + self->facing * sin(self->hp / 2.0 + 1) * SLASH_REACH_X, y - cos(self->hp / 2.0 + 1) * SLASH_REACH_Y}, .color = {255, 127, 0, 255}}, + {.position = {x - from_fixed(self->velocity.x * 2) + self->facing * sin(self->hp / 2.0 + 2) * SLASH_REACH_X, y - cos(self->hp / 2.0 + 2) * SLASH_REACH_Y}, .color = {255, 127, 0, 0}}, }; SDL_RenderGeometry(renderer, NULL, vertices, 4, (int []) {0, 1, 2, 0, 2, 3}, 6); } else { SDL_Vertex vertices[4] = { - {.position = {x - from_fixed(self->velocity.x) + self->facing * sin(self->hp / 2 + 1) * SLASH_REACH_X, y - cos(self->hp / 2 + 1) * SLASH_REACH_Y}, .color = {255, 191, 63, 255}}, - {.position = {x + + self->facing * sin(self->hp / 2 + 0) * SLASH_REACH_X, y - cos(self->hp / 2 + 0) * SLASH_REACH_Y}, .color = {255, 127, 0, 255}}, - {.position = {x + from_fixed(self->velocity.x) + self->facing * sin(self->hp / 2 - 1) * SLASH_REACH_X, y - cos(self->hp / 2 - 1) * SLASH_REACH_Y}, .color = {255, 127, 0, 255}}, - {.position = {x + from_fixed(self->velocity.x * 2) + self->facing * sin(self->hp / 2 - 2) * SLASH_REACH_X, y - cos(self->hp / 2 - 2) * SLASH_REACH_Y}, .color = {255, 127, 0, 0}}, + {.position = {x - from_fixed(self->velocity.x) + self->facing * sin(self->hp / 2.0 + 1) * SLASH_REACH_X, y - cos(self->hp / 2.0 + 1) * SLASH_REACH_Y}, .color = {255, 191, 63, 255}}, + {.position = {x + + self->facing * sin(self->hp / 2.0 + 0) * SLASH_REACH_X, y - cos(self->hp / 2.0 + 0) * SLASH_REACH_Y}, .color = {255, 127, 0, 255}}, + {.position = {x + from_fixed(self->velocity.x) + self->facing * sin(self->hp / 2.0 - 1) * SLASH_REACH_X, y - cos(self->hp / 2.0 - 1) * SLASH_REACH_Y}, .color = {255, 127, 0, 255}}, + {.position = {x + from_fixed(self->velocity.x * 2) + self->facing * sin(self->hp / 2.0 - 2) * SLASH_REACH_X, y - cos(self->hp / 2.0 - 2) * SLASH_REACH_Y}, .color = {255, 127, 0, 0}}, }; SDL_RenderGeometry(renderer, NULL, vertices, 4, (int []) {0, 1, 2, 0, 2, 3}, 6); } diff --git a/src/tilemap.c b/src/tilemap.c index 8a74d9c..ccfe990 100644 --- a/src/tilemap.c +++ b/src/tilemap.c @@ -2,6 +2,7 @@ #include <stdlib.h> #include <stdint.h> #include <string.h> +#include <limits.h> #include "loader.h" #include "main.h" // renderer @@ -70,17 +71,13 @@ collision_T tilemap_area(struct tilemap *tilemap, int x1, int y1, int x2, int y2 if (x1 < 0) { x1 = 0; } - if (x2 < 0) { - x2 = 0; - } else if (x2 >= tilemap->width) { + if (x2 >= (signed) tilemap->width) { x2 = tilemap->width - 1; } if (y1 < 0) { y1 = 0; } - if (y2 < 0) { // for some reason you can bonk your head on nothing without this - y2 = 0; - } else if (y2 >= tilemap->height) { + if (y2 >= (signed) tilemap->height) { y2 = tilemap->height - 1; } return tilemap_area_raw(tilemap, x1, y1, x2, y2); @@ -234,6 +231,9 @@ struct tilemap *tilemap_load(void *data, size_t size) { if (map->width * map->height * map->layers > size - sizeof (struct map)) { goto fail; } + if (map->width > INT_MAX || map->height > INT_MAX) { + goto fail; + } tilemap->backdrop.r = map->backdrop.r; tilemap->backdrop.g = map->backdrop.g; diff --git a/src/tilemap.h b/src/tilemap.h index 0f2bebe..4b6774a 100644 --- a/src/tilemap.h +++ b/src/tilemap.h @@ -21,6 +21,9 @@ extern struct tilemap { } *tilemap, *next_tilemap; // tilemap collision functions +// public functions use pixel coordinates (not subpixel) +// raw functions have no bounds checking and use tile coordinates +// you shouldnt need to use the raw functions collision_T tilemap_tile_raw(struct tilemap *tilemap, int x, int y); collision_T tilemap_tile(struct tilemap *tilemap, int x, int y); |