summary refs log tree commit diff
path: root/src/flier.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/flier.c')
-rw-r--r--src/flier.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/flier.c b/src/flier.c
index f5d33e4..81596d0 100644
--- a/src/flier.c
+++ b/src/flier.c
@@ -5,6 +5,7 @@
 #include <stdbool.h>
 #include <math.h>
 #include <string.h>
+#include "particles.h"
 
 #define SIZE 4
 #define ACCELERATION 1
@@ -79,7 +80,7 @@ static int bullet_update(struct projectile *self) {
 	int y = from_fixed(self->y);
 	self->hitbox = (struct hitbox) {.left = x, .right = x, .top = y, .bottom = y};
 	if (hitbox_overlap(self->hitbox, entities.player[0].hitbox)) {
-		entities.player[0].hurt(entities.player + 0, 1);
+		entities.player[0].hurt(entities.player + 0, (struct damage) {1, 60});
 		return 1;
 	}
 	if (self->hp == 0) {
@@ -90,14 +91,14 @@ static int bullet_update(struct projectile *self) {
 }
 
 static int bullet_draw(struct projectile *self, int camX, int camY) {
-	SDL_Rect rect;
+	SDL_Rect const *rect;
 	if (self->hp & 0x2) {
-		rect = (SDL_Rect) {4, 0, 4, 4};
+		rect = &particle_red;
 	} else {
-		rect = (SDL_Rect) {12, 0, 4, 4};
+		rect = &particle_white;
 	}
-	SDL_RenderCopy(renderer, self->texture, &rect, &(SDL_Rect) {from_fixed(self->x) - camX - 1, from_fixed(self->y) - camY - 1, 4, 4});
-	SDL_RenderCopy(renderer, self->texture, &rect, &(SDL_Rect) {from_fixed(self->x - self->velocity.x) - camX - 1, from_fixed(self->y - self->velocity.y) - camY - 1, 4, 4});
+	SDL_RenderCopy(renderer, self->texture, rect, &(SDL_Rect) {from_fixed(self->x) - camX - 1, from_fixed(self->y) - camY - 1, 4, 4});
+	SDL_RenderCopy(renderer, self->texture, rect, &(SDL_Rect) {from_fixed(self->x - self->velocity.x) - camX - 1, from_fixed(self->y - self->velocity.y) - camY - 1, 4, 4});
 	return 0;
 }
 
@@ -177,7 +178,7 @@ static void move(struct entity *self, signed direction_x, signed direction_y, bo
 	}
 	
 	if (collision_hazard(cx | cy)) {
-		self->hurt(self, 1);
+		self->hurt(self, (struct damage) {1, 60});
 	}
 	
 	self->hitbox.left = from_fixed(self->x) - SIZE / 2;
@@ -357,17 +358,17 @@ static int flier_init(struct entity *self) {
 	return flier_update(self);
 }
 
-static int flier_hurt(struct entity *self, int damage) {
+static int flier_hurt(struct entity *self, struct damage damage) {
 	if (self->iframes == 0) {
-		self->hp -= damage;
-		self->iframes = 60;
+		self->hp -= damage.damage;
+		self->iframes = damage.iframes;
 		for (int x = -1; x <= 1; x += 2) {
 			for (int y = -1; y <= 1; y += 2) {
 				struct particle *part = entities.particle + entities.particles;
 				part->x = self->x;
 				part->y = self->y;
 				part->velocity = (struct vec2) {to_fixed(x), to_fixed(y) - 8};
-				part->rect = (SDL_Rect) {4, 0, 4, 4};
+				part->rect = particle_red;
 				part->acceleration = (struct vec2) {0, 1};
 				part->hp = 30;
 				entities.particles++;