diff options
Diffstat (limited to 'src/player.c')
-rw-r--r-- | src/player.c | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/src/player.c b/src/player.c index 0bf09de..a28a6c9 100644 --- a/src/player.c +++ b/src/player.c @@ -4,6 +4,8 @@ #include "input.h" #include "tilemap.h" #include <stdbool.h> +#include <stdlib.h> +#include <string.h> #include <math.h> #include "particles.h" @@ -38,6 +40,11 @@ enum { PLAYER_A_JUMP, PLAYER_A_FALL, PLAYER_A_FALL2, + PLAYER_A_HOP, + PLAYER_A_HOP2, + PLAYER_A_HOP3, + PLAYER_A_CROUCH, + PLAYER_A_CROUCH2, }; struct anim player_anims[] = { @@ -50,6 +57,11 @@ struct anim player_anims[] = { {PLAYER_A_JUMP, {16, 0, 16, 16}, 300}, {PLAYER_A_FALL2, {32, 0, 16, 16}, 15}, {PLAYER_A_FALL2, {48, 0, 16, 16}, 15}, + {PLAYER_A_HOP2, {16, 0, 16, 16}, 4}, + {PLAYER_A_HOP3, {32, 0, 16, 16}, 4}, + {PLAYER_A_CROUCH, {48, 0, 16, 16}, 4}, + {PLAYER_A_CROUCH2, {64, 0, 16, 16}, 300}, + {PLAYER_A_CROUCH, {80, 0, 16, 16}, 2}, }; enum slash_type { @@ -66,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) { @@ -81,7 +93,7 @@ static int slash_update(struct projectile *self) { continue; } if (hitbox_overlap(self->hitbox, entities.enemy[i].hitbox)) { - entities.enemy[i].hurt(entities.enemy + i, (struct damage) {self->ext == SLASH_STRONG? 2: 1, self->ext == SLASH_NORMAL? 10: 60}); + entities.enemy[i].hurt(entities.enemy + i, (struct damage) {(enum slash_type) self->ext == SLASH_STRONG? 2: 1, self->ext == SLASH_NORMAL? 10: 60}); } } struct particle *part = entities.particle + entities.particles; @@ -106,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); } @@ -291,6 +303,7 @@ static int player_update(struct entity *self) { } attack(self, 0, SLASH_NORMAL); if (input_s(input_pressed)) { + anim(self, PLAYER_A_CROUCH); self->state = PLAYER_ATTACK2; self->timer = 30; } @@ -316,10 +329,12 @@ static int player_update(struct entity *self) { } attack(self, 1, SLASH_STRONG); if (input_s(input_pressed)) { + anim(self, PLAYER_A_HOP); self->state = PLAYER_ATTACK3; self->timer = 60; } if (self->timer-- == 0) { + anim(self, PLAYER_A_IDLE); self->state = PLAYER_IDLE; } break; @@ -340,6 +355,7 @@ static int player_update(struct entity *self) { self->state = PLAYER_JUMP; } if (self->timer-- == 0) { + anim(self, PLAYER_A_IDLE); self->state = PLAYER_IDLE; } break; |