python實現(xiàn)小球彈跳效果
更新時間:2019年05月10日 08:33:58 作者:毒_牙
這篇文章主要為大家詳細介紹了python實現(xiàn)小球彈跳效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了python實現(xiàn)小球彈跳效果的具體代碼,供大家參考,具體內(nèi)容如下
import pygame, sys
pygame.init()
screenGameCaption = pygame.display.set_caption("Ball game")
screen = pygame.display.set_mode([680, 480])
screen.fill([255, 255, 255])
x = 50
y = 50
x_speed = 10
y_speed = 10
# load img
my_ball = pygame.image.load('ball.png')
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.time.delay(100)
pygame.draw.rect(screen, [255, 255, 255], [x, y, 190, 190], 0)
x = x + x_speed
y = y + y_speed
if x > screen.get_width() - 190 or x < 0:
x_speed = - x_speed
if y > screen.get_height() - 190 or y < 0:
y_speed = - y_speed
screen.blit(my_ball, [x, y])
pygame.display.flip()
pygame.quit()
效果圖:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Django中ORM找出內(nèi)容不為空的數(shù)據(jù)實例
這篇文章主要介紹了Django中ORM找出內(nèi)容不為空的數(shù)據(jù)實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05
python 實現(xiàn)調(diào)用子文件下的模塊方法
今天小編就為大家分享一篇python 實現(xiàn)調(diào)用子文件下的模塊方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12
pytorch fine-tune 預(yù)訓(xùn)練的模型操作
這篇文章主要介紹了pytorch fine-tune 預(yù)訓(xùn)練的模型操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-06-06

