Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > Python

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-16-2013, 02:28 AM   PM User | #1
Ceil
New to the CF scene

 
Join Date: Mar 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Ceil is an unknown quantity at this point
Bouncy ball

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)
Ceil is offline   Reply With Quote
Reply

Bookmarks

Tags
pygame

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:13 PM.


Advertisement
Log in to turn off these ads.