-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmenu.py
110 lines (89 loc) · 3.45 KB
/
menu.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
# Setup Python
from socket import EAI_SYSTEM
from tkinter import Button
import pygame, sys
# Setup pygame/window
mainClock = pygame.time.Clock()
from pygame.locals import *
pygame.init()
pygame.display.set_caption('Menu feature')
screen = pygame.display.set_mode((672, 672),0,32)
pygame.display.set_caption("I'm a Coder, Get Me Out of Here!")
font = pygame.font.SysFont('consolas', 60)
smallText = pygame.font.SysFont('Verdana', 35)
def draw_text(text, font, colour, surface, x, y):
textobj = font.render(text, 1, colour)
textrect = textobj.get_rect()
textrect.topleft = (x, y)
surface.blit(textobj, textrect)
#Adding a click variable
click = False
def main_menu():
while True:
screen.fill((0,0,0))
draw_text('main menu', font, (255, 255, 255), screen, 80, 50)
mx, my = pygame.mouse.get_pos()
button_1 = pygame.Rect(175, 200, 372, 75)
button_2 = pygame.Rect(175, 300, 372, 75)
button_3 = pygame.Rect(175, 400, 372, 75)
if button_1.collidepoint((mx, my)):
if click:
game_easy()
if button_2.collidepoint((mx, my)):
if click:
game_hard()
if button_3.collidepoint((mx, my)):
if click:
how_to_play()
pygame.draw.rect(screen, (255, 0, 0), button_1)
pygame.draw.rect(screen, (255, 0, 0), button_2)
pygame.draw.rect(screen, (255, 0, 0), button_3)
draw_text('Easy Mode', smallText, (255, 255, 255), screen, 265, 215)
draw_text('Hard Mode', smallText, (255, 255, 255), screen, 265, 315)
draw_text('How to Play', smallText, (255, 255, 255), screen, 255, 415)
#Resets click to false after every frame.
click = False
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
click = True
pygame.display.update()
mainClock.tick(60)
def game_easy():
exec(open("main.py").read())
mode = 'easy'
return mode
def game_hard():
mode = 'hard'
return mode
def how_to_play():
running = True
while running:
screen.fill((0,0,0))
draw_text('how to play', font, (255,255, 255), screen, 80, 50)
draw_text('Movement:', smallText, (255, 0, 0), screen, 120, 200)
draw_text('Action:', smallText, (255, 0, 0), screen, 195, 250)
draw_text('Exit:', smallText, (255, 0, 0), screen, 240, 300)
draw_text('Arrow Keys', smallText, (255, 100, 0), screen, 330, 200)
draw_text('Space Bar', smallText, (255, 100, 0), screen, 330, 250)
draw_text('Esc Key', smallText, (255, 100, 0), screen, 330, 300)
draw_text('Answer the Questions', smallText, (0, 255, 0), screen, 135, 400)
draw_text('Solve the Riddle', smallText, (0, 255, 0), screen, 180, 450)
draw_text('Escape the Room', smallText, (0, 255, 0), screen, 175, 500)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
running = False
pygame.display.update()
mainClock.tick(60)
main_menu()