#coding=utf-8
#接球的小游戏
import pygame
from pygame.locals import *
from sys import exit
import random
basket_x=0
basket_y=600
ball_x=10
ball_y=10
screen_width=1000
screen_heigh=800
score=0
pygame.init()
screen=pygame.display.set_mode((screen_width,screen_heigh))
pygame.display.set_caption('接球')
basket=pygame.image.load('C:/Users/hou/Desktop/lanzi1.png').convert()
basket_w,basket_h=basket.get_size()
ball=pygame.image.load('C:/Users/hou/Desktop/ball1.png').convert()
ball_w,ball_h=ball.get_size()
def update_basket():
global basket_x
global basket_y
basket_x,ignore=pygame.mouse.get_pos() #检测鼠标事件
basket_x=basket_x-basket_w/2
screen.blit(basket,(basket_x,basket_y))
def update_ball():
global ball_x
global ball_y
ball_y+=1
if ball_y+ball_h>basket_y:
ball_y=0
ball_x=random.randint(0,screen_width-ball_w)
ball_x+=random.randint(-
Python pygame 接球的小游戏
最新推荐文章于 2021-08-26 16:17:07 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)