created game screen, added paddle class and two paddles
This commit is contained in:
parent
3b17cdb8b8
commit
5ce89d29ee
@ -1,19 +1,80 @@
|
|||||||
import pygame
|
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()
|
pygame.init()
|
||||||
|
|
||||||
window = pygame.display.set_mode(SCREEN_SIZE)
|
window = pygame.display.set_mode(SCREEN_SIZE)
|
||||||
surface = pygame.Surface(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
|
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()
|
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():
|
def main():
|
||||||
|
"""
|
||||||
|
Calls the game() function to start the game.
|
||||||
|
"""
|
||||||
game()
|
game()
|
||||||
|
|
||||||
|
pygame.quit()
|
||||||
|
Loading…
Reference in New Issue
Block a user