Commit 26ec9eb7 by BellCodeEditor

save project

parent 018270b6
Showing with 16 additions and 1 deletions
...@@ -9,8 +9,16 @@ class Block(pygame.sprite.Sprite): ...@@ -9,8 +9,16 @@ class Block(pygame.sprite.Sprite):
self.rect=self.image.get_rect() self.rect=self.image.get_rect()
self.rect.x=1000 self.rect.x=1000
self.rect.y=500-self.rect.height self.rect.y=500-self.rect.height
class p(pygame.sprite.Sprite):
def __init__(self,image):
super().__init__()
self.image=image
self.rect=self.image.get_rect()
self.rect.x=150
self.rect.y=400
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
gs=True
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption("悟空酷跑") pygame.display.set_caption("悟空酷跑")
...@@ -43,16 +51,18 @@ while True: ...@@ -43,16 +51,18 @@ while True:
if jumpState == "runing": if jumpState == "runing":
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
if gs==True:
if jumpState == "up": # 起跳状态 if jumpState == "up": # 起跳状态
if t > 0: if t > 0:
y -= t y -= t
p.image.rect.y=y
t -= 2 t -= 2
else: else:
jumpState = "down" jumpState = "down"
if jumpState == "down": # 降落状态 if jumpState == "down": # 降落状态
if t <= 30: if t <= 30:
y += t y += t
p.image.rect.y=y
t += 2 t += 2
else: else:
jumpState = "runing" jumpState = "runing"
...@@ -90,6 +100,10 @@ while True: ...@@ -90,6 +100,10 @@ while True:
screen.blit(prep.image, (prep.rect.x, prep.rect.y)) screen.blit(prep.image, (prep.rect.x, prep.rect.y))
if prep.rect.x<=0-prep.rect.width: if prep.rect.x<=0-prep.rect.width:
prep.kill() prep.kill()
if pygame.sprite.collide_rect(wukong,prep):
o=pygame.image.load("gamemover.png")
screen.blit(gameover(500,300))
gs=False
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(50) FPS.tick(50)
\ 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