From c851581465b9bae8ac679415368d792cefd76de2 Mon Sep 17 00:00:00 2001 From: zlago Date: Mon, 7 Oct 2024 19:07:58 +0200 Subject: fixes --- src/player.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/player.c') diff --git a/src/player.c b/src/player.c index a6fa86d..f36ae1a 100644 --- a/src/player.c +++ b/src/player.c @@ -13,6 +13,9 @@ #define GRAVITY 1 #define JUMP 30 +#define SLASH_REACH_X 8 +#define SLASH_REACH_Y 6 + enum { PLAYER_NONE, PLAYER_IDLE, @@ -49,6 +52,9 @@ static int slash_update(struct projectile *self) { self->x += self->velocity.x; self->y += self->velocity.y; self->hp--; + int x = from_fixed(self->x) + self->facing * sin(self->hp + 0) * SLASH_REACH_X; + int y = from_fixed(self->y) - cos(self->hp + 0) * SLASH_REACH_Y; + self->hitbox = (struct hitbox) {.left = x, .right = x, .top = y, .bottom = y}; #if 0 struct particle *part = entities.particle + entities.particles; part->x = self->x + to_fixed(self->facing >= 0? sin(self->hp): -sin(self->hp)) * 6; @@ -72,9 +78,9 @@ static int slash_draw(struct projectile *self, int camX, int camY) { //SDL_RenderFillRect(renderer, &(SDL_Rect) {from_fixed(self->x) - camX - 8, from_fixed(self->y) - camY - 12, 16, 16}); int const x = from_fixed(self->x) - camX, y = from_fixed(self->y) - camY; SDL_Vertex vertices[3] = { - {.position = {x + from_fixed(self->velocity.x) + ((self->facing >= 0)? sin(self->hp - 1): -sin(self->hp - 1)) * 8, y - cos(self->hp - 1) * 6}, .color = {255, 127, 0, 255}}, - {.position = {x + ((self->facing >= 0)? sin(self->hp + 0): -sin(self->hp + 0)) * 8, y - cos(self->hp + 0) * 6}, .color = {255, 127, 0, 255}}, - {.position = {x - from_fixed(self->velocity.x) + ((self->facing >= 0)? sin(self->hp + 1): -sin(self->hp + 1)) * 8, y - cos(self->hp + 1) * 6}, .color = {255, 127, 0, 255}}, + {.position = {x + from_fixed(self->velocity.x) + self->facing * sin(self->hp - 1) * SLASH_REACH_X, y - cos(self->hp - 1) * SLASH_REACH_Y}, .color = {255, 127, 0, 255}}, + {.position = {x + self->facing * sin(self->hp + 0) * SLASH_REACH_X, y - cos(self->hp + 0) * SLASH_REACH_Y}, .color = {255, 127, 0, 255}}, + {.position = {x - from_fixed(self->velocity.x) + self->facing * sin(self->hp + 1) * SLASH_REACH_X, y - cos(self->hp + 1) * SLASH_REACH_Y}, .color = {255, 127, 0, 255}}, }; SDL_RenderGeometry(renderer, NULL, vertices, 3, NULL, 0); return 0; @@ -287,7 +293,7 @@ static int player_hurt(struct entity *self, int damage) { part->x = self->x; part->y = self->y; part->velocity = (struct vec2) {to_fixed(x), to_fixed(y) - 8}; - part->rect = (SDL_Rect) {0, 0, 4, 4}; + part->rect = (SDL_Rect) {4, 0, 4, 4}; part->acceleration = (struct vec2) {0, 1}; part->hp = 30; entities.particles++; -- cgit 1.4.1-2-gfad0