Compare commits
No commits in common. "6b69d32ad1573e08f0cbce4713c96f5b41aa50c8" and "69a8e0bd9b5bf62cadb3f26b675a0d92b53e8668" have entirely different histories.
6b69d32ad1
...
69a8e0bd9b
1 changed files with 7 additions and 91 deletions
98
cowyeet.py
98
cowyeet.py
|
@ -15,7 +15,6 @@ SAVE_SETTINGS_ON_EXIT = True
|
||||||
# some initializing
|
# some initializing
|
||||||
pygame.init()
|
pygame.init()
|
||||||
screen = pygame.display.set_mode(DEFAULT_WINDOW_SIZE)
|
screen = pygame.display.set_mode(DEFAULT_WINDOW_SIZE)
|
||||||
pygame.display.set_caption("Cowyeet 2.0")
|
|
||||||
|
|
||||||
if os.path.isfile("settings.txt"):
|
if os.path.isfile("settings.txt"):
|
||||||
settings = Settings("settings.txt")
|
settings = Settings("settings.txt")
|
||||||
|
@ -35,44 +34,20 @@ screen.blit(loading_text, (400 - loading_text.get_width() / 2, 300 - loading_tex
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
|
|
||||||
# variables
|
# colors (color names by https://www.color-blindness.com/color-name-hue/)
|
||||||
nero = (40, 40, 40) # colors (color names by https://www.color-blindness.com/color-name-hue/)
|
nero = (40, 40, 40)
|
||||||
dim_gray = (100, 100, 100)
|
dim_gray = (100, 100, 100)
|
||||||
white_smoke = (240, 240, 240)
|
white_smoke = (240, 240, 240)
|
||||||
|
|
||||||
buttons = [] # misc
|
|
||||||
text_buttons = []
|
|
||||||
active_buttons = []
|
|
||||||
last_frame_mouse_pressed = False
|
|
||||||
page = "main_menu"
|
|
||||||
|
|
||||||
|
|
||||||
# pygame objects
|
# pygame objects
|
||||||
clock = pygame.time.Clock() # misc
|
clock = pygame.time.Clock()
|
||||||
mouse = pygame.mouse
|
|
||||||
|
|
||||||
bigger_default_font = pygame.font.SysFont("ubuntu", 32) # fonts
|
bigger_default_font = pygame.font.SysFont("ubuntu", 32)
|
||||||
|
|
||||||
|
|
||||||
# coordinate calculations
|
|
||||||
def center_x(width: int):
|
|
||||||
return screen.get_width() / 2 - width / 2
|
|
||||||
|
|
||||||
|
|
||||||
def center_y(height: int):
|
|
||||||
return screen.get_height() / 2 - height / 2
|
|
||||||
|
|
||||||
|
|
||||||
def center(size):
|
|
||||||
width, height = size
|
|
||||||
|
|
||||||
return center_x(width), center_y(height)
|
|
||||||
|
|
||||||
|
|
||||||
# buttons
|
# buttons
|
||||||
start_button = pg.TextButton("Start", center, screen, lambda: page_switch("game"), text_color=white_smoke, bg_color=dim_gray, font=bigger_default_font)
|
start_button = pg.TextButton("Start", (400, 300), lambda: print("bla"), text_color=white_smoke, bg_color=dim_gray, font=bigger_default_font)
|
||||||
buttons.append(start_button)
|
|
||||||
text_buttons.append(start_button)
|
|
||||||
|
|
||||||
|
|
||||||
def close():
|
def close():
|
||||||
|
@ -80,66 +55,14 @@ def close():
|
||||||
running = False
|
running = False
|
||||||
|
|
||||||
|
|
||||||
def window_size_reload(new_size):
|
|
||||||
for button in text_buttons:
|
|
||||||
button.update()
|
|
||||||
|
|
||||||
|
|
||||||
def main_menu_page():
|
|
||||||
start_button.blit(screen)
|
|
||||||
|
|
||||||
|
|
||||||
def page_selector():
|
|
||||||
if page == "main_menu":
|
|
||||||
main_menu_page()
|
|
||||||
|
|
||||||
|
|
||||||
def page_switch(new_page: str=None):
|
|
||||||
global active_buttons
|
|
||||||
global page
|
|
||||||
|
|
||||||
if not new_page is None:
|
|
||||||
page = new_page
|
|
||||||
|
|
||||||
if page == "main_menu":
|
|
||||||
active_buttons = [start_button]
|
|
||||||
|
|
||||||
else:
|
|
||||||
print("Error: Page not found.")
|
|
||||||
|
|
||||||
# for button in buttons:
|
|
||||||
# button.active = False
|
|
||||||
#
|
|
||||||
# for button in active_buttons:
|
|
||||||
# button.active = True
|
|
||||||
|
|
||||||
|
|
||||||
def get_events():
|
def get_events():
|
||||||
global last_frame_mouse_pressed
|
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
close()
|
close()
|
||||||
return
|
return
|
||||||
|
|
||||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
|
||||||
pressed = mouse.get_pressed()
|
|
||||||
pos = mouse.get_pos()
|
|
||||||
|
|
||||||
if not last_frame_mouse_pressed:
|
|
||||||
for button in active_buttons:
|
|
||||||
button.check(pos, pressed)
|
|
||||||
|
|
||||||
last_frame_mouse_pressed = True
|
|
||||||
|
|
||||||
if event.type == pygame.VIDEORESIZE:
|
|
||||||
|
|
||||||
window_size_reload(event.size)
|
|
||||||
|
|
||||||
|
|
||||||
def loop():
|
def loop():
|
||||||
global last_frame_mouse_pressed
|
|
||||||
|
|
||||||
screen.fill(nero)
|
screen.fill(nero)
|
||||||
|
|
||||||
get_events()
|
get_events()
|
||||||
|
@ -147,11 +70,8 @@ def loop():
|
||||||
if not running:
|
if not running:
|
||||||
return
|
return
|
||||||
|
|
||||||
pressed = mouse.get_pressed()
|
start_button.blit(screen)
|
||||||
if not pressed[0] and not pressed[1] and not pressed[2]:
|
start_button.check(pygame.mouse.get_pos(), [True])
|
||||||
last_frame_mouse_pressed = False
|
|
||||||
|
|
||||||
page_selector()
|
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
|
@ -161,10 +81,6 @@ def loop():
|
||||||
# loading completed
|
# loading completed
|
||||||
|
|
||||||
screen = pygame.display.set_mode(settings["win_size"], flags=pygame.RESIZABLE)
|
screen = pygame.display.set_mode(settings["win_size"], flags=pygame.RESIZABLE)
|
||||||
screen.fill(nero)
|
|
||||||
pygame.display.update()
|
|
||||||
|
|
||||||
page_switch()
|
|
||||||
|
|
||||||
running = True
|
running = True
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue