182 lines
6.5 KiB
Python
182 lines
6.5 KiB
Python
import pygame
|
|
import sys
|
|
|
|
# Colors
|
|
LIGHT_SKY_BLUE = (135, 206, 235)
|
|
BLACK = (0, 0, 0)
|
|
PEACH = (255, 218, 185)
|
|
DARK_PEACH = (205, 175, 149)
|
|
DARKER_PEACH = (235, 200, 175)
|
|
YELLOW = (255, 223, 0)
|
|
|
|
# Screen dimensions
|
|
SCREEN_WIDTH = 800
|
|
SCREEN_HEIGHT = 600
|
|
|
|
# Button dimensions
|
|
BUTTON_WIDTH = 200
|
|
BUTTON_HEIGHT = 100
|
|
|
|
# Initialize Pygame
|
|
pygame.init()
|
|
|
|
# Create the screen
|
|
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.FULLSCREEN)
|
|
|
|
# Fonts
|
|
title_font = pygame.font.SysFont("sans-serif", 64)
|
|
subtitle_font = pygame.font.SysFont("serif", 32, italic=True)
|
|
button_font = pygame.font.SysFont("sans-serif", 24)
|
|
|
|
# Text
|
|
title_text = "custodisco"
|
|
subtitle_text = "hi, what do you want to do?"
|
|
button1_text = "create item"
|
|
button2_text = "lookup item"
|
|
button_yes_text = "yes"
|
|
button_no_text = "no, I'd like to create one now"
|
|
|
|
# Button states
|
|
button1_hovered = False
|
|
button2_hovered = False
|
|
button1_pressed = False
|
|
button2_pressed = False
|
|
button_yes_hovered = False
|
|
button_no_hovered = False
|
|
button_yes_pressed = False
|
|
button_no_pressed = False
|
|
back_button_hovered = False
|
|
back_button_pressed = False
|
|
home_button_hovered = False
|
|
home_button_pressed = False
|
|
|
|
# Function to calculate button text dimensions
|
|
def calculate_text_dimensions(text, font):
|
|
text_width, text_height = font.size(text)
|
|
return text_width, text_height
|
|
|
|
# Function to display text on the screen
|
|
def display_text(text, font, color, x, y):
|
|
text_surface = font.render(text, True, color)
|
|
text_rect = text_surface.get_rect(center=(x, y))
|
|
screen.blit(text_surface, text_rect)
|
|
|
|
# Function to display a button
|
|
def display_button(text, font, color, x, y, width, height):
|
|
pygame.draw.rect(screen, color, (x - width/2, y - height/2, width, height))
|
|
text_width, text_height = calculate_text_dimensions(text, font)
|
|
display_text(text, font, BLACK, x, y)
|
|
|
|
# Function to draw a sparkle
|
|
def draw_sparkle(x, y):
|
|
pygame.draw.line(screen, YELLOW, (x - 10, y - 10), (x + 10, y + 10), 2)
|
|
pygame.draw.line(screen, YELLOW, (x + 10, y - 10), (x - 10, y + 10), 2)
|
|
pygame.draw.line(screen, YELLOW, (x, y - 15), (x, y + 15), 2)
|
|
pygame.draw.line(screen, YELLOW, (x - 15, y), (x + 15, y), 2)
|
|
|
|
# Main menu screen
|
|
def display_main_menu():
|
|
screen.fill(LIGHT_SKY_BLUE)
|
|
|
|
# Title
|
|
display_text(title_text, title_font, BLACK, SCREEN_WIDTH // 2, SCREEN_HEIGHT // 4)
|
|
draw_sparkle(SCREEN_WIDTH // 2 + 150, SCREEN_HEIGHT // 4 - 20)
|
|
|
|
# Subtitle
|
|
display_text(subtitle_text, subtitle_font, BLACK, SCREEN_WIDTH // 2, SCREEN_HEIGHT // 3)
|
|
|
|
# Button 1
|
|
display_button(button1_text, button_font, PEACH, SCREEN_WIDTH // 3, SCREEN_HEIGHT // 2, BUTTON_WIDTH, BUTTON_HEIGHT)
|
|
|
|
# Button 2
|
|
display_button(button2_text, button_font, PEACH, 2 * SCREEN_WIDTH // 3, SCREEN_HEIGHT // 2, BUTTON_WIDTH, BUTTON_HEIGHT)
|
|
|
|
# Home button
|
|
display_button("H", button_font, PEACH, 50, 50, 50, 50)
|
|
|
|
# Create item screen
|
|
def display_create_item_screen():
|
|
screen.fill(LIGHT_SKY_BLUE)
|
|
|
|
# Title
|
|
title_width, _ = calculate_text_dimensions("do you have an existing Scuttlebutt account?", subtitle_font)
|
|
title_x = SCREEN_WIDTH // 2
|
|
title_y = SCREEN_HEIGHT // 4
|
|
display_text("do you have an existing Scuttlebutt account?", subtitle_font, BLACK, title_x, title_y)
|
|
|
|
# Button "Yes"
|
|
display_button(button_yes_text, button_font, PEACH, SCREEN_WIDTH // 3, SCREEN_HEIGHT // 2, BUTTON_WIDTH, BUTTON_HEIGHT)
|
|
|
|
# Button "No"
|
|
display_button(button_no_text, button_font, PEACH, 2 * SCREEN_WIDTH // 3, SCREEN_HEIGHT // 2, BUTTON_WIDTH, BUTTON_HEIGHT)
|
|
|
|
# Back button
|
|
display_button("<", button_font, PEACH, 50, SCREEN_HEIGHT - 50, 50, 50)
|
|
|
|
# Home button
|
|
display_button("H", button_font, PEACH, 50, 50, 50, 50)
|
|
|
|
# Game loop
|
|
clock = pygame.time.Clock()
|
|
running = True
|
|
state = "main_menu" # Initial state
|
|
while running:
|
|
clock.tick(60) # Limit the frame rate to 60 FPS
|
|
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
running = False
|
|
pygame.quit()
|
|
sys.exit()
|
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
|
if state == "main_menu":
|
|
if button1_hovered:
|
|
button1_pressed = True
|
|
elif button2_hovered:
|
|
button2_pressed = True
|
|
elif home_button_hovered:
|
|
state = "main_menu"
|
|
elif state == "create_item_screen":
|
|
if button_yes_hovered:
|
|
button_yes_pressed = True
|
|
elif button_no_hovered:
|
|
button_no_pressed = True
|
|
elif back_button_hovered:
|
|
state = "main_menu"
|
|
elif home_button_hovered:
|
|
state = "main_menu"
|
|
elif event.type == pygame.MOUSEBUTTONUP:
|
|
if state == "main_menu":
|
|
if button1_pressed and button1_hovered:
|
|
state = "create_item_screen"
|
|
print("Going to create item screen")
|
|
elif button2_pressed and button2_hovered:
|
|
print("Going to lookup item screen")
|
|
button1_pressed = False
|
|
button2_pressed = False
|
|
elif state == "create_item_screen":
|
|
if button_yes_pressed and button_yes_hovered:
|
|
print("You selected Yes")
|
|
elif button_no_pressed and button_no_hovered:
|
|
print("You selected No")
|
|
button_yes_pressed = False
|
|
button_no_pressed = False
|
|
|
|
# Update button states
|
|
mouse_pos = pygame.mouse.get_pos()
|
|
button1_hovered = pygame.Rect(SCREEN_WIDTH // 3 - BUTTON_WIDTH / 2, SCREEN_HEIGHT // 2 - BUTTON_HEIGHT / 2, BUTTON_WIDTH, BUTTON_HEIGHT).collidepoint(mouse_pos)
|
|
button2_hovered = pygame.Rect(2 * SCREEN_WIDTH // 3 - BUTTON_WIDTH / 2, SCREEN_HEIGHT // 2 - BUTTON_HEIGHT / 2, BUTTON_WIDTH, BUTTON_HEIGHT).collidepoint(mouse_pos)
|
|
button_yes_hovered = pygame.Rect(SCREEN_WIDTH // 3 - BUTTON_WIDTH / 2, SCREEN_HEIGHT // 2 - BUTTON_HEIGHT / 2, BUTTON_WIDTH, BUTTON_HEIGHT).collidepoint(mouse_pos)
|
|
button_no_hovered = pygame.Rect(2 * SCREEN_WIDTH // 3 - BUTTON_WIDTH / 2, SCREEN_HEIGHT // 2 - BUTTON_HEIGHT / 2, BUTTON_WIDTH, BUTTON_HEIGHT).collidepoint(mouse_pos)
|
|
back_button_hovered = pygame.Rect(50 - 25, SCREEN_HEIGHT - 50 - 25, 50, 50).collidepoint(mouse_pos)
|
|
home_button_hovered = pygame.Rect(50 - 25, 50 - 25, 50, 50).collidepoint(mouse_pos)
|
|
|
|
# Render screen based on state
|
|
if state == "main_menu":
|
|
display_main_menu()
|
|
elif state == "create_item_screen":
|
|
display_create_item_screen()
|
|
|
|
pygame.display.flip()
|
|
|