首页 > 其他分享 >弹跳球

弹跳球

时间:2022-12-01 22:44:07浏览次数:35  
标签:ball ballrect color pygame 弹跳 speed event

import sys
import pygame
pygame.init()
size = width, height = 640,480
screen = pygame.display.set_mode(size)
color = (0,0,0)
ball = pygame.image.load("th.jpg")
ballrect = ball.get_rect()
speed = [5,5]
clock = pygame.time.Clock()
while True:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
ballrect = ballrect.move(speed)
if ballrect.left <0 or ballrect.right > width:
speed[0] = -speed[1]
if ballrect.top <0 or ballrect.bottom > height:
speed[1] = -speed[1]
screen.fill(color)
screen.blit(ball, ballrect)
pygame.display.flip()
pygame.quit()

标签:ball,ballrect,color,pygame,弹跳,speed,event
From: https://www.cnblogs.com/drewan/p/16943040.html

相关文章

  • python篮球自动弹跳
           具体思路是首先导入sys和pygame模块然后初始化pygame然后显示窗口加载篮球图片执行死循环检查事件设置移动篮球将图片画在窗口上最后更新全部显示......
  • 篮球自动弹跳
    importsysimportpygamepygame.init()size=width,height=640,480screen=pygame.display.set_mode(size)color=(0,0,0)ball=pygame.image.......
  • 第十三章实例1篮球自动弹跳
    #-*-coding:utf-8-*-importsys#导入sys模块importpygame#导入pygame模块pygame.init......
  • 篮球自动弹跳
    #-*-codings:utf-8-*-importsysimportpygamepygame.init()size=width,height=640,480screen=pygame.display.set_mode(size)color=(0,0,0)ball=pygame.imag......
  • 篮球自动弹跳
    importsysimportpygamepygame.init()size=width,height=640,480screen=pygame.display.set_mode(size)color=(0,0,0)ball=pygame.im......
  • 篮球自动弹跳
    (1)创建游戏窗口importsysimportpygamepygame.init()size=width,height=640,480screen=pygame.display.set_mode(size)  (2)让窗口一直显示importsysimportpygamep......
  • 20:球弹跳高度的计算
    描述一球从某一高度落下(整数,单位米),每次落地后反跳回原来高度的一半,再落下。编程计算气球在第10次落地时,共经过多少米?第10次反弹多高?输入输入一个整数h,表示球的初始高......