Skip to content

Commit a34d980

Browse files
committed
Moved menu.py function to main
Moved button function to main to implement quick fix for release. Will be reverted and changed at a later date
1 parent 2e95311 commit a34d980

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

main.py

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#main will call the other files and classes to run the game
44

55
import pygame
6-
import menu
6+
# import menu # import menu.py file, currently disabled
77

88
# create pygame window and set title
99
pygame.init()
@@ -27,7 +27,7 @@
2727

2828
# title for display
2929
game_title = "Checkers+"
30-
message = "Checkers with a twist! For all ages and skill levels!" # can change to whatever we feel is best
30+
message = "Checkers with a twist! For all ages and skill levels!"
3131

3232
background_image = pygame.image.load("checkers.jpg")
3333
background_image = pygame.transform.scale(background_image, (Width, Height))
@@ -64,12 +64,75 @@ def main():
6464
screen.blit(message_text, message_rect)
6565

6666
# call PvP button function from menu.py
67-
menu.pvp_button()
67+
menu_buttons()
6868

6969
# flip the display
7070
pygame.display.flip()
7171

7272
# done! time to quit
7373
pygame.quit()
7474

75+
# function to create menu buttons
76+
# currently supports PvP and settings buttons
77+
def menu_buttons():
78+
color = (128, 128, 128) # grey
79+
cursor_color = (100, 100, 100) # darker grey
80+
position = (Width // 2-150, Height // 3-25)
81+
size = (300, 50) # width, height
82+
83+
button_font = pygame.font.Font(None, 32)
84+
button_text = button_font.render("Start Game Against Player", True, (255, 255, 255)) # Button text and color
85+
button_text_rect = button_text.get_rect(center=(Width // 2, Height // 3))
86+
87+
# Create button on screen using position and size parameters
88+
pygame.draw.rect(screen, color, pygame.Rect(position, size))
89+
screen.blit(button_text, button_text_rect)
90+
91+
# Used to indicate if cursor is hovering over button. If so, button will be darker
92+
mouse = pygame.mouse.get_pos()
93+
button_rect = pygame.Rect(position, size)
94+
if button_rect.collidepoint(mouse):
95+
pygame.draw.rect(screen, cursor_color, button_rect) # Change color when cursor hovered over
96+
else:
97+
pygame.draw.rect(screen, color, button_rect) # stay original color if cursor not hovering over
98+
99+
screen.blit(button_text, button_text_rect)
100+
101+
# Settings Button
102+
settings_icon = pygame.image.load('pics/settings_icon.png')
103+
104+
button_height = 50
105+
spacing = 10
106+
107+
position = (Width // 2 - 150, Height // 3 + button_height + spacing)
108+
size = (300, button_height) # width, height
109+
110+
button_text = button_font.render("Settings", True, (255, 255, 255)) # Button text and color
111+
button_text_rect = button_text.get_rect(center=(Width // 2, Height // 3 + button_height + spacing + button_height // 2))
112+
113+
# Set the desired size for the icon
114+
icon_size = (45, 45) # Adjust the size of the icon as needed
115+
116+
# Draw the icon next to the text with the specified size
117+
settings_icon_resized = pygame.transform.scale(settings_icon, icon_size)
118+
settings_icon_rect = settings_icon_resized.get_rect(topleft=(Width // 2 - 150 + 10, Height // 3 + button_height + spacing + (button_height - icon_size[1]) // 2))
119+
120+
# Create button on screen using position and size parameters
121+
pygame.draw.rect(screen, color, pygame.Rect(position, size))
122+
screen.blit(button_text, button_text_rect)
123+
124+
# Used to indicate if the cursor is hovering over the button. If so, the button will be darker
125+
mouse = pygame.mouse.get_pos()
126+
button_rect_2 = pygame.Rect(position, size)
127+
if button_rect_2.collidepoint(mouse):
128+
pygame.draw.rect(screen, cursor_color, button_rect_2) # Change color when cursor hovered over
129+
else:
130+
pygame.draw.rect(screen, color, button_rect_2) # Stay the original color if the cursor is not hovering over
131+
132+
screen.blit(settings_icon_resized, settings_icon_rect.topleft) # Draw the icon after drawing the button
133+
screen.blit(button_text, button_text_rect)
134+
135+
return button_rect, button_rect_2
136+
137+
75138
main()

menu.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
# created a menu file for menu operations
33
# can be changed or refactored if we rather keep menu functions in main.py
44

5+
# CURRENTLY NOT BEING USED IN main.py
6+
57
import pygame
68
Width, Height = 1000, 700 # match size from main.py
79
screen = pygame.display.set_mode([Width, Height])
810

911
# create a button for player versus player mode
10-
def pvp_button():
12+
def menu_buttons():
1113
color = (128, 128, 128) # grey
1214
cursor_color = (100, 100, 100) # darker grey
1315
position = (Width // 2-150, Height // 3-25)

0 commit comments

Comments
 (0)