summaryrefslogtreecommitdiff
path: root/src/walker.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/walker.c')
-rw-r--r--src/walker.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/walker.c b/src/walker.c
index fbb80d4..49595ae 100644
--- a/src/walker.c
+++ b/src/walker.c
@@ -82,16 +82,6 @@ static int bullet_update(struct projectile *self) {
int x = from_fixed(self->x);
int y = from_fixed(self->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;
- part->y = self->y - to_fixed(cos(self->hp)) * 4;
- part->velocity = (struct vec2) {0, 0};
- part->rect = (SDL_Rect) {0, 0, 4, 4};
- part->acceleration = (struct vec2) {0, 0};
- part->hp = 5;
- entities.particles++;
- #endif
if (hitbox_overlap(self->hitbox, entities.player[0].hitbox)) {
entities.player[0].hurt(entities.player + 0, 1);
return 1;
@@ -104,7 +94,12 @@ static int bullet_update(struct projectile *self) {
}
static int bullet_draw(struct projectile *self, int camX, int camY) {
- SDL_Rect rect = {4, 0, 4, 4};
+ SDL_Rect rect;
+ if (self->hp & 0x2) {
+ rect = (SDL_Rect) {4, 0, 4, 4};
+ } else {
+ rect = (SDL_Rect) {12, 0, 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});
@@ -277,6 +272,12 @@ static int walker_update(struct entity *self) {
move(self, 0);
ext->facing = self->x > entities.player[0].x? -1: 1;
self->facing = ext->facing;
+ self->timer--;
+ if (self->timer == 0) {
+ anim(self, WALKER_A_ATTACK);
+ self->state = WALKER_ALERT_ATTACK;
+ self->timer = ext->attack_delay2;
+ }
if (abs(entities.player[0].x - self->x) > CHASE_RANGE) {
if (is_walkable(self->x + to_fixed(ext->facing * WALKABLE_CHECK_DISTANCE), self->y)) {
anim(self, WALKER_A_WALK);
@@ -294,12 +295,7 @@ static int walker_update(struct entity *self) {
}
if (abs(entities.player[0].x - self->x) + abs(entities.player[0].y - self->y) > ext->give_up_range) {
self->state = WALKER_IDLE;
- }
- self->timer--;
- if (self->timer == 0) {
- anim(self, WALKER_A_ATTACK);
- self->state = WALKER_ALERT_ATTACK;
- self->timer = ext->attack_delay2;
+ self->timer = ext->idle_time;
}
break;