From 5ce89d29eeabf4269ddaf84df1366812959dbbc1 Mon Sep 17 00:00:00 2001 From: ndyer Date: Tue, 20 Dec 2022 10:29:19 -0500 Subject: [PATCH] created game screen, added paddle class and two paddles --- pypong/game_files/game.py | 67 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/pypong/game_files/game.py b/pypong/game_files/game.py index 5140621..864c63a 100644 --- a/pypong/game_files/game.py +++ b/pypong/game_files/game.py @@ -1,19 +1,80 @@ import pygame +import pypong -SCREEN_SIZE = (640, 480) # Size of the game window +SCREEN_SIZE = (800, 600) # Size of the game window +GAME_FPS = 30 +GAME_COLOR = (255, 255, 255) # Color of all the sprites on screen +PADDLE_SIZE = (20, 200) -def game(): +class Paddle(pygame.sprite.Sprite): + def __init__(self): + super().__init__() + + self.image = pygame.Surface(PADDLE_SIZE) + self.image.fill(GAME_COLOR) + self.rect = self.image.get_rect() + + def update(self): + pass + + +def game(isHost=True): + """ + Starts the game. + """ + pygame.init() window = pygame.display.set_mode(SCREEN_SIZE) surface = pygame.Surface(SCREEN_SIZE) + # Set title of window + pygame.display.set_caption('PyPong {0}'.format(pypong.__version__)) + + # Add an icon to the pygame window. + # icon = pygame.image.load('NO ICON YET, WIP').convert_alpha() + # pygame.display.set_icon(icon) + + clock = pygame.time.Clock() + + # Default game state when the game first starts. running = True - while running: + # A group of all the sprites on screen. Used to update all sprites at once + all_sprites = pygame.sprite.Group() + + # Functions used for drawing the game screen # + + def draw(): + """ + Draws the main pygame display. + """ + + # Draws all the sprites on a black background + all_sprites.update() + surface.fill((0, 0, 0)) + all_sprites.draw(surface) + window.blit(surface, surface.get_rect()) + + # Update the entire display pygame.display.flip() + # Create the two paddles + host_player = Paddle() + client_player = Paddle() + client_player.rect.x = SCREEN_SIZE[0] - client_player.rect.size[0] # Move client paddle to other side + all_sprites.add(host_player, client_player) + + while running: + clock.tick(GAME_FPS) + draw() + def main(): + """ + Calls the game() function to start the game. + """ game() + + pygame.quit()