version 1.3, 2009/04/07 03:51:53
|
version 1.5, 2009/04/11 13:01:54
|
Line 60
|
Line 60
|
#define SCORE_PINK 200 |
#define SCORE_PINK 200 |
#define SCORE_SECONDS 10 |
#define SCORE_SECONDS 10 |
#define HIGH_SCORE 4630 |
#define HIGH_SCORE 4630 |
#define SCORE_FREE_FROG 200 |
#define SCORE_FREE_FROG 2000 |
|
|
/* The green game timer */ |
/* The green game timer */ |
#define MAX_TIMER 350 |
#define MAX_TIMER 350 |
Line 68
|
Line 68
|
#define TIMER_COLOR 32, 211, 0 |
#define TIMER_COLOR 32, 211, 0 |
#define TIMER_LOW_COLOR 255, 0, 0 |
#define TIMER_LOW_COLOR 255, 0, 0 |
#define FLY_MAX_TIME 50 |
#define FLY_MAX_TIME 50 |
#define GATOR_MAX_TIME 60 |
#define GATOR_MAX_TIME 70 |
|
|
/* baddies */ |
/* baddies */ |
#define VEHICLE 0 |
#define VEHICLE 0 |
Line 158 typedef struct {
|
Line 158 typedef struct {
|
int type; /* SHORT, MEDIUM, or LONG */ |
int type; /* SHORT, MEDIUM, or LONG */ |
int speed; /* What speed does the log move at */ |
int speed; /* What speed does the log move at */ |
int hasPink; // Is bonus frog riding |
int hasPink; // Is bonus frog riding |
|
int isGator; /* Are we a gator? if > 1 we have an open mouth */ |
|
|
SDL_Rect src; |
SDL_Rect src; |
} logObj; |
} logObj; |
Line 186 void beginGame( void );
|
Line 187 void beginGame( void );
|
int loadMedia( void ); |
int loadMedia( void ); |
int heartbeat( void ); |
int heartbeat( void ); |
int updateGameState( void ); |
int updateGameState( void ); |
int checkFly( void ); |
void checkFly( void ); |
|
void checkGator( void ); |
void configGameScreen( void ); |
void configGameScreen( void ); |
void drawGameScreen( void ); |
void drawGameScreen( void ); |
void drawBackground( void ); |
void drawBackground( void ); |
Line 223 void playSound( Mix_Chunk *sound );
|
Line 225 void playSound( Mix_Chunk *sound );
|
void setFullScreenMode( void ); |
void setFullScreenMode( void ); |
|
|
int flyTimer = 0; |
int flyTimer = 0; |
|
int gatorTimer = 0; |
int level = 0; |
int level = 0; |
int playing = 0; |
int playing = 0; |
int lives = 0; |
int lives = 0; |
Line 335 int loadMedia( void ) {
|
Line 338 int loadMedia( void ) {
|
* Load frogger's textures and sounds |
* Load frogger's textures and sounds |
*/ |
*/ |
gfx = IMG_Load( "images/frogger.png" ); |
gfx = IMG_Load( "images/frogger.png" ); |
frogger.riding = FALSE; |
|
|
|
if ( gfx == NULL ) { |
if ( gfx == NULL ) { |
fprintf( stderr, "Error: 'images/frogger.bmp' could not be open: %s\n", SDL_GetError( ) ); |
fprintf( stderr, "Error: 'images/frogger.bmp' could not be open: %s\n", SDL_GetError( ) ); |
result--; |
result--; |
Line 555 logObj setWood( int type, int speed, int
|
Line 556 logObj setWood( int type, int speed, int
|
tempWood.src.x = imgPixelSrc; |
tempWood.src.x = imgPixelSrc; |
tempWood.src.w = FRAME * tempWood.type; |
tempWood.src.w = FRAME * tempWood.type; |
tempWood.src.h = FRAME; |
tempWood.src.h = FRAME; |
|
tempWood.isGator = 0; |
|
|
return tempWood; |
return tempWood; |
} |
} |
Line 758 void drawGameScreen( void ) {
|
Line 760 void drawGameScreen( void ) {
|
* Update and draw everthing else |
* Update and draw everthing else |
*/ |
*/ |
checkFly( ); |
checkFly( ); |
|
checkGator( ); |
drawImage( background, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, screen, 0, 0, 255 ); |
drawImage( background, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, screen, 0, 0, 255 ); |
drawScore( 0, score ); |
drawScore( 0, score ); |
drawScore( 1, hScore ); |
drawScore( 1, hScore ); |
Line 811 int getRowPixel ( int row ) {
|
Line 814 int getRowPixel ( int row ) {
|
* Check our fly timers to determine if we need to display or |
* Check our fly timers to determine if we need to display or |
* remove a fly from the goal area |
* remove a fly from the goal area |
*/ |
*/ |
int checkFly ( void ) { |
void checkFly ( void ) { |
int i; |
int i; |
|
|
for ( i = 0; i < MAX_GOALS; i++ ) { |
for ( i = 0; i < MAX_GOALS; i++ ) { |
Line 822 int checkFly ( void ) {
|
Line 825 int checkFly ( void ) {
|
flyTimer = 0; |
flyTimer = 0; |
} |
} |
|
|
return 0; |
return; |
} |
} |
} |
} |
|
|
Line 837 int checkFly ( void ) {
|
Line 840 int checkFly ( void ) {
|
} |
} |
} |
} |
|
|
return 0; |
return; |
|
} |
|
|
|
/* |
|
* Check our gator timers. Similiar to fly timers above, however, the gator |
|
* has an extra stage as it enters in to the goal area. |
|
*/ |
|
void checkGator ( void ) { |
|
int i; |
|
|
|
for( i = 0; i < MAX_GOALS; i++ ) { |
|
if ( goals[i].gator ) { |
|
goals[i].gator++; |
|
if ( goals[i].gator > GATOR_MAX_TIME ) { |
|
goals[i].gator = 0; |
|
gatorTimer = 0; |
|
} |
|
|
|
return; |
|
} |
|
} |
|
|
|
gatorTimer++; |
|
|
|
if ( gatorTimer > GATOR_MAX_TIME ) { |
|
int randGoal = ( ( int ) ( timeLeft * 2 ) % 10 ); |
|
if ( ( goals[randGoal].fly == 0 ) && |
|
( goals[randGoal].occupied == 0 ) ) { |
|
printf( "Displaying gator in goal %i\n", randGoal ); |
|
goals[randGoal].gator = 1; |
|
} |
|
} |
|
|
|
return; |
} |
} |
|
|
/* |
/* |
Line 1027 void froggerReset ( void ) {
|
Line 1063 void froggerReset ( void ) {
|
* algorithm for calculating the distance and time |
* algorithm for calculating the distance and time |
*/ |
*/ |
void moveFrogger( void ) { |
void moveFrogger( void ) { |
int currentFrame = 0; |
|
int x = 0; |
int x = 0; |
int y = 0; |
int y = 0; |
int h = FRAME; |
int h = FRAME; |
int w = FRAME; |
int w = FRAME; |
int frameLow = HOP_SPEED / 3; |
|
int frameHigh = frameLow * 2; |
|
|
|
/* Determine which frame of frogger to display */ |
|
if ( ( frogger.hopCount >= frameLow ) && ( frogger.hopCount <= frameHigh ) ) |
|
currentFrame = FRAME; |
|
|
|
frogger.oldPlacement[Y] = frogger.placement[Y]; |
frogger.oldPlacement[Y] = frogger.placement[Y]; |
frogger.oldPlacement[X] = frogger.placement[X]; |
frogger.oldPlacement[X] = frogger.placement[X]; |
|
|
switch( frogger.direction ) { |
switch( frogger.direction ) { |
case UP: |
case UP: |
x = currentFrame; |
x = FRAME; |
frogger.placement[Y] -= ( HOP_DISTANCE / HOP_SPEED ); |
frogger.placement[Y] -= ( HOP_DISTANCE / HOP_SPEED ); |
break; |
break; |
case DOWN: |
case DOWN: |
x = currentFrame + ( 4 * FRAME ); |
x = ( 5 * FRAME ); |
frogger.placement[Y] += ( HOP_DISTANCE / HOP_SPEED ); |
frogger.placement[Y] += ( HOP_DISTANCE / HOP_SPEED ); |
break; |
break; |
case LEFT: |
case LEFT: |
x = currentFrame + ( 6 * FRAME ); |
x = ( 7 * FRAME ); |
frogger.placement[X] -= ( HOP_DISTANCE / HOP_SPEED ); |
frogger.placement[X] -= ( HOP_DISTANCE / HOP_SPEED ); |
break; |
break; |
case RIGHT: |
case RIGHT: |
x = currentFrame + ( 2 * FRAME ); |
x = ( 3 * FRAME ); |
frogger.placement[X] += ( HOP_DISTANCE / HOP_SPEED ); |
frogger.placement[X] += ( HOP_DISTANCE / HOP_SPEED ); |
break; |
break; |
} |
} |
Line 1086 void moveFrogger( void ) {
|
Line 1115 void moveFrogger( void ) {
|
frogger.direction = FALSE; |
frogger.direction = FALSE; |
score += SCORE_HOP; |
score += SCORE_HOP; |
lives += freeFrog( score ); |
lives += freeFrog( score ); |
|
frogger.src.x -= FRAME; |
} |
} |
} |
} |
|
|
Line 1260 void drawGoals( void ) {
|
Line 1290 void drawGoals( void ) {
|
drawImage( gfx, FRAME * 16, 0, FRAME, FRAME, |
drawImage( gfx, FRAME * 16, 0, FRAME, FRAME, |
screen, goals[i].x + 13, goals[i].y + 5, 255 ); |
screen, goals[i].x + 13, goals[i].y + 5, 255 ); |
} |
} |
|
if( goals[i].gator ) { |
|
int frame = 17; |
|
|
|
if ( goals[i].gator > ( ( int ) GATOR_MAX_TIME / 2 ) ) |
|
frame++; |
|
|
|
drawImage( gfx, FRAME * frame, 0, FRAME, FRAME, |
|
screen, goals[i].x + 13, goals[i].y + 5, 255 ); |
|
} |
} |
} |
} |
} |
|
|