def update(self, screen): if self.replace == None: with self.ui.newcontext(ui.UIContext(font_size=40)): self.ui.draw_text(screen, "Game Over", location=(screen.get_width() / 2, screen.get_height() / 10), align=0) self.ui.draw_text(screen, "Your Score: " + str(self.score), location=(screen.get_width() / 2, 3 * screen.get_height() / 10), align=0) else: with self.ui.newcontext(ui.UIContext(font_size=40)): self.ui.draw_text(screen, "Game Over", location=(screen.get_width() / 2, screen.get_height() / 10), align=0) self.ui.draw_text(screen, "New High Score!", location=(screen.get_width() / 2, 3 * screen.get_height() / 10), align=0) self.ui.draw_text(screen, "Your Score: " + str(self.score), location=(screen.get_width() / 2, 4 * screen.get_height() / 10), align=0) self.ui.draw_text(screen, "Enter your initials:", location=(screen.get_width() / 2, 5 * screen.get_height() / 10), align=0)
def draw_logo(self, screen): logo = "Whack-a-Dot" prompt = "Click to begin" with self.ui.newcontext( ui.UIContext(font_size=60, location=(screen.get_width() / 2, screen.get_height() / 3), align=0)): self.ui.draw_text(screen, logo) with self.ui.newcontext( ui.UIContext(font_size=40, location=(screen.get_width() / 2, screen.get_height() / 2), align=0)): self.ui.draw_text(screen, prompt)
def update(self, screen): with self.ui.newcontext(ui.UIContext(font_size=80)): self.ui.draw_text(screen, self.text, location=(screen.get_width() / 2, screen.get_height() / 2), align=0) lives = "Lives: " + str(self.lives) score = "Score: " + str(self.score) with self.ui.newcontext(ui.UIContext(font_size=40)): self.ui.draw_text(screen, lives, location=(10, screen.get_height() / 10), align=-1) self.ui.draw_text(screen, score, location=(screen.get_width(), screen.get_height() / 10), align=1)
def setup(self, screen): if self.replace == None: pass else: size = (75, 50) location = ((screen.get_width() / 2) - (size[0] / 2), 6 * screen.get_height() / 10) with self.ui.newcontext(ui.UIContext(font_size=30, len_cap=3)): self.ui.add_input(screen, "___", lambda text: self.input_text(text), location=location, size=size)
def update(self, screen): # draw stats time = str(self.get_time()) lives = "Lives: " + str(self.lives) misses = "Misses: " + str(self.misses) + " of " + str( self.misses_per_life) score = "Score: " + str(self.score) with self.ui.newcontext(ui.UIContext(font_size=40)): self.ui.draw_text(screen, lives, location=(10, screen.get_height() / 10), align=-1) self.ui.draw_text(screen, misses, location=(10, 2 * screen.get_height() / 10), align=-1) self.ui.draw_text(screen, score, location=(screen.get_width(), screen.get_height() / 10), align=1) self.ui.draw_text(screen, time, location=(screen.get_width(), 2 * screen.get_height() / 10), align=1) # draw cirles [pos, radius, width, rect] = self.dot screen.lock() try: self.dot[3] = self.ui.draw_circle(screen, location=pos, radius=radius) for circle in self.circles: [pos, radius, width, rect] = circle with self.ui.newcontext(ui.UIContext(line_width=circle[2])): self.ui.draw_circle(screen, location=pos, radius=radius) finally: screen.unlock()
def setup(self): self.pos = (0, 0) self.rect = pygame.Rect(self.pos, (W, H)) self.gameover = IL.ImageLoader("resources\\breakout_endpg.png") self.gameover_image = self.gameover.load(self.rect) if self.replace == None: pass else: size = (75, 50) location = ((W / 2) - (size[0] / 2), 8 * H / 10 + 30) with self.ui.newcontext( ui.UIContext("Breakout Revisited", W, H, 0, "Comfortaa-Regular.ttf", 30, BLACK, DK_PURPLE, location, size, 0, 3, 0)): self.ui.add_input("___", lambda text: self.input_text(text))
def draw_high_scores(self, screen): scores = HighScores.high_scores caption = "High Scores" with self.ui.newcontext(ui.UIContext(font_size=40)): self.ui.draw_text(screen, caption, location=(screen.get_width() / 2, screen.get_height() / 11), align=0) spacing = 40 dots = "".join([" ." for i in range(spacing)]) for key, (name, score) in sorted(scores.items()): txt = "".join([name, dots, str(score)]) self.ui.draw_text(screen, txt, location=(screen.get_width() / 2, (key + 1) * screen.get_height() / 12), align=0)
import pygame from utilities_1 import level_loader as LL from utilities_1 import ui # CONSTANTS W, H = 800, 700 # Screen width and height LEVELS = LL.LevelLoader("resources\\levels.txt").open_file() DK_PURPLE = pygame.Color(128, 0, 255, 255) BLACK = pygame.Color(0, 0, 0, 255) Jules_UIContext = ui.UIContext("Breakout Revisited", W, H, 0, "resources\\Comfortaa-Regular.ttf", 30, BLACK, DK_PURPLE, (0, 0), (W / 10, H / 10), 0, 0, 0) REBOUND_SOUND_FILES = { "boop1": "resources\\boop1.ogg", "beep1": "resources\\beep1.ogg", "bop1": "resources\\bop1.ogg" } def main(): print(W, H) print LEVELS print DK_PURPLE, BLACK print Jules_UIContext print REBOUND_SOUND_FILES