I intend this to be my final post for this thread.
I have solved my issue but in a way that still "sorta" betrays my holy trinity for programming: never use
magic constants, never use global variables, and never, ever leave a pointer unattended. So instead of using a global (extern) bool I used a very public one. What follows is still in prototype phase but it works as intended and will be built upon (so some comments may not yet truely describe what a funtion accomplishes).
Pertainant Class Member Functions:
void Ball::Reset( )
// Handles loading the ball if the player still has "lives".
{
if (!dbSpriteExist(BALL))
{
dbCreateAnimatedSprite(BALL, "Assets\\Ball.png", 12, 1, 10);
dbOffsetSprite(BALL, 20, 20);
dbSetSpritePriority(BALL, 31);
}
}
void Ball::StartPos( )
// Updates the ball when it is not in verticle motion.
{
ballX = dbSpriteX(SPRING);
ballY = 769;
dbSprite(BALL, ballX, ballY, 10);
}
void Ball::Movement( )
// Handles all non-collision related physics for the ball sprite.
{
ballSpeedX = 0;
gravity = 1;
if (dbSpriteCollision(BALL, PAD) )
{
ballSpeedY = 40;
}
ballSpeedY -= gravity;
ballY -= ballSpeedY;
dbSprite(BALL, ballX, ballY, 10);
dbPlaySprite(BALL, 1, 12, 30);
}
Snippets from my main function:
// Names the various game modes for easier comprehension.
enum GameMode {Setup, Intro, Title, GamePlay, GameLevel, GameOver, HighScore};
GameMode mode = Setup;
// Class declarations.
Levels Levels;
Player Player;
Ball Ball;
void DarkGDK ( void )
// This function only defines some public variable and calls the game loop. All other functions are handled
// within the main game loop it's self.
{
inPlay = false; // initialized in Main.h
while (LoopGDK( ))
// The main game loop. It cycles through the game modes and calls the functions related to each mode.
{
switch (mode)
{
case Setup:
setup( );
break;
case Intro:
break;
case Title:
break;
case GameLevel:
initializeLevel( );
break;
case GamePlay:
startRound( );
checkinPlay( );
ballMovement( );
other( );
break;
case GameOver:
break;
case HighScore:
break;
default:
break;
}
if (dbEscapeKey( ))
break;
dbSync( );
}
for (int del = 0; del < 200; ++del)
{
dbDeleteSprite(del);
dbDeleteImage(del);
}
}
void startRound( )
// Sets up the player and ball assets and set the starting conditions for gameplay.
{
Player.LoadPlayer( );
Player.Movement( );
Ball.Reset( );
if (!inPlay)
Ball.StartPos( );
}
void checkinPlay( )
// Acts as a trigger to put the ball into motion.
{
if (dbMouseClick( ) && inPlay == false)
inPlay = true;
}
void ballMovement( )
// Calls class functions of ball and handles the ball movement and collision.
{
if (inPlay == true)
Ball.Movement( );
}
I hope that I have included everything so people can make sense of this. I guess I was just hoping for some sort of code wizardry that felt a little cleaner, but then again this really isn't such a bad solution. I just want to be sure of not falling into a habit of leaving too many variables laying around in public code space.
The general moral to the story is: couldn't get an on off trigger to work within the LoopGDK loop or as a class member variable. Had to set it in the DarkGDK wrapper.
Again the invite is out there for anyone to humble me with their expertiece. Sorry 'bout any mistypes. Me much sleepy.
I'm not suggesting we should eradicate all stupid people. I am just saying lets remove all of the warning lables and let the situation sort its self out.