-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstracts.py
81 lines (60 loc) · 2.19 KB
/
abstracts.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from pygame import font, mouse, sprite, Surface, Rect
from settings import Color
class Scene(object):
def __init__(self):
pass
def render(self, screen):
raise NotImplementedError
def update(self):
raise NotImplementedError
def handle_events(self, events):
raise NotImplementedError
class Entity(sprite.Sprite):
def __init__(self, xpos, ypos, width, height, color):
sprite.Sprite.__init__(self)
self.width = width
self.height = height
self.xpos = xpos
self.ypos = ypos
# TODO: change from a color to an image / spritesheet
self.image = Surface((width, height))
self.image.fill(color)
self.image.convert()
# TODO: End
self.rect = Rect(xpos, ypos, width, height)
def draw(self, screen):
screen.blit(self.image, self.rect)
def update(self):
raise NotImplementedError
class Button(sprite.Sprite):
def __init__(self, text, xpos, ypos, width, height, font_size, action=None):
sprite.Sprite.__init__(self)
self.width = width
self.height = height
self.xpos = xpos
self.ypos = ypos
self.blue_color = Color.SKY.value
self.white_color = Color.PLAYER.value
self.rect = Rect(xpos, ypos, width, height)
# TODO: change from a color to an image / spritesheet
self.btn = Surface((width, height))
self.btn.convert()
self.btn.set_alpha(0)
# TODO: End
self.btnfnt = font.SysFont('Arial', font_size)
self.content = self.btnfnt.render(text, True, self.white_color)
self.contentpos = self.content.get_rect()
self.contentpos.centerx = self.rect.centerx
self.contentpos.centery = self.ypos + 35
self.action = action
def draw(self, screen):
screen.blit(self.btn, self.rect)
screen.blit(self.content, self.contentpos)
def update(self):
lft_click = mouse.get_pressed()[0]
if self.rect.collidepoint(mouse.get_pos()):
self.btn.set_alpha(128)
if lft_click == 1 and self.action is not None:
self.action()
else:
self.btn.set_alpha(0)