version 1.2, 2009/04/03 02:48:21
|
version 1.3, 2009/04/07 03:51:53
|
Line 25
|
Line 25
|
/* |
/* |
* Set some basic definitions |
* Set some basic definitions |
*/ |
*/ |
#define VERSION "$Id$" |
#define VER "$Id$" |
#define TITLE "Froggix" |
#define TITLE "Froggix" |
#define SCREEN_WIDTH 640 |
#define SCREEN_WIDTH 640 |
#define SCREEN_HEIGHT 480 |
#define SCREEN_HEIGHT 480 |
Line 67
|
Line 67
|
#define TIMER_SIZE 150 |
#define TIMER_SIZE 150 |
#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 GATOR_MAX_TIME 60 |
|
|
/* baddies */ |
/* baddies */ |
#define VEHICLE 0 |
#define VEHICLE 0 |
Line 184 void beginGame( void );
|
Line 186 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 configGameScreen( void ); |
void configGameScreen( void ); |
void drawGameScreen( void ); |
void drawGameScreen( void ); |
void drawBackground( void ); |
void drawBackground( void ); |
Line 219 void drawImage(SDL_Surface *srcimg, int
|
Line 222 void drawImage(SDL_Surface *srcimg, int
|
void playSound( Mix_Chunk *sound ); |
void playSound( Mix_Chunk *sound ); |
void setFullScreenMode( void ); |
void setFullScreenMode( void ); |
|
|
|
int flyTimer = 0; |
int level = 0; |
int level = 0; |
int playing = 0; |
int playing = 0; |
int lives = 0; |
int lives = 0; |
Line 453 int keyEvents( SDL_Event event ) {
|
Line 457 int keyEvents( SDL_Event event ) {
|
default: |
default: |
break; |
break; |
} |
} |
|
/* Uncomment for positioning debug information |
printf( "x,y,d => %i,%i,%i,%i\n", frogger.placement[X], |
printf( "x,y,d => %i,%i,%i,%i\n", frogger.placement[X], |
frogger.placement[Y], |
frogger.placement[Y], |
frogger.direction, |
frogger.direction, |
frogger.currentRow ); |
frogger.currentRow ); |
|
*/ |
} |
} |
/* Game over man, game over! */ |
/* Game over man, game over! */ |
if ( ! lives ) { |
if ( ! lives ) { |
Line 704 void configGameScreen( void ) {
|
Line 710 void configGameScreen( void ) {
|
rightBorderRect.w = SCREEN_WIDTH - RIGHT_SIDE; |
rightBorderRect.w = SCREEN_WIDTH - RIGHT_SIDE; |
rightBorderRect.h = SCREEN_HEIGHT; |
rightBorderRect.h = SCREEN_HEIGHT; |
|
|
|
/* |
|
* We reset the flyTimer since this may not be the first game played |
|
*/ |
|
flyTimer = 0; |
|
|
/* |
/* |
* Draw frogger in starting position |
* Draw frogger in starting position |
Line 747 void drawGameScreen( void ) {
|
Line 757 void drawGameScreen( void ) {
|
/* |
/* |
* Update and draw everthing else |
* Update and draw everthing else |
*/ |
*/ |
|
checkFly( ); |
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 797 int getRowPixel ( int row ) {
|
Line 808 int getRowPixel ( int row ) {
|
} |
} |
|
|
/* |
/* |
|
* Check our fly timers to determine if we need to display or |
|
* remove a fly from the goal area |
|
*/ |
|
int checkFly ( void ) { |
|
int i; |
|
|
|
for ( i = 0; i < MAX_GOALS; i++ ) { |
|
if ( goals[i].fly ) { |
|
goals[i].fly++; |
|
if ( goals[i].fly > FLY_MAX_TIME ) { |
|
goals[i].fly = 0; |
|
flyTimer = 0; |
|
} |
|
|
|
return 0; |
|
} |
|
} |
|
|
|
flyTimer++; |
|
|
|
if ( flyTimer > ( FLY_MAX_TIME ) ) { |
|
int randGoal = ( ( int ) timeLeft % 10 ); |
|
if ( ( goals[randGoal].gator == 0 ) && |
|
( goals[randGoal].occupied == 0 ) ) { |
|
printf( "Displaying fly in goal %i\n", randGoal ); |
|
goals[randGoal].fly = 1; |
|
} |
|
} |
|
|
|
return 0; |
|
} |
|
|
|
/* |
* This does collision detection based on the row frogger |
* This does collision detection based on the row frogger |
* is in to help reduce overhead |
* is in to help reduce overhead |
*/ |
*/ |
Line 853 int collisionRow ( void ) {
|
Line 897 int collisionRow ( void ) {
|
if ( collideFrogger( goals[i].x, goals[i].y, goals[i].w, goals[i].h ) ) { |
if ( collideFrogger( goals[i].x, goals[i].y, goals[i].w, goals[i].h ) ) { |
if ( goals[i].occupied ) return 1; |
if ( goals[i].occupied ) return 1; |
goals[i].occupied++; |
goals[i].occupied++; |
|
if ( goals[i].fly ) { |
|
goals[i].fly = 0; |
|
flyTimer = 0; |
|
score += SCORE_FLY; |
|
} |
/* playSound( s_goal ); */ |
/* playSound( s_goal ); */ |
score += SCORE_GOAL; |
score += SCORE_GOAL; |
score += ( ( int ) ( timeLeft / 10 ) ) * 10; |
score += ( ( int ) ( timeLeft / 10 ) ) * 10; |
Line 1192 void drawNumbers( int num, int x, int y
|
Line 1241 void drawNumbers( int num, int x, int y
|
void drawGoals( void ) { |
void drawGoals( void ) { |
int drawDebugRect = 0; |
int drawDebugRect = 0; |
int i; |
int i; |
|
|
for ( i = 0; i < MAX_GOALS; i++ ) { |
for ( i = 0; i < MAX_GOALS; i++ ) { |
if ( drawDebugRect ) { |
if ( drawDebugRect ) { |
SDL_Rect d; |
SDL_Rect d; |
Line 1207 void drawGoals( void ) {
|
Line 1256 void drawGoals( void ) {
|
if ( goals[i].occupied ) |
if ( goals[i].occupied ) |
drawImage( gfx, FRAME * 15, 0, FRAME, FRAME, |
drawImage( gfx, FRAME * 15, 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].fly ) { |
|
drawImage( gfx, FRAME * 16, 0, FRAME, FRAME, |
|
screen, goals[i].x + 13, goals[i].y + 5, 255 ); |
|
} |
} |
} |
} |
} |
|
|