Skip to content

Commit

Permalink
adding round start/end sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
aosyborg committed Oct 10, 2011
1 parent 8a20a5a commit 2754939
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 14 deletions.
80 changes: 70 additions & 10 deletions driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,32 @@
HIT_DUCK_WHITE_RECT = 217, 43, 19, 16
HIT_DUCK_RED_RECT = 199, 43, 19, 16
SCORE_POSITION = 620, 440
SCORE_RECT = 69, 43, 128, 43
SCORE_RECT = 69, 43, 130, 43
FONT = os.path.join('media', 'arcadeclassic.ttf')
FONT_STARTING_POSITION = 730, 442
ROUND_POSITION = 60, 410
NOTICE_POSITION = 370, 120
NOTICE_RECT = 0, 86, 128, 63
NOTICE_WIDTH = 128
NOTICE_LINE_1_HEIGHT = 128
NOTICE_LINE_2_HEIGHT = 150

class Driver(object):
def __init__(self, surface):
self.surface = surface
self.gun = Gun(surface)
self.ducks = [Duck(surface), Duck(surface)]
self.round = 1
self.phase = 'shoot'
self.phase = 'start'
self.score = 0
self.timer = int(time.time())
self.roundTime = 10 # Seconds in a round
self.controlImgs = pygame.image.load(os.path.join('media', 'screenobjects.png'))
self.hitDucks = [False for i in range(10)]
self.hitDuckIndex = 0
self.nextRoundSound = os.path.join('media', 'next-round.mp3')
self.flyawaySound = os.path.join('media', 'flyaway.mp3')
self.notices = ()

def handleEvent(self, event):
# If we are in the shooting phase, pass event off to the gun
Expand All @@ -47,13 +55,36 @@ def handleEvent(self, event):
def update(self):
allDone = False

# Update all ducks
for duck in self.ducks:
duck.update()

self.manageRound()
# Update game based on phase
if self.phase == 'start':
self.startRound()
elif self.phase == 'shoot':
# Update all ducks
for duck in self.ducks:
duck.update()
self.manageRound()
elif self.phase == 'end':
self.endRound()

def render(self):
# If there is a notice, display and return
if len(self.notices) > 0:
font = pygame.font.Font(FONT, 20)
text = font.render(str(self.notices[0]), True, (255, 255, 255));
x, y = NOTICE_POSITION
x = x + (NOTICE_WIDTH - text.get_width()) / 2
y = NOTICE_LINE_1_HEIGHT
self.surface.blit(self.controlImgs, NOTICE_POSITION, NOTICE_RECT)
self.surface.blit(text, (x, y));
if len(self.notices) > 1:
text = font.render(str(self.notices[1]), True, (255, 255, 255));
x, y = NOTICE_POSITION
x = x + (NOTICE_WIDTH - text.get_width()) / 2
y = NOTICE_LINE_2_HEIGHT
self.surface.blit(text, (x, y));

return

# Show the ducks
for duck in self.ducks:
duck.render()
Expand Down Expand Up @@ -106,11 +137,40 @@ def manageRound(self):

# Start new around if duck index is at the end
if self.hitDuckIndex >= 9:
self.round += 1
self.hitDucks = [False for i in range(10)]
self.hitDuckIndex = 0
pygame.mixer.music.load(self.nextRoundSound)
pygame.mixer.music.play()
self.phase = 'end'
return

# Populate screen with new ducks
self.ducks = [Duck(self.surface), Duck(self.surface)]
self.timer = int(time.time())
self.gun.reloadIt()

def startRound(self):
timer = int(time.time())
self.notices = ("ROUND", self.round)
if (timer - self.timer) > 2:
self.phase = 'shoot'
self.notices = ()

def endRound(self):
# Pause game for new round music to play
while pygame.mixer.music.get_busy():
return

# Count missed ducks - more than 4 and you're done
missedCount = 0
for i in self.hitDucks:
if i == False:
missedCount += 1
if missedCount > 4:
self.notices = ("GAME OVER", "")
return

# Prep for new round
self.round += 1
self.hitDucks = [False for i in range(10)]
self.hitDuckIndex = 0
self.phase = 'start'
self.timer = int(time.time())
7 changes: 6 additions & 1 deletion duck.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
class Duck(object):
def __init__(self, surface):
self.surface = surface
self.image = pygame.image.load(os.path.join('media', 'duck.png'))
self.imageReversed = False
self.image = pygame.image.load(os.path.join('media', 'duck.png'))
self.dropSound = os.path.join('media', 'drop.mp3')
self.isDead = False
self.isFinished = False
self.flyOff = False
Expand Down Expand Up @@ -52,6 +53,10 @@ def render(self):
width, height = FRAME_SIZE
x, y = self.position

# If we are finished, don't just return
if self.isFinished:
return

# Set offsets
xOffset, yOffset = FRAME_SIZE
if not self.imageReversed:
Expand Down
6 changes: 3 additions & 3 deletions gun.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
class Gun(object):
def __init__(self, surface):
self.surface = surface
self.mouseImg = pygame.image.load(os.path.join('media', 'crosshairs.png'))
self.mousePos = (0,0)
self.rounds = 3
self.blastSound = os.path.join('media', 'blast.mp3')
self.mouseImg = pygame.image.load(os.path.join('media', 'crosshairs.png'))
self.shotImgs = pygame.image.load(os.path.join('media', 'screenobjects.png'))
self.blastSound = os.path.join('media', 'blast.mp3')
self.rounds = 3

def render(self):
self.surface.blit(self.mouseImg, self.mousePos)
Expand Down
File renamed without changes.
Binary file modified media/screenobjects.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2754939

Please sign in to comment.