version 1.2, 2011/06/16 23:29:25
|
version 1.4, 2011/11/05 02:38:17
|
Line 39 LONG_LOG = 9
|
Line 39 LONG_LOG = 9
|
MAX_WOOD = 7 |
MAX_WOOD = 7 |
|
|
## |
## |
|
## Input |
|
## |
|
UP = 273 |
|
DOWN = 274 |
|
RIGHT = 275 |
|
LEFT = 276 |
|
|
|
## |
## Turtles |
## Turtles |
## |
## |
DIVE_START_TIME = 50 |
DIVE_START_TIME = 50 |
Line 62 SCORE_PINK = 200
|
Line 70 SCORE_PINK = 200
|
SCORE_SECONDS = 10 |
SCORE_SECONDS = 10 |
HIGH_SCORE = 4630 |
HIGH_SCORE = 4630 |
SCORE_FREE_FROG = 2000 |
SCORE_FREE_FROG = 2000 |
|
LIVES = 3 |
|
|
|
global screen |
|
|
## |
## |
## Some general game state stats |
## Some general game state stats |
## |
## |
level = 0 |
class mainGame( ): |
playing = 0 |
|
goDelay = 0 |
|
score = 0 |
|
lives = 0 |
|
freefrog = 0 |
|
drawBG = 1 |
|
global screen |
|
|
|
class gameStats( ): |
|
def __init__( self ): |
def __init__( self ): |
self.level = 0 |
self.level = 0 |
self.playing = 0 |
self.playing = 0 |
self.goDelay = 0 |
self.goDelay = 0 |
self.score = 0 |
self.score = 0 |
Line 124 class Goals( pygame.sprite.Sprite ):
|
Line 126 class Goals( pygame.sprite.Sprite ):
|
self.fly = 0 |
self.fly = 0 |
self.gator = 0 |
self.gator = 0 |
|
|
|
class frog( pygame.sprite.Sprite): |
|
def __init__( self ): |
|
pygame.sprite.Sprite.__init( self ) |
|
pos = [0, 0] |
|
oldPos = [0, 0] |
|
direction = 0 |
|
location = 0 |
|
hopCount = 0 |
|
currentRow = 0 |
|
alive = 1 |
|
riding = 0 |
|
ridingType = 0 |
|
deathType = 0 |
|
deathCount = 0 |
|
|
def main( ): |
def main( ): |
pygame.mixer.init( ) |
pygame.mixer.init( ) |
pygame.mixer.pre_init( 44100, -16, 2, 2048 ) |
pygame.mixer.pre_init( 44100, -16, 2, 2048 ) |
Line 142 def beginGame( ):
|
Line 159 def beginGame( ):
|
next_heartbeat = 0 |
next_heartbeat = 0 |
done = 0 |
done = 0 |
|
|
|
if loadMedia( ) <= 0: |
|
print "Error: Failed to load graphics and audio!\n" |
|
return |
|
|
drawBackground( ) |
drawBackground( ) |
|
|
if DEBUG: print "D: Starting main game loop" |
if DEBUG: print "D: Starting main game loop" |
Line 160 def beginGame( ):
|
Line 181 def beginGame( ):
|
def keyEvents( event ): |
def keyEvents( event ): |
if event.type == QUIT: return 1 |
if event.type == QUIT: return 1 |
elif event.type == KEYDOWN: |
elif event.type == KEYDOWN: |
|
print "Key Event Type: ", event.key |
|
|
if event.key == K_ESCAPE: return 1 |
if event.key == K_ESCAPE: return 1 |
elif event.key == K_P: |
elif event.key == K_p: |
if level: |
if game.level: |
|
if game.playing: |
|
game.playing = 0 |
|
else: |
|
game.playing = 1 |
print "D: Pausing Game" |
print "D: Pausing Game" |
|
|
elif event.key == K_1: |
elif event.key == K_1: |
if not level: |
if not game.level: |
|
game.level = 1 |
|
game.playing = 1 |
|
game.lives = LIVES |
print "D: Starting Game" |
print "D: Starting Game" |
|
|
return 0 |
return 0 |
|
|
def updateGameState( ): |
def updateGameState( ): |
if lives <= 0: |
if game.lives <= 0: |
goDelay += 1 |
game.goDelay += 1 |
drawGameOver( ) |
drawGameOver( ) |
if goDelay > 7: |
if goDelay > 7: |
playing = 0 |
game.playing = 0 |
lives = 0 |
game.lives = 0 |
level = 0 |
game.level = 0 |
score = 0 |
game.score = 0 |
freefrog = 0 |
game.freefrog = 0 |
drawBG = 0 |
game.drawBG = 0 |
# for i = 0; i < MAX_GOALS; i++: |
# for i = 0; i < MAX_GOALS; i++: |
# goals[i].occupied = 0 |
# goals[i].occupied = 0 |
return 500 |
return 500 |
Line 194 def drawGameScreen( ):
|
Line 225 def drawGameScreen( ):
|
|
|
def heartbeat( ): |
def heartbeat( ): |
ticks = 0; |
ticks = 0; |
if level: |
if game.level: |
if playing: |
if game.playing: |
ticks = updateGameState( ) |
ticks = updateGameState( ) |
if ticks <= 0: ticks = 30 |
if ticks <= 0: ticks = 30 |
return ticks |
return ticks |
Line 216 def drawTitleScreen( ):
|
Line 247 def drawTitleScreen( ):
|
drawBackground( ) |
drawBackground( ) |
|
|
def drawBackground( ): |
def drawBackground( ): |
background_image, background_rect = loadImage( 'gameboard.png' ) |
background_image, background_rect = loadImage( 'tempgameboard.png' ) |
screen.blit( background_image, ( 0, 0 ) ) |
screen.blit( background_image, ( 0, 0 ) ) |
pygame.display.flip( ) |
pygame.display.flip( ) |
|
|
|
def loadMedia( ): |
|
print "D: Loading media" |
|
return 1 |
|
|
def loadImage( filename, colorKey = None ): |
def loadImage( filename, colorKey = None ): |
fullname = os.path.join( 'images', filename ) |
fullname = os.path.join( 'images', filename ) |
|
|
Line 253 def loadSound( name ):
|
Line 288 def loadSound( name ):
|
return noSound |
return noSound |
|
|
return sound |
return sound |
|
game = mainGame( ) |
if __name__ == '__main__': main() |
if __name__ == '__main__': main() |
#init( ) |
|
#beginGame( ) |
|
#sys.quit( ) |
|