def run_start_screen(win): hover = False while True: pygame.time.delay(10) startScreen.mainScreen(hover) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() return if event.type == pygame.MOUSEMOTION: pos = pygame.mouse.get_pos() hover = startScreen.shopClick(pos) course = startScreen.click(pos) startScreen.mouseOver(course != None) if event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() if startScreen.click(pos) != None: return if startScreen.shopClick(pos): run_shop(startScreen, win)
def endScreen(): # Display this screen when the user completes the course global start, starting, level, sheet, coins starting = True start = True # Draw all text to display on screen win.blit(background, (0, 0)) text = myFont.render('Course Completed!', 1, (64, 64, 64)) win.blit(text, (winWidth / 2 - text.get_width() / 2, 210)) text = parFont.render('Par: ' + str(sheet.getPar()), 1, (64, 64, 64)) win.blit(text, (winWidth / 2 - text.get_width() / 2, 320)) text = parFont.render('Strokes: ' + str(sheet.getStrokes()), 1, (64, 64, 64)) win.blit(text, (winWidth / 2 - text.get_width() / 2, 280)) blit = parFont.render('Press the mouse to continue...', 1, (64, 64, 64)) win.blit(blit, (winWidth / 2 - blit.get_width() / 2, 510)) text = parFont.render('Score: ' + str(sheet.getScore()), 1, (64, 64, 64)) win.blit(text, (winWidth / 2 - text.get_width() / 2, 360)) text = parFont.render('Coins Collected: ' + str(coins), 1, (64, 64, 64)) win.blit(text, (winWidth / 2 - text.get_width() / 2, 470)) pygame.display.update() if powerups == 9 and sheet.getScore() <= -1: text = myFont.render('Clean Ball Awarded and Negative Score!!!', 1, (54, 204, 31)) win.blit(text, (winWidth / 2 - text.get_width() / 2, 170)) coins += 10 pygame.display.update() elif powerups == 9: text = myFont.render('Clean Ball Awarded!!!', 1, (54, 204, 31)) win.blit(text, (winWidth / 2 - text.get_width() / 2, 170)) coins += 5 pygame.display.update() elif sheet.getScore() <= -1: text = myFont.render('Negative Score!!!', 1, (54, 204, 31)) win.blit(text, (winWidth / 2 - text.get_width() / 2, 170)) coins += 5 pygame.display.update() # RE-WRITE TEXT FILE Containing Scores oldScore = 0 oldCoins = 0 file = open('scores.txt', 'r') f = file.readlines() for line in file: l = line.split() if l[0] == 'score': oldScore = str(l[1]).strip() if l[0] == 'coins': oldCoins = str(l[1]).strip() file = open('scores.txt', 'w') if str(oldScore).lower() != 'none': if sheet.getScore() < int(oldScore): text = myFont.render('New Best!', 1, (64, 64, 64)) win.blit(text, (winWidth / 2 - text.get_width() / 2, 130)) pygame.display.update() file.write('score ' + str(sheet.getScore()) + '\n') file.write('coins ' + str(int(oldCoins) + coins) + '\n') else: file.write('score ' + str(oldScore) + '\n') file.write('coins ' + str(int(oldCoins) + coins) + '\n') else: file.write('score ' + str(sheet.getScore()) + '\n') file.write('coins ' + str(int(oldCoins) + coins) + '\n') co = 0 for line in f: if co > 2: file.write(line) co += 1 file.close() # Wait loop = True while loop: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() if event.type == pygame.MOUSEBUTTONDOWN: loop = False break level = 1 setup(level) list = courses.getPar(1) par = list[level - 1] sheet = ScoreSheet(list) starting = True hover = False while starting: pygame.time.delay(10) startScreen.mainScreen(hover) for event in pygame.event.get(): if event.type == pygame.MOUSEMOTION: pos = pygame.mouse.get_pos() hover = startScreen.shopClick(pos) course = startScreen.click(pos) startScreen.mouseOver(course is not None) if event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() if startScreen.click(pos) is not None: starting = False break if startScreen.shopClick(pos) is True: surface = startScreen.drawShop() win.blit(surface, (0, 0)) pygame.display.update() shop = True while shop: for event in pygame.event.get(): pygame.time.delay(10) if event.type == pygame.QUIT: pygame.quit() if event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() if 10 < pos[0] < 100 and pos[1] > 560: shop = False break surface = startScreen.drawShop(pos, True) win.blit(surface, (0, 0)) pygame.display.update() if event.type == pygame.QUIT: pygame.quit() break
# - Shooting the ball, uses physics module # - Keeping track of strokes # - Calls all functions and uses modules/classes imported and defined above # Start loop # Display start screen hover = False starting = True while starting: pygame.time.delay(10) startScreen.mainScreen(hover) for event in pygame.event.get(): if event.type == pygame.MOUSEMOTION: pos = pygame.mouse.get_pos() hover = startScreen.shopClick(pos) course = startScreen.click(pos) startScreen.mouseOver(course is not None) if event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() if startScreen.click(pos) is not None: starting = False break if startScreen.shopClick(pos) is True: surface = startScreen.drawShop() win.blit(surface, (0, 0)) pygame.display.update() shop = True while shop: for event in pygame.event.get(): pygame.time.delay(10) if event.type == pygame.QUIT:
# - Shooting the ball, uses physics module # - Keeping track of strokes # - Calls all functions and uses modules/classes imported and defined above # Start loop # Display start screen hover = False starting = True while starting: pygame.time.delay(10) startScreen.mainScreen(hover) for event in pygame.event.get(): if event.type == pygame.MOUSEMOTION: pos = pygame.mouse.get_pos() hover = startScreen.shopClick(pos) course = startScreen.click(pos) startScreen.mouseOver(course != None) if event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() if startScreen.click(pos) != None: starting = False break if startScreen.shopClick(pos) == True: surface = startScreen.drawShop() win.blit(surface, (0, 0)) pygame.display.update() shop = True while shop: for event in pygame.event.get(): pygame.time.delay(10) if event.type == pygame.QUIT:
def endScreen(): # Display this screen when the user completes trhe course global Start, starting, level, sheet, coins, user starting = True Start = True # Draw all text to display on screen win.blit(background, (0, 0)) text = myFont.render('Course Completed!', 1, (64, 64, 64)) win.blit(text, (winwidth / 2 - text.get_width() / 2, 210)) text = parFont.render('Par: ' + str(sheet.getPar()), 1, (64, 64, 64)) win.blit(text, ((winwidth / 2 - text.get_width() / 2, 320))) text = parFont.render('Strokes: ' + str(sheet.getStrokes()), 1, (64, 64, 64)) win.blit(text, ((winwidth / 2 - text.get_width() / 2, 280))) blit = parFont.render('Press the mouse to continue...', 1, (64, 64, 64)) win.blit(blit, (winwidth / 2 - blit.get_width() / 2, 510)) text = parFont.render('Score: ' + str(sheet.getScore()), 1, (64, 64, 64)) win.blit(text, ((winwidth / 2 - text.get_width() / 2, 360))) pygame.display.update() # Change highscore if applicable session = boto3.resource( 'dynamodb', aws_access_key_id='AKIAIOPUXE2QS7QN2MMQ', aws_secret_access_key='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', region_name="ca-central-1") table = session.Table('highscores') response = table.query(KeyConditionExpression=Key('peopleid').eq(user)) for i in response['Items']: score = i['golf'] if sheet.getScore() < score or score == 0: if sheet.getScore() == 0: leaderboard.addHighscore(user, 'golf', 'Par') else: leaderboard.addHighscore(user, 'golf', sheet.getScore()) leaderboard.addGamesPlayed(user, 'golf') leaderboard.addTimePlayed(user, 'golf', t.time() - timePlayed) # Wait loop = True while loop: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() if event.type == pygame.MOUSEBUTTONDOWN: loop = False break level = 1 setup(level) list = courses.getPar(1) par = list[level - 1] sheet = scoreSheet(list) starting = True hover = False while starting: pygame.time.delay(10) startScreen.mainScreen(user, hover) for event in pygame.event.get(): if event.type == pygame.MOUSEMOTION: pos = pygame.mouse.get_pos() hover = startScreen.shopClick(pos) course = startScreen.click(pos) startScreen.mouseOver(course != None) if event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() if startScreen.click(pos) != None: starting = False break if startScreen.shopClick(pos) == True: surface = startScreen.drawShop() win.blit(surface, (0, 0)) pygame.display.update() shop = True while shop: for event in pygame.event.get(): pygame.time.delay(10) if event.type == pygame.QUIT: pygame.quit() if event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() if pos[0] > 10 and pos[0] < 100 and pos[ 1] > 560: shop = False break surface = startScreen.drawShop(pos, True) win.blit(surface, (0, 0)) pygame.display.update() if event.type == pygame.QUIT: pygame.quit() break