Skip to content

Commit

Permalink
cgame: Implement crosshair blob effect and cg_crosshairHealth on hit
Browse files Browse the repository at this point in the history
  • Loading branch information
LegendaryGuard committed Sep 10, 2023
1 parent 1ecb533 commit ad70d2c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/bfp_cvars_task.md
Expand Up @@ -47,7 +47,6 @@

- g_hitStun [0/1]: turn on or off the melee hit stun.
- cg_drawKiWarning [0/1]: turn on or off the low ki warning.
- cg_crosshairhealth [0/1]: turn on or off the feature that makes the crosshair turn red when you score a hit.

#### Cvar Gametypes:

Expand Down Expand Up @@ -77,6 +76,7 @@
- [x] ~~cg_yrgolroxor~~
- [x] ~~cg_thirdPersonHeight~~
- [x] ~~cg_crosshairColor~~
- [x] ~~cg_crosshairHealth~~

#### Cvar Gametypes:

Expand Down
18 changes: 12 additions & 6 deletions source/cgame/cg_draw.c
Expand Up @@ -1721,24 +1721,30 @@ static void CG_DrawCrosshair(void) {
}
#endif

#if 0
// set color based on health
if ( cg_crosshairHealth.integer ) {
vec4_t hcolor;

CG_ColorForHealth( hcolor );
trap_R_SetColor( hcolor );
}
#endif

CG_SetCrosshairColor(); // BFP - Crosshair color

w = h = cg_crosshairSize.value;

// pulse the size of the crosshair when picking up items
f = cg.time - cg.itemPickupBlendTime;
if ( f > 0 && f < ITEM_BLOB_TIME ) {
f /= ITEM_BLOB_TIME;
w *= ( 1 + f );
h *= ( 1 + f );
// BFP - pulse the size of the crosshair when hitting someone (before: when picking up items)
f = cg.time - cg.opponentHitBlendTime;
if ( f > 0 && f < HIT_BLOB_TIME ) {
f /= HIT_BLOB_TIME;
// BFP - Make crosshair size starting from biggest to current
w = LERP( w*2, w, f ); // before: w *= ( 1 + f );
h = LERP( h*2, h, f ); // before: h *= ( 1 + f );
if ( cg_crosshairHealth.integer && f <= 0.35f ) { // BFP - BFP crosshair health feature
trap_R_SetColor( colorRed );
}
}

x = cg_crosshairX.integer;
Expand Down
2 changes: 1 addition & 1 deletion source/cgame/cg_event.c
Expand Up @@ -347,7 +347,7 @@ A new item was picked up this frame
static void CG_ItemPickup( int itemNum ) {
cg.itemPickup = itemNum;
cg.itemPickupTime = cg.time;
cg.itemPickupBlendTime = cg.time;
// cg.itemPickupBlendTime = cg.time; // BFP - BFP doesn't use the item pickup effect for the crosshair, now it's reused for when some opponent is being hit
// see if it should be the grabbed weapon
if ( bg_itemlist[itemNum].giType == IT_WEAPON ) {
// select it immediately
Expand Down
6 changes: 4 additions & 2 deletions source/cgame/cg_local.h
Expand Up @@ -47,7 +47,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define WEAPON_SELECT_TIME 1400
#define ITEM_SCALEUP_TIME 1000
#define ZOOM_TIME 150
#define ITEM_BLOB_TIME 200
#define HIT_BLOB_TIME 200 // BFP - For crosshair health, before ITEM_BLOB_TIME
#define MUZZLE_FLASH_TIME 20
#define SINK_TIME 1000 // time for fragments to sink into ground before going away
#define ATTACKER_HEAD_TIME 10000
Expand Down Expand Up @@ -590,7 +590,9 @@ typedef struct {

int itemPickup;
int itemPickupTime;
int itemPickupBlendTime; // the pulse around the crosshair is timed seperately

// BFP - before itemPickupBlendTime
int opponentHitBlendTime; // the pulse around the crosshair is timed seperately

int weaponSelectTime;
int weaponAnimation;
Expand Down
1 change: 1 addition & 0 deletions source/cgame/cg_playerstate.c
Expand Up @@ -310,6 +310,7 @@ void CG_CheckLocalSounds( playerState_t *ps, playerState_t *ops ) {

// hit changes
if ( ps->persistant[PERS_HITS] > ops->persistant[PERS_HITS] ) {
cg.opponentHitBlendTime = cg.time + 0.5f; // BFP - For crosshair opponent hit effect
armor = ps->persistant[PERS_ATTACKEE_ARMOR] & 0xff;
health = ps->persistant[PERS_ATTACKEE_ARMOR] >> 8;
trap_S_StartLocalSound( cgs.media.hitSound, CHAN_LOCAL_SOUND );
Expand Down

0 comments on commit ad70d2c

Please sign in to comment.