PynPong/pypong/game_files/game.py

81 lines
1.8 KiB
Python

import pygame
import pypong
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)
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
# 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()