-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.py
105 lines (80 loc) · 3.37 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
import pygame, sys
from pygame.locals import *
from button import Button
import messages
from _thread import start_new_thread
import cv2
import numpy as np
from mouse import Mouse
def main():
pygame.init()
clock = pygame.time.Clock()
pygame.display.set_caption('FBLA 2023-24')
global WINDOW_SIZE
WINDOW_SIZE = (800, 600)
screen = pygame.display.set_mode(WINDOW_SIZE, 0, 32)
cap = cv2.VideoCapture('data/images/grand opening.mp4')
bg_img = pygame.image.load("data/images/grand opening.png")
title_font = pygame.font.Font('data/ARCADE_N.TTF', 30)
video_playing = True
while True:
clicked = False
if video_playing:
# Read a frame from the video
ret, frame = cap.read()
if not ret:
video_playing = False
else:
# Convert the frame from BGR to RGB
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame = cv2.flip(frame, 1)
# Convert the frame to a Pygame surface
frame_surface = pygame.surfarray.make_surface(np.rot90(frame))
# Display the frame on the Pygame window
screen.blit(frame_surface, (0, 0))
else:
# Display the background image
screen.blit(bg_img, (0, 0))
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 == MOUSEBUTTONUP:
clicked = True
start_button = Button(title_font, "START", Color("black"), pygame.Rect(WINDOW_SIZE[0] // 2 - 75, 320, 150, 50), Color("white"), Color("pink"))
start_button.draw_button(screen, pygame.mouse.get_pos())
instruction_button = Button(title_font, "INSTRUCTIONS", Color("black"), pygame.Rect(WINDOW_SIZE[0] // 2 - 175, 400, 350, 50), Color("white"), Color("pink"))
instruction_button.draw_button(screen, pygame.mouse.get_pos())
quit_button = Button(title_font, "QUIT", Color("black"), pygame.Rect(WINDOW_SIZE[0] // 2 - 75, 480, 150, 50), Color("white"), Color("pink"))
quit_button.draw_button(screen, pygame.mouse.get_pos())
if clicked and start_button.checkHover(pygame.mouse.get_pos()):
play_effect('data/audio/select.wav')
messages.story_line()
pygame.quit()
sys.exit()
elif clicked and instruction_button.checkHover(pygame.mouse.get_pos()):
play_effect('data/audio/select.wav')
messages.instructions1()
pygame.quit()
sys.exit()
elif clicked and quit_button.checkHover(pygame.mouse.get_pos()):
play_effect('data/audio/select.wav')
pygame.quit()
sys.exit()
pygame.display.update()
pygame.display.flip()
dt = clock.tick(60)
def play_bg_music(filename):
bg_music = pygame.mixer.Sound(filename)
bg_music.set_volume(0.2)
pygame.mixer.Channel(0).play(bg_music, -1)
def play_effect(filename):
pygame.mixer.Channel(1).play(pygame.mixer.Sound(filename))
if __name__ == '__main__':
pygame.mixer.init()
start_new_thread(play_bg_music, ('data/audio/bg_music.wav',))
main()