mirror of
https://github.com/softdorothy/GliderPRO.git
synced 2024-11-22 05:31:29 +00:00
1 line
7.8 KiB
C
1 line
7.8 KiB
C
|
//============================================================================
//----------------------------------------------------------------------------
// RubberBands.c
//----------------------------------------------------------------------------
//============================================================================
#include "Externs.h"
#include "RectUtils.h"
#define kRubberBandVelocity 20
#define kBandFallCount 4
#define kKillBandMode -1
void CheckBandCollision (short);
void KillBand (short);
bandPtr bands;
Rect bandsSrcRect;
Rect bandRects[3];
GWorldPtr bandsSrcMap;
GWorldPtr bandsMaskMap;
short numBands, bandHitLast;
extern hotPtr hotSpots;
extern long gameFrame;
extern short nHotSpots, leftThresh, rightThresh;
extern Boolean twoPlayerGame, onePlayerLeft, playerDead;
//============================================================== Functions
//-------------------------------------------------------------- CheckBandCollision
void CheckBandCollision (short who)
{
short i, action, whoLinked;
Boolean collided, nothingCollided;
nothingCollided = true;
if ((leftThresh == kLeftWallLimit) && (bands[who].dest.left < kLeftWallLimit))
{
if (bands[who].hVel < 0)
bands[who].hVel = -bands[who].hVel;
bands[who].dest.left = kLeftWallLimit;
bands[who].dest.right = bands[who].dest.left + 16;
PlayPrioritySound(kBandReboundSound, kBandReboundPriority);
collided = true;
}
else if ((rightThresh == kRightWallLimit) && (bands[who].dest.right > kRightWallLimit))
{
if (bands[who].hVel > 0)
bands[who].hVel = -bands[who].hVel;
bands[who].dest.right = kRightWallLimit;
bands[who].dest.left = bands[who].dest.right - 16;
PlayPrioritySound(kBandReboundSound, kBandReboundPriority);
collided = true;
}
for (i = 0; i < nHotSpots; i++)
{
if (hotSpots[i].isOn)
{
action = hotSpots[i].action;
if ((action == kDissolveIt) || (action == kRewardIt) ||
(action == kSwitchIt) || (action == kTriggerIt) ||
(action == kBounceIt))
{
if (bands[who].dest.bottom < hotSpots[i].bounds.top)
collided = false;
else if (bands[who].dest.top > hotSpots[i].bounds.bottom)
collided = false;
else if (bands[who].dest.right < hotSpots[i].bounds.left)
collided = false;
else if (bands[who].dest.left > hotSpots[i].bounds.right)
collided = false;
else
collided = true;
if (collided)
{
nothingCollided = false; // we have detected a collision
if (bandHitLast != i) // don't count it if same as last frame
{ // we don't want rapid on/off toggles
bandHitLast = i; // note who so we don't double-toggle it
if ((action == kDissolveIt) || (action == kBounceIt))
{
if (bands[who].hVel > 0)
{
if ((bands[who].dest.right - bands[who].hVel) <
hotSpots[i].bounds.left)
{
bands[who].hVel = -bands[who].hVel;
bands[who].dest.right = hotSpots[i].bounds.left;
bands[who].dest.left = bands[who].dest.right - 16;
}
else
bands[who].mode = kKillBandMode;
}
else
{
if ((bands[who].dest.left - bands[who].hVel) >
hotSpots[i].bounds.right)
{
bands[who].hVel = -bands[who].hVel;
bands[who].dest.left = hotSpots[i].bounds.right;
bands[who].dest.right = bands[who].dest.left + 16;
}
else
bands[who].mode = kKillBandMode;
}
PlayPrioritySound(kBandReboundSound, kBandReboundPriority);
break;
}
else if (action == kRewardIt)
{
whoLinked = hotSpots[i].who;
if ((masterObjects[whoLinked].theObject.what == kGreaseRt) ||
(masterObjects[whoLinked].theObject.what == kGreaseLf))
{
if (SetObjectState(thisRoomNumber,
masterObjects[whoLinked].objectNum, 0, whoLinked))
SpillGrease(masterObjects[whoLinked].dynaNum,
masterObjects[whoLinked].hotNum);
hotSpots[i].isOn = false;
}
}
else if (action == kSwitchIt)
|