-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethods.py
82 lines (66 loc) · 2.97 KB
/
methods.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
import pygame
import dataTypes
WHITE = dataTypes.WHITE
#button object
#for reuse of easy buttoning
class button(pygame.sprite.Sprite):
def __init__(self, x, y, w, h, text, font=(dataTypes.GAME_FONT, dataTypes.GAME_FONT_BUTTON), boxOffset=0):
super().__init__()
self.x = x
self.y = y
self.w = w
self.h = h
self.text = text
self.fonts = font
self.offset= boxOffset
def press(self, *args, **kwargs):
pass
def update(self, screen):
mouse = pygame.mouse.get_pos()
if ((self.x + self.w + self.offset) > mouse[0] > self.x+self.offset) and ((self.y + self.h+self.offset) > mouse[1] > self.y+self.offset):
text_to_screen(self.text, self.x+self.w//2, self.y+self.h//2, screen, center=True, font=self.fonts[0])
else:
text_to_screen(self.text, self.x+self.w//2, self.y+self.h//2, screen, center=True, font=self.fonts[1])
class playButton(button):
def __init__(self, x, y, fonts=(dataTypes.GAME_FONT, dataTypes.GAME_FONT_BUTTON)):
super().__init__(x-75, y, 150, 50, "Play", font=fonts)
class instructionsButton(button):
def __init__(self, x, y, fonts=(dataTypes.GAME_FONT, dataTypes.GAME_FONT_BUTTON)):
super().__init__(x-75, y, 150, 50, "Instructions", font=fonts)
class loadButton(button):
def __init__(self, x, y, loadName, fonts=(dataTypes.GAME_FONT, dataTypes.GAME_FONT_BUTTON)):
super().__init__(x-75, y, 150, 50, loadName, font=fonts)
def press(self, method, name, *args, **kwargs):
method(name)
class newSaveButton(button):
def __init__(self, x, y, fonts=(dataTypes.GAME_FONT, dataTypes.GAME_FONT_BUTTON)):
super().__init__(x-100, y, 200, 50, "- New Save -", font=fonts)
class createSaveButton(button):
def __init__(self, x, y, fonts=(dataTypes.GAME_FONT, dataTypes.GAME_FONT_BUTTON)):
super().__init__(x-100, y, 200, 50, "Create", font=fonts)
class nextButton(button):
def __init__(self, x, y, LR, fonts=(dataTypes.GAME_FONT, dataTypes.GAME_FONT_BUTTON)):
super().__init__(x, y, 50, 50, None, font=fonts)
self.LR = LR
if LR == "L":
self.text = "<"
elif LR == "R":
self.text = ">"
def press(self, iterVar, *args, **kwargs):
if self.LR == "R":
return (iterVar+1)%3
if self.LR == "L":
return (iterVar-1)%3
class backButton(button):
def __init__(self, x, y, fonts=(dataTypes.GAME_FONT, dataTypes.GAME_FONT_BUTTON), text="Back", boxOffset=0):
super().__init__(x-50, y, 100, 50, text, font=fonts, boxOffset=boxOffset)
def text_obj(text, font):
textSurface = font.render(text, True, dataTypes.WHITE)
return textSurface, textSurface.get_rect()
def text_to_screen(text, x, y, surface, font=dataTypes.GAME_FONT, center=True):
textSurf, textRect = text_obj(text, font)
if center:
textRect.center = (x, y)
if not center:
textRect.x, textRect.y = (x, y)
surface.blit(textSurf, textRect)