Exemplo n.º 1
0
def update():
    global fox_score
    global hedgehog_score
    global game_over

    if not game_over:
        if keyboard.left:
            fox.x -= 6
        elif keyboard.right:
            fox.x += 6
        elif keyboard.up:
            fox.y -= 6
        elif keyboard.down:
            fox.y += 6

        fox_coin_collected = fox.colliderect(coin)

        if fox_coin_collected:
            fox_score += 1
            place_coin()

        if not hedgehog.colliderect(fox):
            if hedgehog.y > coin.y:
                hedgehog.y -= 1.75
            elif hedgehog.y < coin.y:
                hedgehog.y *= 1.05
            if hedgehog.x > coin.x:
                hedgehog.x -= 1.75
            elif hedgehog.x < coin.x:
                hedgehog.x *= 1.05

        hedgehog_coin_collected = hedgehog.colliderect(coin)

        if hedgehog_coin_collected:
            hedgehog_score += 1
            place_coin()

    elif game_over:
        hedgehog.x = 0
        hedgehog.y = 0
    elif game_over and keyboard.space:
        game_over = False
        hedgehog_score = 0
        fox_score = 0
        if not hedgehog.colliderect(fox):
            if hedgehog.y > coin.y:
                hedgehog.y -= 1.75
            elif hedgehog.y < coin.y:
                hedgehog.y *= 1.05
            if hedgehog.x > coin.x:
                hedgehog.x -= 1.75
            elif hedgehog.x < coin.x:
                hedgehog.x *= 1.05
        clock.schedule(time_up, 20.0)
Exemplo n.º 2
0
                hedgehog.x *= 1.05

        hedgehog_coin_collected = hedgehog.colliderect(coin)

        if hedgehog_coin_collected:
            hedgehog_score += 1
            place_coin()

    elif game_over:
        hedgehog.x = 0
        hedgehog.y = 0
    elif game_over and keyboard.space:
        game_over = False
        hedgehog_score = 0
        fox_score = 0
        if not hedgehog.colliderect(fox):
            if hedgehog.y > coin.y:
                hedgehog.y -= 1.75
            elif hedgehog.y < coin.y:
                hedgehog.y *= 1.05
            if hedgehog.x > coin.x:
                hedgehog.x -= 1.75
            elif hedgehog.x < coin.x:
                hedgehog.x *= 1.05
        clock.schedule(time_up, 20.0)


clock.schedule(time_up, 20.0)
place_coin()
pgzrun.go()
Exemplo n.º 3
0
    pineapple.draw()
    screen.draw.text(f"Score: {len(count)}", topleft=(10, 10))


def place_apple():
    apple.x = randint(-10, 310)
    apple.y = randint(-10, 310)
    orange.x = randint(-10, 310)
    orange.y = randint(-10, 310)
    pineapple.x = randint(-10, 310)
    pineapple.y = randint(-10, 310)


def on_mouse_down(pos):
    if apple.collidepoint(pos):
        count.append("1")
        place_apple()
    else:
        print(f"\nFINAL SCORE: {len(count)} points")
        quit()


def time_up():
    global game_over
    game_over = True


clock.schedule(time_up, 1.0)
place_apple()
pgzrun.go()