首页 > 其他分享 >跳跃的球

跳跃的球

时间:2022-12-01 22:00:27浏览次数:35  
标签:ball ballrect screen 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("ball.png")
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[0]
    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,screen,pygame,跳跃,speed,event
From: https://www.cnblogs.com/whc123/p/16942926.html

相关文章

  • 篮球自动跳跃
    importsysimportpygamepygame.init()#初始化pygamesize=width,height=640,640#设置窗口screen=pygame.display.set_mode(size)#显示窗口color=(0,0,......
  • 跳跃的小球
    importpygame,syspygame.init()screenGameCaption=pygame.display.set_caption("Ballgame")screen=pygame.display.set_mode([680,480])screen.fill([255,255,25......
  • python第十三章(篮球的跳跃游戏
    #-*-coding:utf-8-*-importsysimportpygamepygame.init()size=width,height=640,480screen=pygame.display.set_mode(size)color=(0,0,0)ball=pygame.image.load("b......
  • 跳跃小球游戏
     ......
  • 跳跃的小球
     ......
  • 力扣 leetcode 45. 跳跃游戏 II
    问题描述给你一个非负整数数组nums,你最初位于数组的第一个位置。数组中的每个元素代表你在该位置可以跳跃的最大长度。你的目标是使用最少的跳跃次数到达数组的最后一......
  • 为博客添加底部小鱼跳跃特效
    代码如下,往博客园添加的话无需重复引入jquery了,效果如本页面底部特效所示,还是挺好看的:<scriptsrc="https://common.cnblogs.com/scripts/jquery-2.2.0.min.js"></script>......
  • Pygame制作跳跃小球小游戏
    首先创建一个游戏窗口,然后再窗口内创建一个小球。以一定的速度移动小球,当小球碰到游戏窗口的边缘时,小球弹回,继续移动。可以按照如下步骤实现该功能。(1)首先来创建一个游戏窗......
  • 45. 跳跃游戏 II
    给你一个非负整数数组nums,你最初位于数组的第一个位置。数组中的每个元素代表你在该位置可以跳跃的最大长度。你的目标是使用最少的跳跃次数到达数组的最后一个位置。......
  • #yyds干货盘点# 动态规划专题:跳跃游戏(二)
    1.简述:描述给定一个非负整数数组nums,假定最开始处于下标为0的位置,数组里面的每个元素代表下一跳能够跳跃的最大长度,如果可以跳到数组最后一个位置,请你求出跳跃路径中所能获......