首页 > 其他分享 >弹跳小球

弹跳小球

时间:2022-12-01 23:11:18浏览次数:38  
标签:ball ballrect image 小球 pygame 弹跳 speed event

弹跳小球

import sys

import pygame

pygame.init() #初始化pygame

size = width,height = 640,480 #设置窗口大小

screen = pygame.display.set_mode(size)#显示窗口

color = (0,0,0)

ball = pygame.image.load('ball.png')

image = pygame.transform.scale(ball,(100,100))

ballrect = ball.get_rect()

speed=[500,500]#x,y轴

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[0]

if ballrect.top < 0 or ballrect.bottom > height:

speed[1] = -speed[1]

screen.fill(color)#颜色

screen.blit(image,ballrect)#将图片滑到窗口

pygame.display.flip()#更新全部显示

pygame.quit()

标签:ball,ballrect,image,小球,pygame,弹跳,speed,event
From: https://www.cnblogs.com/zyyyywzsyx/p/16943090.html

相关文章

  • Python第十三章小球移动游戏
    #-*-coding:utf-8-*-importsys#导入sys模块importpygame#导入pygame模块pygame.init()#初始化pygamesize=width,height=640,480#设置窗口screen=pyga......
  • 跳动小球
    importsysimportpygamepygame.init()size=width,height=640,480screen=pygame.display.set_mode(size)color=(0,0,0)ball=pygame.image.load("th.jpg......
  • 弹跳球
    importsysimportpygamepygame.init()size=width,height=640,480screen=pygame.display.set_mode(size)color=(0,0,0)ball=pygame.image.load("th.jpg")bal......
  • 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......
  • 跳跃的小球
    importpygame,syspygame.init()screenGameCaption=pygame.display.set_caption("Ballgame")screen=pygame.display.set_mode([680,480])screen.fill([255,255,25......
  • 篮球自动弹跳
    (1)创建游戏窗口importsysimportpygamepygame.init()size=width,height=640,480screen=pygame.display.set_mode(size)  (2)让窗口一直显示importsysimportpygamep......