diff options
| author | BoredGuy <osome3717@gmail.com> | 2025-09-11 22:10:05 +0300 |
|---|---|---|
| committer | BoredGuy <osome3717@gmail.com> | 2025-09-11 22:10:05 +0300 |
| commit | c326d6c5297667304cec5f78eede6e3c94163431 (patch) | |
| tree | 1c33ee0ed87fdb0de436f7ba9020c95fc9660e77 /src/barrel.c | |
| parent | c2add3e23ee1b69f059d5b78e33c0a922dc1a22d (diff) | |
A lot of stuff tbh
- Added collision response to barrel
- Transparency effects added
Diffstat (limited to 'src/barrel.c')
| -rw-r--r-- | src/barrel.c | 45 |
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); } |
