Commit 582e005b by BellCodeEditor

save project

parent eddc54b8
Showing with 30 additions and 9 deletions
import turtle # 和你的小伙伴用列表讲讲桃园结义的故事,并说说这其中运用了哪些列表知识:
pen=turtle.Pen() # 来,我给你起个头~
pen.write("诺依, turtle真好用, 我会在画布上写字啦!"font=("Times",30,"normal")) # 从前啊,有三个bro,分别是:刘备、关羽、张飞...
turtle.done() bro1="关羽"
\ No newline at end of file bro2="刘备"
bro3="张飞"
bros=["刘备","关羽","张飞"]
bro1=["关羽",160,8.5]
bro2=["刘备",161,9.1]
bro3=["张飞",166,8.3]
bros[0]="关羽"
bros[1]="刘备"
print(bros)
\ No newline at end of file
...@@ -11,7 +11,13 @@ class Block(pygame.sprite.Sprite): ...@@ -11,7 +11,13 @@ 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 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
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
...@@ -35,6 +41,7 @@ t = 30 ...@@ -35,6 +41,7 @@ t = 30
bg_x = 0 bg_x = 0
road_x = 0 road_x = 0
time=0 time=0
gamestate=True
# +++++++++++++++++++++++ # +++++++++++++++++++++++
#obstacle = Block(bush, stone, cacti) #obstacle = Block(bush, stone, cacti)
block_list=pygame.sprite.Group() block_list=pygame.sprite.Group()
...@@ -47,7 +54,7 @@ while True: ...@@ -47,7 +54,7 @@ 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 gamestate==True
if jumpState == "up": # 起跳状态 if jumpState == "up": # 起跳状态
if t > 0: if t > 0:
y -= t y -= t
...@@ -63,7 +70,7 @@ while True: ...@@ -63,7 +70,7 @@ while True:
t =30 t =30
# 悟空造型 # 悟空造型
wukong = hero[index] wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下 if jumpState == "runing": # 跑步状态下
index += 1 index += 1
if index >= 5: if index >= 5:
...@@ -79,7 +86,7 @@ while True: ...@@ -79,7 +86,7 @@ while True:
road_x = 0 road_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)) # 悟空
time+=1 time+=1
if time >=60: if time >=60:
time=0 time=0
...@@ -92,6 +99,10 @@ while True: ...@@ -92,6 +99,10 @@ while True:
screen.blit(sprite.image, (sprite.rect.x, sprite.rect.y)) screen.blit(sprite.image, (sprite.rect.x, sprite.rect.y))
if sprite.rect.x <= 0-sprite.rect.x: if sprite.rect.x <= 0-sprite.rect.x:
sprite.kill() sprite.kill()
if pygame.sprite.collide_rect(wukong,sprite):
gameover=pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
gameover=False
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(30) FPS.tick(30)
\ 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