Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import pygame
- import sys
- import math
- from random import random
- from pong import Pong
- from pygame.locals import *
- x_vel = random()
- y_vel = (2 - x_vel**2) ** .5
- x = 294
- y = 294
- # Create an instance
- game = Pong()
- # Initalize the game
- pygame.init()
- screen = pygame.display.set_mode((900,600),0,32)
- screen.blit(screen, (0,0))
- pygame.mouse.set_visible(False) # Hide mr. mouse
- beeper = pygame.image.load('paddle.png') # Paddle
- bpaddle = pygame.image.load('blank_paddle.png') # Paddle that is drawn over the green one to ensure "motion"
- ball_img = pygame.image.load('ball.png')
- ball_cover = pygame.image.load('blank_ball.png')
- ball_rect = ball_img.get_rect()
- clock = pygame.time.Clock()
- # Setup the paddle
- paddle_pos = (0,0)
- paddle_rect = beeper.get_rect()
- bounds_rect = pygame.Rect(880,1,0,900)
- while True:
- for event in pygame.event.get():
- if event.type == QUIT:
- sys.exit()
- # Draw the net
- pygame.draw.line(screen, game.lineColor, game.net1, game.net2, game.netWidth)
- # Ball animation
- boundsball_rect = pygame.Rect(x,y,0,0)
- ball_rect.clamp_ip(boundsball_rect)
- x += x_vel
- y += y_vel
- if x<=0 or x>=900: x_vel*=-1
- if y<=0 or y>=600: y_vel*=-1
- screen.blit(ball_img, ball_rect)
- pygame.display.flip()
- clock.tick(20)
- screen.blit(ball_cover, ball_rect)
- # Player paddle animation
- paddle_rect.center = pygame.mouse.get_pos()
- paddle_rect.clamp_ip(bounds_rect)
- screen.blit(beeper, paddle_rect)
- pygame.display.flip()
- screen.blit(bpaddle, paddle_rect)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement