Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

ball bounce in pygame

# How to make a ball bounce in pygame
# make sure you have pygame installed

import os
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
import sys, pygame
from pygame.locals import *
pygame.init()

speed = [1, 1]
color = (255, 250, 250)
width = 550
height = 300

screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Pygame bouncing ball")

ball = pygame.image.load("ball.png")
rect_boundry = ball.get_rect()

while 1:
    for event in pygame.event.get():
        rect_boundry = rect_boundry.move(speed)
        if rect_boundry.left < 0 or rect_boundry.right > width:
            speed[0] = -speed[0]
        if rect_boundry.top < 0 or rect_boundry.bottom > height:
            speed[1] = -speed[1]

        screen.fill(color)
        screen.blit(ball, rect_boundry)
        pygame.display.flip()

        if event.type == QUIT:
            pygame.quit()
            sys.exit()
Comment

PREVIOUS NEXT
Code Example
Python :: python writelines newline 
Python :: python save .mat 
Python :: python how to get alphabet 
Python :: import python module from another directory 
Python :: calculate root mean square error python 
Python :: python poner en mayusculas 
Python :: migrate using other database django 
Python :: python armstrong number 
Python :: from time import sleep, time 
Python :: finding if user input is lower or upper in python 
Python :: union df pandas 
Python :: convert series to datetime 
Python :: how to Take Matrix input from user in Python 
Python :: python get name of tkinter frame 
Python :: convert string representation of a list to list 
Python :: replace url with text python 
Python :: fastest sort python 
Python :: SafeERC20: low-level call failed 
Python :: Resource punkt not found. Please use the NLTK Downloader to obtain the resource: 
Python :: A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable. 
Python :: import pyttsx3 
Python :: how to get rid of all null values in array python 
Python :: download kaggle dataset in colab 
Python :: how to run a function in interval in python 
Python :: discordpy 
Python :: tkinter gui grid and frame 
Python :: cosine interpolation 
Python :: generate all parameters combination python 
Python :: how to delete records in pandas before a certain date 
Python :: label encode one column pandas 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =