forked from ismailhasannnnnn/PyMario
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpregamescreen.py
More file actions
63 lines (47 loc) · 1.8 KB
/
pregamescreen.py
File metadata and controls
63 lines (47 loc) · 1.8 KB
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
import pygame as pg
import sys
from mario import Mario
from vector import Vector
from button import Button
import time
GREEN = (0, 255, 0)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREY = (130, 130, 130)
ORANGE = (217, 91, 13)
class PregameScreen:
menu_bg = pg.transform.rotozoom(pg.image.load("images/menu_bg.png"), 0, 0.65)
def __init__(self, game):
self.settings = game.settings
self.screen = game.screen
self.menu_finished = False
self.highscore = game.stats.get_highscore()
headingFont = pg.font.Font("fonts/8bit.ttf", 30)
subheadingFont = pg.font.Font("fonts/8bit.ttf", 30)
font = pg.font.SysFont(None, 48)
strings = [('WORLD 1-1', WHITE, headingFont),
(f'HIGH SCORE = {self.highscore:}', WHITE, subheadingFont),
]
self.texts = [self.get_text(msg=s[0], color=s[1], msg_font=s[2]) for s in strings]
self.posns = [100, 230, 340, 400]
centerx = self.screen.get_rect().centerx
self.play_button = Button(self.screen, "START GAME", ul=(centerx - 125, 500))
n = len(self.texts)
self.rects = [self.get_text_rect(text=self.texts[i], centerx=centerx, centery=self.posns[i]) for i in range(n)]
def get_text(self, msg_font, msg, color): return msg_font.render(msg, True, color, BLACK)
def get_text_rect(self, text, centerx, centery):
rect = text.get_rect()
rect.centerx = centerx
rect.centery = centery
return rect
def show(self):
self.draw()
time.sleep(1)
def draw_text(self):
n = len(self.texts)
for i in range(n):
self.screen.blit(self.texts[i], self.rects[i])
def draw(self):
self.screen.fill(self.settings.bg_color)
self.draw_text()
pg.display.flip()