I am making a pong game and am putting it together a piece at a time. Right now I am working on a simple bouncy ball. I can make it move, but it wont bounce back. Basically I don't know how to set up walls . Here is my code:
Code:
#!/usr/bin/python
import pygame
import sys
from pygame.locals import *
x_vel = 1
y_vel = 1
x = 1
y = 1
pygame.init()
screen = pygame.display.set_mode((600,600),0,32)
screen.blit(screen, (0,0))
ball_img = pygame.image.load('ball.png')
ball_cover = pygame.image.load('blank_ball.png')
clock = pygame.time.Clock()
ball_rect = ball_img.get_rect()
while True:
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
bounds_rect = pygame.Rect(x,y,0,0)
ball_rect.clamp_ip(bounds_rect)
x += x_vel
y += y_vel
screen.blit(ball_img, ball_rect)
pygame.display.update()
clock.tick(50)
screen.blit(ball_cover, ball_rect)
Bookmarks