一、实验目的和要求
学会Pygame的基本应用
二、实验环境
软件版本:Python 3.10 64_bit
三、实验过程
1、实例1:制作一个跳跃的小游戏
(1)代码如下:
# -*- coding:utf-8 -*- 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("D:\保存\微信图片_20221202213655.jpg") ballrect = ball.get_rect() speed = [5,5] while True: for event in pygame.event.get(): if event.type == pygame.QUIT: 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()
运行结果如下:
标签:13,ball,ballrect,screen,编程,pygame,speed,event From: https://www.cnblogs.com/zzxxhqmy/p/16947202.html