File: score.py

package info (click to toggle)
funnyboat 1.5-6
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 4,128 kB
  • ctags: 207
  • sloc: python: 2,139; makefile: 43; sh: 3
file content (32 lines) | stat: -rw-r--r-- 846 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pygame

from locals import *

import util

class Score(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)

        self.score = 0
        self.target_score = 0

        self.image = util.smallfont.render("Score: 0", Variables.alpha, (10,10,10))

        self.rect = self.image.get_rect()
        self.rect.left = 100
        self.rect.top = 5

    def update(self):
        if self.target_score > self.score:
            self.score += 1
            self.image = util.smallfont.render("Score: " + str(self.score), Variables.alpha, (10,10,10))
            self.rect.width = self.image.get_width()
            self.rect.height = self.image.get_height()

    def add(self, points):    
        self.target_score += points
        self.update()

    def get_score(self):
        return self.target_score