-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay_badgario.py
171 lines (132 loc) · 6.01 KB
/
play_badgario.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# This Menu is in Playable condition! PLAYABLE!!
# ----------------------------------------------------
from badgario import *
from config import *
#import webbrowser #To externally open files
import os
# ----------------------------------------------------
#Initialize pygame
pygame.init()
class GameMenu():
def __init__(self, screen):
self.screen = screen
self.bgColor = BLACK
self.clock = pygame.time.Clock()
#More of Initializing pygame
pygame.display.set_caption('Shitty Agario')
self.SURF = screen
self.SMALLESTFONT = pygame.font.Font('freesansbold.ttf', 14)
self.SMALLERFONT = pygame.font.Font('freesansbold.ttf', 20)
self.BASICFONT = pygame.font.Font('freesansbold.ttf', 32)
self.BIGFONT = pygame.font.Font('freesansbold.ttf', 72)
### Main running menu function ###
def run(self):
mainLoop = True
#Some button boolean flags
playHover = False;
configHover = False;
bossHover = False;
####################
## Main menu loop ##
####################
while mainLoop:
#Limit frame speed to FPS
self.clock.tick(15)
## Screen ##
#Drawing the background
self.SURF.fill(WHITE)
#pygame.display.flip() #To be honest, not sure what this is supposed to do.
#Titles
textTitleSurf = self.BIGFONT.render("Badgario - A shitty version of Agar.io", True, BLACK)
textTitleRect = textTitleSurf.get_rect()
textTitleRect.center = (HALF_SCREENSIZE_X, HALF_SCREENSIZE_Y - CAMERASLACK - 72)
textSubSurf = self.SMALLERFONT.render("A silly half-baked game by Haoda Fan - the master of silly half-baked things.", True, BLACK)
textSubRect = textSubSurf.get_rect()
textSubRect.center = (HALF_SCREENSIZE_X, HALF_SCREENSIZE_Y - CAMERASLACK)
#Drawing the titles
self.SURF.blit(textTitleSurf, textTitleRect)
self.SURF.blit(textSubSurf, textSubRect)
## Buttons ##
#Button 1: Play the game
if playHover:
textPlayColor = WHITE
backPlayColor = BLACK
else:
textPlayColor = BLACK
backPlayColor = WHITE
pygame.draw.circle(self.SURF, backPlayColor, (HALF_SCREENSIZE_X, HALF_SCREENSIZE_Y + CAMERASLACK + 25), CAMERASLACK, 0)
textPlaySurf = self.SMALLERFONT.render("Play game!", True, textPlayColor)
textPlayRect = textPlaySurf.get_rect()
textPlayRect.center = (HALF_SCREENSIZE_X, HALF_SCREENSIZE_Y + CAMERASLACK + 25)
self.SURF.blit(textPlaySurf, textPlayRect)
#Button 2: How to configure game
if configHover:
textConfigColor = WHITE
backConfigColor = BLUE
else:
textConfigColor = BLUE
backConfigColor = WHITE
pygame.draw.circle(self.SURF, backConfigColor, (50 + CAMERASLACK, HALF_SCREENSIZE_Y + CAMERASLACK + 25), CAMERASLACK, 0)
textConfigSurf = self.SMALLESTFONT.render("Game Settings", True, textConfigColor)
textConfigRect = textConfigSurf.get_rect()
textConfigRect.center = (50 + CAMERASLACK, HALF_SCREENSIZE_Y + CAMERASLACK + 25)
self.SURF.blit(textConfigSurf, textConfigRect)
#Button 3: How to customize boss
if bossHover:
textBossColor = WHITE
backBossColor = RED
else:
textBossColor = RED
backBossColor = WHITE
pygame.draw.circle(self.SURF, backBossColor, (SCREENSIZE_X - CAMERASLACK - 50, HALF_SCREENSIZE_Y + CAMERASLACK + 25), CAMERASLACK, 0)
textBossSurf = self.SMALLESTFONT.render("Customize Boss", True, textBossColor)
textBossRect = textBossSurf.get_rect()
textBossRect.center = (SCREENSIZE_X - CAMERASLACK - 50, HALF_SCREENSIZE_Y + CAMERASLACK + 25)
self.SURF.blit(textBossSurf, textBossRect)
#Coming soon! Buttons that do the work for you! (you lazy asshole)
#Mouse recognition
mouse = pygame.mouse.get_pos()
#Note mouse[0] = x, mouse[1] = y
# Mouse Hovering effects
if GameMenu.isInRect(mouse[0], mouse[1], textPlayRect):
playHover = True
print("Hovering over play")
elif GameMenu.isInRect(mouse[0], mouse[1], textConfigRect):
configHover = True
print("Hovering over config")
elif GameMenu.isInRect(mouse[0], mouse[1], textBossRect):
bossHover = True
print("Hovering over boss")
else:
playHover = False
configHover = False
bossHover = False
# Mouse clicking effects
mouseClick = pygame.mouse.get_pressed()
if mouseClick == (1,0,0) and playHover:
time.sleep(0.2)
main()
elif mouseClick == (1,0,0) and configHover:
os.system("notepad.exe more_instructions/config.txt")
elif mouseClick == (1,0,0) and bossHover:
os.system("notepad.exe more_instructions/customboss.txt")
## Event Listeners ##
for event in pygame.event.get():
# Quitting
if event.type == pygame.QUIT:
mainLoop = False
terminate()
#Updates the display
pygame.display.update()
# -------------------- #
### HELPER FUNCTIONS ###
# -------------------- #
def isInRect(x, y, objRect):
newRect = pygame.Rect(x-1, y-1, 2, 2)
return objRect.colliderect(newRect)
if __name__ == "__main__":
#Create the screen
screen = pygame.display.set_mode((SCREENSIZE_X, SCREENSIZE_Y), 0, 32)
pygame.display.set_caption("Badgario - A shitty agario, by Haoda Fan")
gm = GameMenu(screen)
gm.run()