前言
嗨喽,大家好呀~这里是爱看美女的茜茜呐
天天酷跑是一款轻松好玩、简单时尚的跑酷类手机游戏。
那我们能不能用python模拟出这个一个游戏呢?
答案当然是可以的,今天我就给大家带来简易版的天天酷跑小游戏
开发环境:
-
版 本: python 3.8
-
编辑器:pycharm 2021.2
准备事宜
音乐准备:
字体准备:
图片准备:
代码展示
import pygame,sys
import random
游戏配置
width = 1200 #窗口宽度
height = 508 #窗口高度
size = width, height
score=None #分数
myFont=myFont1=None #字体
surObject=None #障碍物图片
surGameOver=None #游戏结束图片
bg=None #背景对象
role=None #人物对象
object=None #障碍物对象
objectList=[] #障碍物对象数组
clock=None #时钟
gameState=None #游戏状态(0,1)表示(游戏中,游戏结束)
人物
class Role:
def __init__(self,surface=None,y=None):
self.surface=surface
self.y=y
self.w=(surface.get_width())/12
self.h=surface.get_height()/2
self.currentFrame=-1
self.state=0 #0代表跑步状态,1代表跳跃状态,2代表连续跳跃
self.g=1 #重力加速度
self.vy=0 #y轴速度
self.vy_start=-20 #起跳开始速度
def getRect(self):
return (0,self.y+12,self.w,self.h)
障碍物
class Object:
def __init__(self,surface,x=0,y=0):
self.surface=surface
self.x=x
self.y=y
self.w=surface.get_width()
self.h=surface.get_height()
self.currentFrame=random.randint(