pygame_framework
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| pygame_framework [2024/09/18 08:46] – appledog | pygame_framework [2024/09/22 05:38] (current) – appledog | ||
|---|---|---|---|
| Line 238: | Line 238: | ||
| self.sounds = {} | self.sounds = {} | ||
| - | self.sounds[" | + | |
| - | self.sounds[" | + | |
| - | self.sounds[" | + | |
| - | self.sounds[" | + | |
| - | self.sounds[" | + | |
| - | self.sounds[" | + | |
| def play(self, sound): | def play(self, sound): | ||
| Line 250: | Line 250: | ||
| else: | else: | ||
| print(f" | print(f" | ||
| + | </ | ||
| + | |||
| + | == Sprite Objects | ||
| + | If you need it, you can try this: | ||
| + | |||
| + | === A basic square | ||
| + | < | ||
| + | import pygame | ||
| + | import time | ||
| + | from Color import * | ||
| + | from Screen import * | ||
| + | |||
| + | # Define the Player Sprite class | ||
| + | class Player(pygame.sprite.Sprite): | ||
| + | SPEED = 5 | ||
| + | SIZE = 20 | ||
| + | COLOR = Color.WHITE | ||
| + | |||
| + | def __init__(self): | ||
| + | super().__init__() | ||
| + | |||
| + | # Create a surface for the Player | ||
| + | self.image = pygame.Surface((self.SIZE, | ||
| + | |||
| + | # Fill the surface with a color | ||
| + | self.image.fill(self.COLOR) | ||
| + | |||
| + | # Get the rectangle for positioning | ||
| + | self.rect = self.image.get_rect() | ||
| + | |||
| + | # Set the initial position | ||
| + | self.rect.center = (Screen.WIDTH // 2, Screen.HEIGHT // 2) | ||
| + | |||
| + | def update(self): | ||
| + | # Restrict positioning to screen. | ||
| + | if self.rect.x < 0: | ||
| + | self.rect.x = 0 | ||
| + | if self.rect.x > Screen.WIDTH - self.SIZE: | ||
| + | self.rect.x = Screen.WIDTH - self.SIZE | ||
| + | if self.rect.y < 0: | ||
| + | self.rect.y = 0 | ||
| + | if self.rect.y > Screen.HEIGHT - self.SIZE: | ||
| + | self.rect.y = Screen.HEIGHT - self.SIZE | ||
| + | |||
| + | # Easier to read, but, slower. | ||
| + | # | ||
| + | # | ||
| </ | </ | ||
pygame_framework.1726649199.txt.gz · Last modified: 2024/09/18 08:46 by appledog
