Commit b923cd80 by BellCodeEditor

auto save

parent ed2198d9
Showing with 12 additions and 32 deletions
...@@ -2,16 +2,8 @@ import pygame ...@@ -2,16 +2,8 @@ import pygame
from pygame import locals from pygame import locals
from random import* from random import*
pygame.init() # 初始化
class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
super().__init__()
self.image=random.choice([image1,image2,image3])
self.rect=self,image.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height
pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
...@@ -32,16 +24,12 @@ lu_x=0 ...@@ -32,16 +24,12 @@ lu_x=0
shan_x=0 shan_x=0
index = 0 index = 0
y = 400 y = 400
jumpState = "running" jumpState = "runing"
t = 37 t = 37
#zhangaiwu=choice([bush,cacti,stone])#随机获得一个障碍物 zhangaiwu=choice([bush,cacti,stone])#随机获得一个障碍物
#xingzhuang=zhangaiwu.get_rect()#活得障碍物的坐标,宽,高。 xingzhuang=zhangaiwu.get_rect()#活得障碍物的坐标,宽,高。
#xingzhuang.x=1000#使障碍物的x坐标为1000 xingzhuang.x=1000#使障碍物的x坐标为1000
#xingzhuang.y=500-xingzhuang.height#初始化障碍物的y坐标 xingzhuang.y=500-xingzhuang.height#初始化障碍物的y坐标
block_list=pygame.sprite .Group()
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -82,21 +70,13 @@ while True: ...@@ -82,21 +70,13 @@ while True:
lu_x=0 lu_x=0
screen.blit(road, (lu_x, 500)) # 路 screen.blit(road, (lu_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空 screen.blit(wukong, (150, y)) # 悟空
zhangaiwu=Block(bush,cacti,stone)
block_list.add(zhangaiwu)
#zhangaiwu.x-=8
#if zhangaiwu.x <0-zhangaiwu.width:#如果障碍物的x
# zhangaiwu=choice([bush,cacti,stone])
# zhangaiwu.y=500-zhangaiwu.height#初始化障碍物的y坐标
# zhangaiwu.x=1000#使障碍物的x坐标为1000
#screen.blit(zhangaiwu,(xingzhuang.x,xingzhuang.y))
for sprite in block_list: xingzhuang.x-=8
sprite.rect.x-=8 if xingzhuang.x <0-xingzhuang.width:#如果障碍物的x
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y)) zhangaiwu=choice([bush,cacti,stone])
xingzhuang.y=500-xingzhuang.height#初始化障碍物的y坐标
xingzhuang.x=1000#使障碍物的x坐标为1000
screen.blit(zhangaiwu,(xingzhuang.x,xingzhuang.y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
......
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