summaryrefslogtreecommitdiff
path: root/src/barrel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/barrel.c')
-rw-r--r--src/barrel.c45
1 files changed, 36 insertions, 9 deletions
diff --git a/src/barrel.c b/src/barrel.c
index df1e29e..474b151 100644
--- a/src/barrel.c
+++ b/src/barrel.c
@@ -2,6 +2,14 @@
#include "barrel_data.h"
#include "utils.h"
#include "assets.h"
+#include "physics.h"
+#include "constants.h"
+#include <raymath.h>
+
+enum Barrel_State {
+ BARREL_NEUTRAL,
+ BARREL_DAMAGED
+};
void AddBarrel(float xpos, float ypos) {
Entity barrel = {0};
@@ -15,14 +23,10 @@ void AddBarrel(float xpos, float ypos) {
Sprite barrelSprite = (Sprite) {
.texture = barrelTexture->texture,
.layer = Foreground_Layer,
+ .alpha = 1.0,
.destRect = destRect,
- .srcRect = {
- .x = 0,
- .y = 0,
- .width = barrelTexture->texture.width / 2,
- .height = barrelTexture->texture.height
- }
+ .srcRect = srcRect
};
AddSpriteToEntity(&barrel, barrelSprite);
@@ -31,6 +35,8 @@ void AddBarrel(float xpos, float ypos) {
barrel.hurtBoxes[0] = physicsCollider;
barrel.numHurtBoxes = 1;
+ barrel.state = BARREL_NEUTRAL;
+
#ifdef BEATEMUP_DEBUG
barrel.physicsColliderColor = RED;
barrel.hurtboxColors[0] = BLUE;
@@ -39,10 +45,31 @@ void AddBarrel(float xpos, float ypos) {
AddEntity(&barrel);
}
-void UpdateBarrel(float dt) {
- UNUSED(dt);
+void UpdateBarrel(Entity* barrel, float dt) {
+ if (barrel->state == BARREL_DAMAGED) {
+ barrel->velocity.y += GRAVITY * dt * 0.5;
+ MoveWithoutPhysics(barrel, dt);
+ barrel->velocity.y += GRAVITY * dt * 0.5;
+
+ barrel->sprites[0].alpha =
+ 1.0 - (barrel->timeSinceLastHit / BARREL_REMOVE_TIME);
+
+ barrel->timeSinceLastHit += dt;
+ if (barrel->timeSinceLastHit > BARREL_REMOVE_TIME)
+ barrel->flags &= ~ENTITY_ALLOCATED;
+ }
+}
+
+void GetDamaged(Entity* barrel) {
+ barrel->sprites[0].srcRect = srcRectDamaged;
+
+ barrel->flags &= ~ENTITY_PHYSICS_ACTIVE;
+ barrel->state = BARREL_DAMAGED;
+
+ barrel->velocity = (Vector2) {100.0f, -400.0f};
+ barrel->timeSinceLastHit = 0.0f;
}
void BarrelHandleCollision(Entity* barrel) {
- barrel->flags &= !ENTITY_ALLOCATED;
+ GetDamaged(barrel);
}