diff --git a/scores.py b/scores.py new file mode 100644 index 0000000..138e9af --- /dev/null +++ b/scores.py @@ -0,0 +1,55 @@ +import pygame +from pygame.sprite import Group +from gun import Gun + +class Scores(): + def __init__(self, screen, stats): + self.screen = screen + self.screen_rect=screen.get_rect() + self.stats = stats + self.text_color = (0,0,0) + self.font=pygame.font.SysFont(None, 36) + self.image_score() + self.image_high_score() + self.image_guns() + + def image_score(self): + self.score_img=self.font.render(str(self.stats.score), True, self.text_color,(250,250,0)) + self.score_rect=self.score_img.get_rect() + self.score_rect.right = self.screen_rect.right - 20 + self.score_rect.top = 20 + + + def image_high_score(self): + self.high_score_img=self.font.render(str(self.stats.high_score), True, self.text_color,(250,250,0)) + self.high_score_rect=self.high_score_img.get_rect() + self.high_score_rect.centerx = self.screen_rect.centerx + self.high_score_rect.top = 20 + + + def image_guns (self): + self.guns = Group() + for gun_number in range(self.stats.guns_left): + gun = Gun(self.screen) + gun.rect.x = (10 + gun_number * gun.rect.width) + gun.rect.top = 20 + self.guns.add(gun) + + + + def score_output(self): + self.screen.blit(self.score_img, self.score_rect) + self.screen.blit(self.high_score_img, self.high_score_rect) + self.guns.draw(self.screen) + + + + + + + + + + + + \ No newline at end of file diff --git a/stats.py b/stats.py new file mode 100644 index 0000000..2cba366 --- /dev/null +++ b/stats.py @@ -0,0 +1,11 @@ +import pygame + +class Stats(): + def __init__(self): + self.reset_stats() + self.run_game = True + with open("highscore.txt", "r") as f: + self.high_score = int(f.readline()) + def reset_stats(self): + self.guns_left = 3 + self.score = 0 \ No newline at end of file