forked from CaptainCarmel/python-pygame-platformer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
27 lines (26 loc) · 778 Bytes
/
ui.py
File metadata and controls
27 lines (26 loc) · 778 Bytes
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
import utils
import globals
class ButtonUI:
def __init__(self, keyCode, text, x, y):
self.keyCode = keyCode
self.text = text
self.x = x
self.y = y
self.pressed = False
self.on = False
self.timer = 20
def update(self, inputStream):
self.pressed = inputStream.keyboard.isKeyPressed(self.keyCode)
if self.pressed:
self.on = True
if self.on:
self.timer -= 1
if self.timer <= 0:
self.on = False
self.timer = 20
def draw(self, screen, alpha=255):
if self.on:
colour = globals.GREEN
else:
colour = globals.WHITE
utils.drawText(screen, self.text, self.x, self.y, colour, alpha)