summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/player.c134
1 files changed, 121 insertions, 13 deletions
diff --git a/src/player.c b/src/player.c
index 72aedac..4844b96 100644
--- a/src/player.c
+++ b/src/player.c
@@ -19,6 +19,9 @@
 enum {
 	PLAYER_NONE,
 	PLAYER_IDLE,
+	PLAYER_ATTACK1,
+	PLAYER_ATTACK2,
+	PLAYER_ATTACK3,
 	PLAYER_WALK,
 	PLAYER_JUMP,
 	PLAYER_FALL,
@@ -51,7 +54,11 @@ struct anim player_anims[] = {
 static int slash_update(struct projectile *self) {
 	self->x += self->velocity.x;
 	self->y += self->velocity.y;
-	self->hp--;
+	if (self->hp >= 0) {
+		self->hp--;
+	} 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;
@@ -76,9 +83,9 @@ static int slash_update(struct projectile *self) {
 	part->velocity = (struct vec2) {self->velocity.x + x - xx, self->velocity.y + y - yy};
 	part->rect = (SDL_Rect) {8, 0, 4, 4};
 	part->acceleration = (struct vec2) {0, 0};
-	part->hp = 10 - self->hp;
+	part->hp = 10 - (self->hp >= 0? self->hp: -self->hp - 8);
 	entities.particles++;
-	if (self->hp == 0) {
+	if (self->hp == 0 || self->hp == -8) {
 		return 1;
 		self->state = 0;
 	}
@@ -90,12 +97,23 @@ static int slash_draw(struct projectile *self, int camX, int camY) {
 	//SDL_RenderCopy(renderer, self->texture, &rect, &(SDL_Rect) {from_fixed(self->x) - camX - 8, from_fixed(self->y) - camY - 12, 16, 16});
 	//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 * 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}},
-	};
-	SDL_RenderGeometry(renderer, NULL, vertices, 3, NULL, 0);
+	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}},
+		};
+		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}},
+		};
+		SDL_RenderGeometry(renderer, NULL, vertices, 4, (int []) {0, 1, 2, 0, 2, 3}, 6);
+	}
 	return 0;
 }
 
@@ -171,7 +189,7 @@ static int move(struct entity *self) {
 	return on_ground;
 }
 
-static void attack(struct entity *self) {
+static void attack(struct entity *self, int a) {
 	if (!input_s(input_pressed)) {
 		return;
 	}
@@ -185,7 +203,7 @@ static void attack(struct entity *self) {
 			0, 0, 0, 0,
 		},
 		.state = PLAYER_IDLE,
-		.hp = 8,
+		.hp = a? 8: -16,
 		.timer = 0,
 		.facing = self->facing,
 		.faction = FACTION_PLAYER,
@@ -222,8 +240,98 @@ static int player_update(struct entity *self) {
 				self->velocity.y = -JUMP;
 				anim(self, PLAYER_A_JUMP);
 				self->state = PLAYER_JUMP;
+			struct particle *part = entities.particle + entities.particles;
+			part->x = self->x - to_fixed(-3) - to_fixed(1);
+			part->y = self->y - 2;
+			part->velocity = (struct vec2) {12, -8};
+			part->rect = (SDL_Rect) {0, 0, 4, 4};
+			part->acceleration = (struct vec2) {0, 1};
+			part->hp = 5;
+			entities.particles++;
+			part = entities.particle + entities.particles;
+			part->x = self->x - to_fixed(3) - to_fixed(1);
+			part->y = self->y - 2;
+			part->velocity = (struct vec2) {-12, -8};
+			part->rect = (SDL_Rect) {0, 0, 4, 4};
+			part->acceleration = (struct vec2) {0, 1};
+			part->hp = 5;
+			entities.particles++;
+			}
+			attack(self, 1);
+			if (input_s(input_pressed)) {
+				self->state = PLAYER_ATTACK1;
+				self->timer = 30;
+			}
+			break;
+
+		case PLAYER_ATTACK1:
+			if (move(self) == false) {
+				self->velocity.y = 0;
+				anim(self, PLAYER_A_FALL);
+				self->state = PLAYER_FALL;
+			}
+			if (input_right(input_held) - input_left(input_held)) {
+				anim(self, PLAYER_A_WALK);
+				self->state = PLAYER_WALK;
+			}
+			if (input_a(input_held)) {
+				self->velocity.y = -JUMP;
+				anim(self, PLAYER_A_JUMP);
+				self->state = PLAYER_JUMP;
+			}
+			attack(self, 0);
+			if (input_s(input_pressed)) {
+				self->state = PLAYER_ATTACK2;
+				self->timer = 30;
+			}
+			if (self->timer-- == 0) {
+				self->state = PLAYER_IDLE;
+			}
+			break;
+
+		case PLAYER_ATTACK2:
+			if (move(self) == false) {
+				self->velocity.y = 0;
+				anim(self, PLAYER_A_FALL);
+				self->state = PLAYER_FALL;
+			}
+			if (input_right(input_held) - input_left(input_held)) {
+				anim(self, PLAYER_A_WALK);
+				self->state = PLAYER_WALK;
+			}
+			if (input_a(input_held)) {
+				self->velocity.y = -JUMP;
+				anim(self, PLAYER_A_JUMP);
+				self->state = PLAYER_JUMP;
+			}
+			attack(self, 1);
+			if (input_s(input_pressed)) {
+				self->state = PLAYER_ATTACK3;
+				self->timer = 60;
+			}
+			if (self->timer-- == 0) {
+				self->state = PLAYER_IDLE;
+			}
+			break;
+
+		case PLAYER_ATTACK3:
+			if (move(self) == false) {
+				self->velocity.y = 0;
+				anim(self, PLAYER_A_FALL);
+				self->state = PLAYER_FALL;
+			}
+			if (input_right(input_held) - input_left(input_held)) {
+				anim(self, PLAYER_A_WALK);
+				self->state = PLAYER_WALK;
+			}
+			if (input_a(input_held)) {
+				self->velocity.y = -JUMP;
+				anim(self, PLAYER_A_JUMP);
+				self->state = PLAYER_JUMP;
+			}
+			if (self->timer-- == 0) {
+				self->state = PLAYER_IDLE;
 			}
-			attack(self);
 			break;
 
 		case PLAYER_WALK:;
@@ -250,7 +358,7 @@ static int player_update(struct entity *self) {
 				anim(self, PLAYER_A_JUMP);
 				self->state = PLAYER_JUMP;
 			}
-			attack(self);
+			attack(self, 1);
 			break;
 		
 		case PLAYER_JUMP: