-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.py
More file actions
41 lines (34 loc) · 1.41 KB
/
menu.py
File metadata and controls
41 lines (34 loc) · 1.41 KB
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
import pygame
from need_fncts import load_image
from all_variables import Button
class Menu(pygame.Surface):
def __init__(self, lvl):
super().__init__((1280, 40))
self.fill((0, 0, 0))
self.x = 0
self.y = 720 - 40
self.lvl = lvl
self.set_alpha(120)
self.rect = pygame.Rect((self.x, self.y), self.get_size())
self.create_buttons()
def draw(self, srfc):
srfc.blit(self, (self.x, self.y))
def change_pos(self, x, y):
self.x = x
self.y = y
self.rect.x, self.rect.y = x, y
def create_buttons(self):
self.buttons = pygame.sprite.Group()
for i in range(self.lvl):
font = pygame.font.Font('freesansbold.ttf', 12)
text = font.render(str(i + 1), True, (255, 255, 255))
archer_img = pygame.Surface((40, 40))
archer_img.blit(pygame.transform.scale(load_image('archer/1_IDLE_003.png'), (40, 40)), (0, 0))
archer_img.blit(text, (14, 14))
archer_btn = Button(archer_img, 'archer' + str(i), i * 60 + 10 * i, 0)
wall_img = pygame.Surface((40, 40))
pygame.draw.rect(wall_img, (128, 128, 128), ((15, 0), (10, 40)))
wall_img.blit(text, (17, 17))
wall_btn = Button(wall_img, 'wall' + str(i), 1280 - (i + 1) * 60 - 10 * i, 0)
self.buttons.add(wall_btn, archer_btn)
self.buttons.draw(self)