大家好,小编为大家解答python简单小游戏代码200行的问题。很多人还不知道python小游戏代码1000行,现在让我们一起来看看吧!
python制作的赛车小游戏,逆行飙车,通过键盘方向键控制
程序运行截图
源代码
import pygame, sys, time, random
# pygame 初始化
pygame.init()
pygame.display.set_caption('逆行飙车')
# 常量类
class Constant:
# 自定义事件
OUT_OF_SIDE = pygame.USEREVENT + 1 # 碰到边界
SPEED_UP = pygame.USEREVENT + 2 # 速度加快
# 初始分数
SCORE = 0
# 帧数
FPS = 30
# 屏幕
size = width, height = (351, 600)
screen = pygame.display.set_mode(size) # 屏幕surface
screen_rect = screen.get_rect() # 屏幕rect
# 背景图片
street_img = pygame.image.load('AnimatedStreet.png') # 背景surface
street_rect = street_img.get_rect() # 背景rect
# 字体和音乐
font_big = pygame.font.Font('Hellocute.ttf', 60)
font_small = pygame.font.Font('文道甜甜圈.ttf', 20)
font_gam