Commit a69d474b by BellCodeEditor

save project

parent 7ea0e575
Showing with 61 additions and 44 deletions
......@@ -3,6 +3,7 @@ from pygame import locals
import random
pygame.init() # 初始化
class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
super().__init__()
......@@ -11,6 +12,14 @@ class Block(pygame.sprite.Sprite):
self.rect.x = 1000
self.rect.y = 500 - self.rect.height
self.score = 1
class Player(pygame.sprite.Sprite):
def __init__ (self,img):
super().__init__()
self.img=img
self.rect=self.img.get_rect()
self.rect.x=150
self.rect.y=400
#obstacle=Block(importpygame)
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
......@@ -35,9 +44,8 @@ t = 30
# rect = obstacle.get_rect()
# rect.x = 1000
# rect.y = 500 - rect.height
obstacle = Block(bush,stone,cacti)
pygame
time = 0
status=True
list=pygame.sprite.Group()
while True:
for event in pygame.event.get():
......@@ -49,51 +57,60 @@ while True:
if event.key == locals.K_SPACE:
jumpState = "up"
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
t -= 2
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
t += 2
else:
jumpState = "runing"
t =30
# 悟空造型
wukong = hero[index]
# 悟空造型
wukong =Player( hero[index])
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去
screen.blit(background, (0, 0)) # 远处背景
screen.blit(road, (0, 500)) # 路
screen.blit(wukong, (150, y))
if time>=60:
time=0
num = random.randint(0,50)
if num >20:
obstacle=Block(bush,carti,stone)
block.list.add(obstacle)
if status==True:
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
wukong.rect.y=y
t -= 2
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
wukong.rect.y=y
t += 2
else:
jumpState = "runing"
t =30
# 将背景图画上去
screen.blit(background, (0, 0)) # 远处背景
screen.blit(road, (0, 500)) # 路
screen.blit(wukong.img, (150, y))
time+=1
if time>=60:
time=0
num = random.randint(0,50)
if num >20:
obstacle=Block(bush,cacti,stone)
list.add(obstacle)
for sprite in list:
sprite.rect.x-=8
screen.blit(sprite.image(sprite.rcet.x.sprite.rect.y))
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x<=0-sprite.rect.width:
sprite.skill()
# if rect.x <= 0-rect.width: # 障碍物消失
# # 创建障碍物对象
# obstacle = random.choice([bush,stone,cacti])
# rect = obstacle.get_rect()
# rect.x = 1000
# rect.y = 500 - rect.height
# rect.x -= 8
# screen.blit(obstacle, (rect.x, rect.y))
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
sprite.kill()
if pygame.sprite.collide_rect(wukong,sprite):
gameover = pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
status = False
# if rect.x <= 0-rect.width: # 障碍物消失
# # 创建障碍物对象
# obstacle = random.choice([bush,stone,cacti])
# rect = obstacle.get_rect()
# rect.x = 1000
# rect.y = 500 - rect.height
# rect.x -= 8
# screen.blit(obstacle, (rect.x, rect.y))
# 刷新画面
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