Commit a511dcc5 by BellCodeEditor

save project

parent e70a9ab4
Showing with 31 additions and 7 deletions
...@@ -2,6 +2,22 @@ import pygame ...@@ -2,6 +2,22 @@ import pygame
from pygame import locals from pygame import locals
import random import random
class Player(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
gamemode=True
class Gge(pygame.sprite.Sprite): class Gge(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3): def __init__(self,image1,image2,image3):
super().__init__() super().__init__()
...@@ -46,31 +62,35 @@ while True: ...@@ -46,31 +62,35 @@ while True:
if jumpState == "runing": if jumpState == "runing":
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
# 悟空造型
wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
if gamemode == True:
if jumpState == "up": # 起跳状态 if jumpState == "up": # 起跳状态
if t > 0: if t > 0:
y -= t y -= t
wukong.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
wukong.rect.y = y
t += 2 t += 2
else: else:
jumpState = "runing" jumpState = "runing"
t =30 t =30
# 悟空造型
wukong = hero[index]
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (beside_x, 0)) # 远处背景 screen.blit(background, (beside_x, 0)) # 远处背景
screen.blit(road, (road_x, 500)) # 路 screen.blit(road, (road_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空 screen.blit(wukong.image, (150, y)) # 悟空
beside_x-=3 beside_x-=3
road_x-=8 road_x-=8
...@@ -93,6 +113,10 @@ while True: ...@@ -93,6 +113,10 @@ while True:
if sprite.rect.x<=0-sprite.rect.width: if sprite.rect.x<=0-sprite.rect.width:
sprite.kill() sprite.kill()
if pygame.sprite.collide_rect(wukong,sprite):
gameover=pygame.image.load("gameover.png")
screen.blit(gameover,(400,200))
gamemode = False
......
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