0% found this document useful (0 votes)
13 views

Python 3.13 Module Docs (64-bit)

The document outlines a simple Pygame project called 'Milky Moo Adventure', where a player controls a character to collect milk while avoiding obstacles. It includes initialization of Pygame, screen setup, sprite creation for the player and milk, and the game loop that handles events, updates, and rendering. The score is tracked based on the number of milk items collected by the player.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Python 3.13 Module Docs (64-bit)

The document outlines a simple Pygame project called 'Milky Moo Adventure', where a player controls a character to collect milk while avoiding obstacles. It includes initialization of Pygame, screen setup, sprite creation for the player and milk, and the game loop that handles events, updates, and rendering. The score is tracked based on the number of milk items collected by the player.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Server ready at http://localhost:50171/

Server commands: [b]rowser, [q]uit


server> pip install pygame
Server commands: [b]rowser, [q]uit
server> import pygame
Server commands: [b]rowser, [q]uit
server> import random
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> # Inicializa o Pygame
Server commands: [b]rowser, [q]uit
server> pygame.init()
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> # Configuração da tela
Server commands: [b]rowser, [q]uit
server> WIDTH, HEIGHT = 800, 600
Server commands: [b]rowser, [q]uit
server> screen = pygame.display.set_mode((WIDTH, HEIGHT))
Server commands: [b]rowser, [q]uit
server> pygame.display.set_caption("Milky Moo Adventure")
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> # Cores
Server commands: [b]rowser, [q]uit
server> WHITE = (255, 255, 255)
Server commands: [b]rowser, [q]uit
server> GREEN = (0, 255, 0)
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> # FPS
Server commands: [b]rowser, [q]uit
server> clock = pygame.time.Clock()
Server commands: [b]rowser, [q]uit
server> FPS = 60
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> # Variáveis do jogo
Server commands: [b]rowser, [q]uit
server> running = True
Server commands: [b]rowser, [q]uit
server> class MilkyMoo(pygame.sprite.Sprite):
Server commands: [b]rowser, [q]uit
server> def __init__(self):
Server commands: [b]rowser, [q]uit
server> super().__init__()
Server commands: [b]rowser, [q]uit
server> self.image = pygame.image.load("milky_moo.png")
Server commands: [b]rowser, [q]uit
server> self.image = pygame.transform.scale(self.image, (80, 80)) # Ajuste
de tamanho
Server commands: [b]rowser, [q]uit
server> self.rect = self.image.get_rect()
Server commands: [b]rowser, [q]uit
server> self.rect.center = (WIDTH // 4, HEIGHT // 2)
Server commands: [b]rowser, [q]uit
server> self.speed = 5
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> def update(self, keys):
Server commands: [b]rowser, [q]uit
server> if keys[pygame.K_UP] and self.rect.top > 0:
Server commands: [b]rowser, [q]uit
server> self.rect.y -= self.speed
Server commands: [b]rowser, [q]uit
server> if keys[pygame.K_DOWN] and self.rect.bottom < HEIGHT:
Server commands: [b]rowser, [q]uit
server> self.rect.y += self.speed
Server commands: [b]rowser, [q]uit
server> class Milk(pygame.sprite.Sprite):
Server commands: [b]rowser, [q]uit
server> def __init__(self):
Server commands: [b]rowser, [q]uit
server> super().__init__()
Server commands: [b]rowser, [q]uit
server> self.image = pygame.image.load("milk.png")
Server commands: [b]rowser, [q]uit
server> self.image = pygame.transform.scale(self.image, (50, 50)) # Ajuste
de tamanho
Server commands: [b]rowser, [q]uit
server> self.rect = self.image.get_rect()
Server commands: [b]rowser, [q]uit
server> self.rect.x = random.randint(WIDTH, WIDTH + 100)
Server commands: [b]rowser, [q]uit
server> self.rect.y = random.randint(50, HEIGHT - 50)
Server commands: [b]rowser, [q]uit
server> self.speed = random.randint(3, 7)
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> def update(self):
Server commands: [b]rowser, [q]uit
server> self.rect.x -= self.speed
Server commands: [b]rowser, [q]uit
server> if self.rect.right < 0:
Server commands: [b]rowser, [q]uit
server> self.kill()
Server commands: [b]rowser, [q]uit
server> player = MilkyMoo()
Server commands: [b]rowser, [q]uit
server> all_sprites = pygame.sprite.Group()
Server commands: [b]rowser, [q]uit
server> all_sprites.add(player)
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> milk_group = pygame.sprite.Group()
Server commands: [b]rowser, [q]uit
server> score = 0
Server commands: [b]rowser, [q]uit
server> font = pygame.font.Font(None, 36)
Server commands: [b]rowser, [q]uit
server> while running:
Server commands: [b]rowser, [q]uit
server> screen.fill(GREEN) # Cor de fundo
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> for event in pygame.event.get():
Server commands: [b]rowser, [q]uit
server> if event.type == pygame.QUIT:
Server commands: [b]rowser, [q]uit
server> running = False
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> # Controle do jogador
Server commands: [b]rowser, [q]uit
server> keys = pygame.key.get_pressed()
Server commands: [b]rowser, [q]uit
server> player.update(keys)
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> # Gerar leite aleatoriamente
Server commands: [b]rowser, [q]uit
server> if random.randint(1, 40) == 1:
Server commands: [b]rowser, [q]uit
server> milk = Milk()
Server commands: [b]rowser, [q]uit
server> all_sprites.add(milk)
Server commands: [b]rowser, [q]uit
server> milk_group.add(milk)
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> # Atualizar sprites
Server commands: [b]rowser, [q]uit
server> all_sprites.update()
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> # Detectar colisões
Server commands: [b]rowser, [q]uit
server> milk_collected = pygame.sprite.spritecollide(player, milk_group, True)
Server commands: [b]rowser, [q]uit
server> score += len(milk_collected)
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> # Desenhar sprites
Server commands: [b]rowser, [q]uit
server> all_sprites.draw(screen)
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> # Exibir o placar
Server commands: [b]rowser, [q]uit
server> score_text = font.render(f"Score: {score}", True, WHITE)
Server commands: [b]rowser, [q]uit
server> screen.blit(score_text, (10, 10))
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> # Atualizar a tela
Server commands: [b]rowser, [q]uit
server> pygame.display.flip()
Server commands: [b]rowser, [q]uit
server> clock.tick(FPS)
Server commands: [b]rowser, [q]uit
server>
Server commands: [b]rowser, [q]uit
server> pygame.quit()
Server commands: [b]rowser, [q]uit
server> milk_collected = pygame.sprite.spritecollide(player, milk_group, True)
Server commands: [b]rowser, [q]uit
server>

You might also like