-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
50 lines (41 loc) · 1.51 KB
/
gui.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from PyQt5.QtWidgets import QGraphicsTextItem
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtGui import QFont
from PyQt5.QtCore import pyqtSignal
class Score(QGraphicsTextItem):
def __init__(self, scene, parent=None):
super().__init__(parent)
scene.addItem(self)
self._score = 0
self.setFont(QFont("Arial", 15))
self.setPlainText("Score: " + str(self._score))
self.setDefaultTextColor(Qt.blue)
def increase(self):
self._score += 1
self.setPlainText("Score: " + str(self._score))
class Health(QGraphicsTextItem):
dead = pyqtSignal()
def __init__(self, scene, parent=None):
super().__init__(parent)
scene.addItem(self)
self._health = 1
self.setFont(QFont("Arial", 15))
self.setPlainText("Health: " + str(self._health))
self.setDefaultTextColor(Qt.red)
rect = self.boundingRect()
self.setPos((800/2) - rect.width()/2, self.y())
def decrease(self):
self._health -= 1
self.setPlainText("Health: " + str(self._health))
if self._health <= 0:
self.dead.emit()
class GameOver(QGraphicsTextItem):
def __init__(self, scene, parent=None):
super().__init__(parent)
scene.addItem(self)
self.setPlainText("GameOver")
self.setDefaultTextColor(Qt.red)
self.setFont(QFont("Arial", 50))
rect = self.boundingRect()
self.setPos((800/2) - rect.width()/2, self.y())
print(self.boundingRect(), rect.width())