Commit 5fcf0105 by BellCodeEditor

save project

parent 9258f1c7
Showing with 45 additions and 15 deletions
...@@ -3,6 +3,13 @@ from pygame import locals ...@@ -3,6 +3,13 @@ from pygame import locals
import random import random
pygame.init() # 初始化 pygame.init() # 初始化
class JIANCE(pygame.sprite.Sprite):
def __init__(self,image,image2,image3):
super().__init__()
self.image = random.choice([image,image2,image3])
self.rect = self.image.get_rect()
self.rect.x = 1000
self.rect.y = 500 - self.rect.height
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
...@@ -22,12 +29,16 @@ lux = 0 ...@@ -22,12 +29,16 @@ lux = 0
jinx = 0 jinx = 0
index = 0 index = 0
y = 400 y = 400
time = 0
jumpState = "runing" jumpState = "runing"
t = 30 t = 30
obstacle = random.choice([bush, stone, cacti]) sudu = 100
rect = obstacle.get_rect() fenshu = 0
rect.x = 1000 #obstacle = random.choice([bush, stone, cacti])
rect.y = 500 - rect.height # rect = obstacle.get_rect()
# rect.x = 1000
# rect.y = 500 - rect.height
abc = pygame.sprite.Group()
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -61,27 +72,46 @@ while True: ...@@ -61,27 +72,46 @@ while True:
index = 0 index = 0
if rect.x <= 0-rect.width: # 障碍物消失 # if rect.x <= 0-rect.width: # 障碍物消失
# 创建障碍物对象 # # 创建障碍物对象
obstacle = random.choice([bush,stone,cacti]) # obstacle = random.choice([bush,stone,cacti])
rect = obstacle.get_rect() # rect = obstacle.get_rect()
rect.x = 1000 # rect.x = 1000
rect.y = 500 - rect.height # rect.y = 500 - rect.height
rect.x -= 8 # rect.x -= 8
jinx -= 2 jinx -= 2
if jinx <= -1000: if jinx <= -1000:
jinx = 0 jinx = 0
screen.blit(background,(jinx,0)) screen.blit(background,(jinx,0))
lux -= 8 lux -= sudu
if lux <= -1000: if lux <= -1000:
lux = 0 lux = 0
screen.blit(road,(lux,500)) screen.blit(road,(lux,500))
screen.blit(obstacle, (rect.x, rect.y))
# 将背景图画上去 # 将背景图画上去
screen.blit(wukong, (150, y)) # 悟空 screen.blit(wukong, (150, y)) # 悟空
time += 1
if time >= 0:
timetime = random.randint(0,0)
if timetime >= 0:
zhangaiwu = JIANCE(bush, stone, cacti)
abc.add(zhangaiwu)
sudu += 0.5
fenshu += 1
print("当前分数为:"+str(fenshu))
time = 0
for sprite in abc:
sprite.rect.x -= sudu
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sudu >= 1000:
sudu = 900
if sprite.rect.x <= 0 - sprite.rect.width:
sprite.kill()
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(45) FPS.tick(99999999999999999)
\ No newline at end of file \ 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