Ejemplo n.º 1
0
def setup(level):  # Setup objects for the level from module courses
    global line, par, hole, power, ballStationary, objects, ballColor, stickyPower, superPower, mullagain, freeShot
    global halo
    ballColor = (255, 255, 255)
    stickyPower = False
    superPower = False
    mullagain = False
    freeShot = False
    halo = False
    if level >= 10:
        endScreen()  # Completed the course
    else:
        list = courses.getPar(1)
        par = list[level - 1]
        pos = courses.getStart(level, 1)
        ballStationary = pos

        objects = courses.getLvl(level)

        # Create the borders if sand is one of the objects
        for i in objects:
            if i[4] == 'sand':
                objects.append([i[0] - 16, i[1], 16, 64, 'edge'])
                objects.append(
                    [i[0] + ((i[2] // 64) * 64), i[1], 16, 64, 'edge'])
                objects.append([i[0], i[1] + 64, i[2], 16, 'bottom'])
            elif i[4] == 'flag':
                # Define the position of the hole
                hole = (i[0] + 2, i[1] + i[3])

        line = None
        power = 1
Ejemplo n.º 2
0
def setup():  # Setup objects for the level from module courses
    global level, line, par, hole, power, ball, level_map, stickyPower, superPower, mullagain
    ball.color = (255,255,255)
    stickyPower = False
    superPower = False
    mullagain = False
    if level >= 10:
        endScreen()  # Completed the course
    else:
        list = courses.getPar(1)
        par = list[level - 1]
        pos = courses.getStart(level, 1)
        ball.set_coordinates(*pos)

        level_map = Map(courses.getLvl(level))

        # Create the borders if sand is one of the objects
        for flag in level_map.flags():
            hole = MapHole(flag.x1 + 2, flag.y1 + flag.y2)

        line = None
        power = 1
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
                return True
            else:
                return False


def overHole(x, y):  # Determine if we are over top of the hole
    if hole[0] - 6 < x < hole[0] + 6:
        if hole[1] - 13 < y < hole[1] + 10:
            return True
        else:
            return False
    else:
        return False


list = courses.getPar(1)
par = list[level - 1]
sheet = ScoreSheet(list)

pos = courses.getStart(level, 1)
ballStationary = pos
setup(1)

# MAIN GAME LOOP:
# - Collision of ball
# - Locking angle and power
# - Checking if power up buttons are clicked
# - Shooting the ball, uses physics module
# - Keeping track of strokes
# - Calls all functions and uses modules/classes imported and defined above
Ejemplo n.º 5
0
def endScreen(): # Display this screen when the user completes trhe course
    global level, sheet, coins

    # 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()


    # RE-WRITE TEXT FILE Contaning 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
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                return
    level = 1
    setup()
    list = courses.getPar(1)
    par = list[level - 1]
    sheet = scoreSheet(list)

    run_start_screen(win)
Ejemplo n.º 6
0
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