summary refs log tree commit diff
path: root/src/walker.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/walker.c')
-rw-r--r--src/walker.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/walker.c b/src/walker.c
index 49595ae..6441909 100644
--- a/src/walker.c
+++ b/src/walker.c
@@ -4,6 +4,7 @@
 #include "tilemap.h"
 #include <stdbool.h>
 #include <math.h>
+#include "particles.h"
 
 #define SIZE 4
 #define ACCELERATION 1
@@ -83,7 +84,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) {
@@ -94,14 +95,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});
 	//SDL_RenderFillRect(renderer, &(SDL_Rect) {from_fixed(self->x) - camX - 8, from_fixed(self->y) - camY - 12, 16, 16});
 	return 0;
 }
@@ -168,7 +169,7 @@ static int move(struct entity *self, signed direction) {
 	}
 	
 	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;
@@ -359,17 +360,17 @@ static int walker_update(struct entity *self) {
 	return 0;
 }
 
-static int walker_hurt(struct entity *self, int damage) {
+static int walker_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++;