Commit 4f6fbddf authored by Alan Aguiar's avatar Alan Aguiar
Browse files

end score works

parent 1d2ba343
......@@ -28,7 +28,7 @@ from pipe import Pipe_I
from pipe import Pipe_S
from build import Build
from bird import Bird
from scores import Scores
from scores import EndScore
from scores import Message
from scores import CurrentScore
......@@ -71,7 +71,7 @@ class Flappy():
self.build = Build(0, self.build_y)
self.bird = Bird(self, self.bird_x, self.bird_y)
self.bird.mAcc = 0
self.scores = Scores(200, 200)
self.end_scores = EndScore(200, 200)
self.message = Message(200, 200)
self.currentS = CurrentScore(300, 100)
########################################################################
......@@ -93,7 +93,7 @@ class Flappy():
self.bird.mAcc = 5
self.bird.count = 20
self.floor.mVel = -5
self.sprites.remove(self.scores)
self.sprites.remove(self.end_scores)
self.sprites.remove(self.message)
def main(self):
......@@ -148,7 +148,10 @@ class Flappy():
self.floor.mVel = 0
for spr in self.tubes:
spr.mVel = 0
self.sprites.add(self.scores, layer=3)
if self.score > self.best:
self.best = self.score
self.end_scores.update_scores(self.score, self.best)
self.sprites.add(self.end_scores, layer=3)
self.sprites.draw(self.screen)
self.running_t = True
while self.running_t:
......
......@@ -6,15 +6,34 @@ import pygame
back = pygame.image.load('images/score_alfa.png')
mes = pygame.image.load('images/init_alfa.png')
class Scores(pygame.sprite.Sprite):
class EndScore(pygame.sprite.Sprite):
def __init__(self, x=0, y=0):
pygame.sprite.Sprite.__init__(self)
self.mPos = [x, y]
self.image = back
self.score = 0
self.best = 0
self.font = pygame.font.Font('DejaVuSans-Bold.ttf', 40)
self.fgColor = (255, 255, 255)
self._update_image()
def update_scores(self, score, best):
self.score = score
self.best = best
self._update_image()
def _update_image(self):
self.image = back.copy()
fontSurface = self.font.render(str(self.score), True, self.fgColor)
xPos = (self.image.get_width() - fontSurface.get_width())/2
self.image.blit(fontSurface, (xPos, 35))
fontSurface = self.font.render(str(self.best), True, self.fgColor)
xPos = (self.image.get_width() - fontSurface.get_width())/2
self.image.blit(fontSurface, (xPos, 97))
self.rect = self.image.get_rect()
self.rect.x = self.mPos[0]
self.rect.y = self.mPos[1]
class CurrentScore(pygame.sprite.Sprite):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment