This repository was archived by the owner on May 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersonnalize.py
86 lines (74 loc) · 2.87 KB
/
personnalize.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
82
83
84
85
86
# import drawing lib
import pygame
# pygame constants as events' constants
from pygame.locals import *
# game constants
from constants import *
from buttonwimage import ButtonWImage
import glob
import os
import textentry
from button import Button
import shutil
class Personnalize:
def __init__(self, win):
self.running = False
self.win = win
self.dbox = textentry.TextBox(self.win, font=pygame.font.SysFont("arial", 18), sy=22, x=((WIDTH - 120) // 2), y=HEIGHT - 32)
self.btns = []
x, y = 200, 20
i = 0
for folder in sorted(glob.glob("gfx/personnalize/*")):
self.btns.append(ButtonWImage(x, y, 64, 64, folder + "/front.png", (128, 48, 120)))
i += 1
if i == 5:
y = 20
x = WIDTH - 264
else:
y += 74
self.valid_btn = Button((WIDTH - 80) // 2, (HEIGHT - 32), 50, 22, "Valider", (12, 200, 35), pygame.font.SysFont("arial", 18), (0, 0, 0))
self.has_valid = False
self.selected = -1
def load(self):
self.running = True
def update(self):
pass
def render(self):
pygame.draw.rect(self.win, (20, 175, 170), (0, 0) + self.win.get_size())
for btn in self.btns:
btn.render(self.win)
if not self.has_valid:
self.valid_btn.render(self.win)
else:
self.dbox.mainloop()
def create_game(self):
with open("saves/game", "w") as file:
file.write(self.dbox.input)
folder = sorted(glob.glob("gfx/personnalize/*"))[self.selected]
for f in glob.glob(folder + "/*.png"):
if os.path.exists("gfx/player/" + os.path.basename(f)):
os.remove("gfx/player/" + os.path.basename(f))
shutil.copyfile(f, "gfx/player/" + os.path.basename(f))
def run(self):
while self.running:
for ev in pygame.event.get():
if ev.type == QUIT:
self.running = False
elif ev.type == MOUSEBUTTONDOWN:
x, y = pygame.mouse.get_pos()
for i, btn in enumerate(self.btns):
if btn.collide(x, y):
if self.selected != -1:
self.btns[self.selected].color = (128, 48, 120)
self.selected = i
btn.color = (50, 120, 50)
break
if not self.has_valid:
if self.valid_btn.collide(x, y):
self.has_valid = True
if not self.dbox.is_running():
self.create_game()
self.running = False
self.update()
self.render()
pygame.display.flip()