-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartScreen.py
executable file
·81 lines (66 loc) · 3.16 KB
/
startScreen.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
#History Mansion - A history slider game
#startScreen.py Created by Terry Clark
#Released under a "Simplified BSD" License
import pygame, sys, levelSelect, quiz, scoreBoard
from context import *
from pygame.locals import *
class startScreen():
def __init__(self, screen):
#Screen Size
self.WINDOWWIDTH = 1100
self.WINDOWHEIGHT = 700
#Set In Game colors and assets
self.WHITE = ( 255, 255, 255 )
self.BLACK = ( 0, 0, 0 )
self.BROWN = ( 180, 120, 40 )
self.BGIMAGE = pygame.image.load("Assets/images/Pictures/mansion/mansion.jpg")
#Button Attributes
self.BUTTONTEXTCOLOR = self.WHITE
#Main Theme Tune
self.startSOUND = pygame.mixer.Sound("Assets/Audio/Mansion.wav")
#Option buttons
self.START_SURF, self.START_RECT = self.makeText('Start Game', self.BUTTONTEXTCOLOR, 40, self.WINDOWWIDTH/2, 400)
self.SCOREBOARD_SURF, self.SCOREBOARD_RECT = self.makeText('Score Board', self.BUTTONTEXTCOLOR, 40, self.WINDOWWIDTH/2, 450)
self.QUIZ_SURF, self.QUIZ_RECT = self.makeText('Take a Quiz', self.BUTTONTEXTCOLOR, 40, self.WINDOWWIDTH/2, 500)
self.EXIT_SURF, self.EXIT_RECT = self.makeText('Exit', self.BUTTONTEXTCOLOR, 40, self.WINDOWWIDTH/2, 550)
self.startSOUND.play()
self.screen = screen
#/---Event loop function---\#
def update(self, dt):
for event in pygame.event.get():
if event.type == MOUSEBUTTONUP:
if self.START_RECT.collidepoint(event.pos): #user clicked start button
#choose level here
push(levelSelect.levelSelect())
elif self.SCOREBOARD_RECT.collidepoint(event.pos):#user clicked start button
push(scoreBoard.scoreBoard())
elif self.QUIZ_RECT.collidepoint(event.pos):#user clicked start button
push(quiz.quiz())
elif self.EXIT_RECT.collidepoint(event.pos):
if top() is self:
pop()
elif event.type == KEYUP:
if event.key == K_ESCAPE:
if top() is self:
pop()
elif event.type == QUIT:
sys.exit()
#/-----Draw to screen-----\#
def draw(self, dt):
# Blit (Show) everything to the screen
self.screen.blit(self.BGIMAGE, (0, 0))
self.screen.blit(self.START_SURF, self.START_RECT)
self.screen.blit(self.SCOREBOARD_SURF, self.SCOREBOARD_RECT)
self.screen.blit(self.QUIZ_SURF, self.QUIZ_RECT)
self.screen.blit(self.EXIT_SURF, self.EXIT_RECT)
pygame.display.flip()
#/-----In Game Functions-----\#
def think(self, dt):
self.update(dt)
self.draw(dt)
def makeText(self, text, color, size, centerx, height):
font = pygame.font.SysFont("monospace", size, bold=True, italic = True)
textSurf = font.render(text, True, color)
textRect = textSurf.get_rect()
textRect.midbottom = (centerx, height)
return (textSurf, textRect)