The Pinball Game
Game Physics with Bespoke Code
Loading...
Searching...
No Matches
CGate Class Reference

A gate. More...

#include <Gate.h>

Inheritance diagram for CGate:
Collaboration diagram for CGate:

Public Member Functions

 CGate (Shapes::CLineSeg *)
 Constructor.
 
 ~CGate ()
 Destructor.
 
bool NarrowPhase (Shapes::CDynamicCircle *)
 Narrow phase.
 

Private Attributes

Shapes::CLineSeg * m_pLineSeg = nullptr
 Pointer to line segment.
 

Additional Inherited Members

- Static Protected Attributes inherited from CCommon
static Sage::CSpriteRenderer * m_pRenderer = nullptr
 Pointer to the renderer.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to the object manager.
 
static UINT m_nMIterations = 4
 Number of motion iterations.
 
static UINT m_nCIterations = 1
 Number of collision iterations.
 
static float m_fFrequency = 60.0f*m_nMIterations
 Frequency, number of physics iterations per second.
 
static eDrawMode m_eDrawMode = eDrawMode::Background
 Draw mode.
 
static bool m_bBallInPlay = false
 Is there a ball currently in play?
 
static UINT m_nScore = 0
 Current score.
 

Detailed Description

A gate allows circles to cross in one direction only. It's essentially a line segment with some code that handles the crossing-in-one-direction requirement. More specifically, if the circle's velocity is in the opposite direction to the line segment's normal vector CLineSeg::m_vNormal and the circle's speed is larger than some threshold, then the circle passes through. Otherwise it bounces off of the line segment. Recall that the direction of CLineSeg::m_vNormal depends on the order in which CLineSeg's end points were specified, so make sure you get it right.

Constructor & Destructor Documentation

◆ CGate()

CGate::CGate ( Shapes::CLineSeg * p)

Construct a closed and unlatched gate from a line segment.

Parameters
pPointer to a line segment.

Member Function Documentation

◆ NarrowPhase()

bool CGate::NarrowPhase ( Shapes::CDynamicCircle * p)

If a dynamic circle collides with a gate and it is moving in the correct direction and is fast enough, then the gate opens and the dynamic circle is allowed through. Otherwise the dynamic circle bounces off the gate as usual.

Parameters
pPointer to a dynamic circle.
Returns
true if the dynamic circle intersects the gate.
Here is the caller graph for this function: