Skip to content

Commit

Permalink
adding score and round display + functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
aosyborg committed Oct 10, 2011
1 parent ef6051c commit 8a20a5a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
from gun import Gun
from duck import Duck

HIT_POSITION = 255, 440
HIT_POSITION = 245, 440
HIT_RECT = 0, 0, 287, 43
HIT_DUCK_POSITION = 339, 445
HIT_DUCK_POSITION = 329, 445
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
FONT = os.path.join('media', 'arcadeclassic.ttf')
FONT_STARTING_POSITION = 730, 442
ROUND_POSITION = 60, 410

class Driver(object):
def __init__(self, surface):
Expand All @@ -32,13 +37,12 @@ def handleEvent(self, event):
gunFired = self.gun.shoot()
for duck in self.ducks:
if gunFired:
if (duck.isShot(event.pos)):
if duck.isShot(event.pos):
self.score += 10
self.hitDucks[self.hitDuckIndex] = True
self.hitDuckIndex += 1
else:
duck.flyOff = True
self.hitDuckIndex += 1

def update(self):
allDone = False
Expand All @@ -50,10 +54,16 @@ def update(self):
self.manageRound()

def render(self):
# Show the ducks
for duck in self.ducks:
duck.render()

# Update game controls
# Show round number
font = pygame.font.Font(FONT, 20)
text = font.render(("R= %d" % self.round), True, (154, 233, 0), (0, 0, 0));
self.surface.blit(text, ROUND_POSITION);

# Show the hit counter
self.surface.blit(self.controlImgs, HIT_POSITION, HIT_RECT)
startingX, startingY = HIT_DUCK_POSITION
for i in range(10):
Expand All @@ -64,6 +74,15 @@ def render(self):
else:
self.surface.blit(self.controlImgs, (x, y), HIT_DUCK_WHITE_RECT)

# Show the score
self.surface.blit(self.controlImgs, SCORE_POSITION, SCORE_RECT)
font = pygame.font.Font(FONT, 20)
text = font.render(str(self.score), True, (255, 255, 255));
x, y = FONT_STARTING_POSITION
x -= text.get_width();
self.surface.blit(text, (x,y));

# Show the cross hairs
self.gun.render()

def manageRound(self):
Expand Down
Binary file added media/arcadeclassic.ttf
Binary file not shown.
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 8a20a5a

Please sign in to comment.