Commit 848dbcb9 by BellCodeEditor

save project

parent 27613fb0
Showing with 23 additions and 3 deletions
import pygame
from pygame import locals
import random
bianliang=0
pygame.init() # 初始化
class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
......@@ -9,6 +10,8 @@ class Block(pygame.sprite.Sprite):
self.rect = self.image.get_rect()
self.rect.x = 1000
self.rect.y = 500 - self.rect.height
self.bianliang=1
self.rect.width=10
class Player(pygame.sprite.Sprite):
def __init__(self,image):
super().__init__()
......@@ -16,12 +19,13 @@ class Player(pygame.sprite.Sprite):
self.rect = self.image.get_rect()
self.rect.x = 150
self.rect.y = 400
self.rect.width=30
self.rect.width=0
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption("sha13游戏")
# 载入图片
score_audio=pygame.mixer.Sound('score.wav')
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头
......@@ -32,6 +36,8 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
basic_font=pygame.font.Font('STKAITI.TTF',18)
score_audio.play()
index = 0
y = 400
jumpState = "runing"
......@@ -39,8 +45,10 @@ t = 30
block_list=pygame.sprite.Group()
lu=0
beijing=0
old_bianliang=0
time=0
panduan=True
speed=8
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -50,6 +58,7 @@ while True:
if jumpState == "runing":
if event.key == locals.K_SPACE:
jumpState = "up"
speed=8+bianliang//3
wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下
index += 1
......@@ -90,13 +99,23 @@ while True:
obstacle = Block(bush,cacti,stone)
block_list.add(obstacle)
for prop in block_list:
prop.rect.x-=8
prop.rect.x-=speed
screen.blit(prop.image,(prop.rect.x,prop.rect.y))
if prop.rect.x<0-prop.rect.width:
prop.kill() # 刷新画面
prop.kill()
# 刷新画面
if pygame.sprite.collide_rect(wukong,prop):
gameover=pygame.image.load("gameover.png")
screen.blit(gameover,(400,200))
panduan=False
else:
if (prop.rect.x+prop.rect.width)<wukong.rect.x:
bianliang+=prop.bianliang
prop.bianliang=0
if bianliang>old_bianliang:
score_audio.play()
old_bianliang=bianliang
sconreSurf=basic_font.render("分数:"+str(bianliang),True,(255,255,255))
screen.blit(sconreSurf,(880,20))
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment