From a6b66783f801d159ee8e7904cf0bff938508427f Mon Sep 17 00:00:00 2001 From: westonCoder Date: Wed, 4 Oct 2023 00:14:55 -0500 Subject: [PATCH] Various Tweaks to Portal Gun Mechanics - tweaked portal gun to have a max fire rate, that is tied to its animation speed (used video of portal1 for reference) - allowed ControllerActionOpenPortal1 and ControllerActionOpenPortal2 actions to be "Holdable" meaning that you can hold down the button and continuously do that action - made sure two portals cant be shot at once, prohibiting both buttons being held at once. video attached: --- src/audio/clips.c | 4 +--- src/audio/clips.h | 2 +- src/controls/controller_actions.c | 4 +++- src/controls/controller_actions.h | 1 + src/scene/portal_gun.c | 16 +++++++++++++++- src/scene/portal_gun.h | 2 ++ src/scene/scene.c | 4 ++-- 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/audio/clips.c b/src/audio/clips.c index ecc77be..eb8d738 100644 --- a/src/audio/clips.c +++ b/src/audio/clips.c @@ -3,13 +3,11 @@ #include "../../build/src/audio/clips.h" -unsigned short soundsSkippable[10] = { +unsigned short soundsSkippable[8] = { SOUNDS_PORTAL_ENTER1, SOUNDS_PORTAL_ENTER2, SOUNDS_PORTAL_EXIT1, SOUNDS_PORTAL_EXIT2, - SOUNDS_PORTALGUN_SHOOT_RED1, - SOUNDS_PORTALGUN_SHOOT_BLUE1, SOUNDS_CONCRETE1, //left foot SOUNDS_CONCRETE2, //right foot SOUNDS_CONCRETE3, //land diff --git a/src/audio/clips.h b/src/audio/clips.h index f7f9f41..ab97a7e 100644 --- a/src/audio/clips.h +++ b/src/audio/clips.h @@ -1,7 +1,7 @@ #ifndef __AUDIO_CLIPS_H__ #define __AUDIO_CLIPS_H__ -extern unsigned short soundsSkippable[10]; +extern unsigned short soundsSkippable[8]; extern unsigned short soundsPortalEnter[2]; extern unsigned short soundsPortalExit[2]; diff --git a/src/controls/controller_actions.c b/src/controls/controller_actions.c index 3527036..8bf7110 100644 --- a/src/controls/controller_actions.c +++ b/src/controls/controller_actions.c @@ -136,7 +136,9 @@ void controllerActionRead() { if (sourceIndex == ControllerActionSourceCUpButton || sourceIndex == ControllerActionSourceDUpButton) { sourceIndex += 3; } - } else if (controllerGetButtonDown(controllerIndex, gActionSourceButtonMask[sourceIndex])) { + }else if (IS_HOLDABLE_ACTION(action) && controllerGetButton(controllerIndex, gActionSourceButtonMask[sourceIndex])){ + controllerActionApply(action); + }else if (controllerGetButtonDown(controllerIndex, gActionSourceButtonMask[sourceIndex])) { controllerActionApply(action); } } diff --git a/src/controls/controller_actions.h b/src/controls/controller_actions.h index bfe3ae2..72c180d 100644 --- a/src/controls/controller_actions.h +++ b/src/controls/controller_actions.h @@ -46,6 +46,7 @@ enum ControllerAction { }; #define IS_DIRECTION_ACTION(action) ((action) >= ControllerActionMove && (action) <= ControllerActionRotate) +#define IS_HOLDABLE_ACTION(action) ((action) >= ControllerActionOpenPortal0 && (action) <= ControllerActionOpenPortal1) #define IS_VALID_SOURCE(source) ((source) >= 0 && (source) < ControllerActionSourceCount) #define MAX_DEADZONE 0.25f diff --git a/src/scene/portal_gun.c b/src/scene/portal_gun.c index bd304d9..6cdc87f 100644 --- a/src/scene/portal_gun.c +++ b/src/scene/portal_gun.c @@ -12,7 +12,7 @@ #include "../../build/assets/models/portal_gun/v_portalgun.h" #include "../../build/assets/materials/static.h" -#define PORTAL_GUN_RECOIL_TIME (0.18f) +#define PORTAL_GUN_RECOIL_TIME (0.22f) #define PORTAL_GUN_NEAR_PLANE 0.05f @@ -52,6 +52,7 @@ void portalGunInit(struct PortalGun* portalGun, struct Transform* at){ portalGun->rigidBody.angularVelocity = gZeroVec; portalGun->portalGunVisible = 0; portalGun->shootAnimationTimer = 0.0; + portalGun->shootTotalAnimationTimer = 0.0; portalGunCalcTargetPosition(portalGun, at, &portalGun->rigidBody.transform.position, 0); @@ -180,6 +181,7 @@ void portalGunUpdate(struct PortalGun* portalGun, struct Player* player) { if (player->flags & PlayerJustShotPortalGun && portalGun->shootAnimationTimer <= 0.0f) { portalGun->shootAnimationTimer = PORTAL_GUN_RECOIL_TIME; + portalGun->shootTotalAnimationTimer = PORTAL_GUN_RECOIL_TIME * 2.0f; } if (portalGun->shootAnimationTimer >= 0.0f) { @@ -189,6 +191,12 @@ void portalGunUpdate(struct PortalGun* portalGun, struct Player* player) { player->flags &= ~PlayerJustShotPortalGun; } } + if (portalGun->shootTotalAnimationTimer >= 0.0f) { + portalGun->shootTotalAnimationTimer -= FIXED_DELTA_TIME; + if (portalGun->shootTotalAnimationTimer <= 0.0f){ + portalGun->shootTotalAnimationTimer = 0.0f; + } + } for (int i = 0; i < 2; ++i) { struct PortalGunProjectile* projectile = &portalGun->projectiles[i]; @@ -258,4 +266,10 @@ void portalGunFire(struct PortalGun* portalGun, int portalIndex, struct Ray* ray vector3Add(&projectile->effectOffset, &ray->origin, &fireFrom); portalTrailPlay(&projectile->trail, &fireFrom, &hit.at); +} +int portalGunIsFiring(struct PortalGun* portalGun){ + if (portalGun->shootTotalAnimationTimer > 0.0f){ + return 1; + } + return 0; } \ No newline at end of file diff --git a/src/scene/portal_gun.h b/src/scene/portal_gun.h index b9239ad..05789f3 100644 --- a/src/scene/portal_gun.h +++ b/src/scene/portal_gun.h @@ -31,6 +31,7 @@ struct PortalGun { struct RigidBody rigidBody; int portalGunVisible; float shootAnimationTimer; + float shootTotalAnimationTimer; struct PortalGunProjectile projectiles[2]; }; @@ -41,5 +42,6 @@ void portalGunUpdate(struct PortalGun* portalGun, struct Player* player); void portalGunRenderReal(struct PortalGun* portalGun, struct RenderState* renderState, struct Camera* fromCamera); void portalGunFire(struct PortalGun* portalGun, int portalIndex, struct Ray* ray, struct Vector3* playerUp, int roomIndex); +int portalGunIsFiring(struct PortalGun* portalGun); #endif \ No newline at end of file diff --git a/src/scene/scene.c b/src/scene/scene.c index 70ef3c2..b3a73a6 100644 --- a/src/scene/scene.c +++ b/src/scene/scene.c @@ -347,14 +347,14 @@ void sceneCheckPortals(struct Scene* scene) { sceneFirePortal(scene, &scene->savedPortal.ray, &scene->savedPortal.transformUp, scene->savedPortal.portalIndex, scene->savedPortal.roomIndex, 0, 0); } - if (fireOrange && hasOrange && !playerIsGrabbing(&scene->player)) { + if (fireOrange && !fireBlue && hasOrange && !playerIsGrabbing(&scene->player) && !portalGunIsFiring(&scene->portalGun)) { portalGunFire(&scene->portalGun, 0, &raycastRay, &playerUp, scene->player.body.currentRoom); scene->player.flags |= PlayerJustShotPortalGun; hudPortalFired(&scene->hud, 0); soundPlayerPlay(soundsPortalgunShoot[0], 1.0f, 1.0f, NULL, NULL); } - if ((fireBlue || (!hasOrange && fireOrange)) && hasBlue && !playerIsGrabbing(&scene->player)) { + if ((fireBlue || (!hasOrange && fireOrange)) && !fireOrange && hasBlue && !playerIsGrabbing(&scene->player) &&!portalGunIsFiring(&scene->portalGun)) { portalGunFire(&scene->portalGun, 1, &raycastRay, &playerUp, scene->player.body.currentRoom); scene->player.flags |= PlayerJustShotPortalGun; hudPortalFired(&scene->hud, 1);