一、安装pygame
详见pygame安装-Requirement already satisfied问题_Kiraxqc的博客-CSDN博客
二、熟悉pygame命令操作
import pygame # 导入模块 pygame.init() # 初始化 # 游戏代码编写 print("游戏代码") pygame.quit() # 卸载所有pygame模块,game over的时候
1. 坐标系
背景左上角为(0,0),游戏为多个静止图片组成,需要确定具体坐标系位置
pygame提供一个类pygame.Rect用于描述矩形区域
Rect (x, y, width, height): (x轴位置,y轴位置,图片宽度,图片高度)
import pygame hero_rect = pygame.Rect(100, 500, 120, 125) print("原点 %d %d" % (hero_rect.x, hero_rect.y)) print("尺寸 %d %d" % (hero_rect.width, hero_rect.height)) print(