Commit 2a1a4a20 by BellCodeEditor

save project

parent 0945c955
Showing with 30 additions and 7 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
...@@ -13,6 +13,13 @@ road = pygame.image.load('road.png') # 路 ...@@ -13,6 +13,13 @@ road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头 stone = pygame.image.load('stone.png') # 石头
cacti = pygame.image.load('cacti.png') # 仙人掌 cacti = pygame.image.load('cacti.png') # 仙人掌
apple = pygame.image.load('bush.png') # 灌木丛 apple = pygame.image.load('bush.png') # 灌木丛
z=random.choice([stone,cacti,apple])
rect=z.get_rect()
rect.x=1000
rect.y=500-rect.width
if rect.x<=0-rect.width:
z=ramdom.choue([stone,cacti,applee])
rect=z.get_rect()
hero=[pygame.image.load('hero1.png'), hero=[pygame.image.load('hero1.png'),
...@@ -25,6 +32,7 @@ hero=[pygame.image.load('hero1.png'), ...@@ -25,6 +32,7 @@ hero=[pygame.image.load('hero1.png'),
m = 0 m = 0
jumpstate="runing" jumpstate="runing"
y=400 y=400
t=30
while True: while True:
hero1=hero[m] hero1=hero[m]
...@@ -43,15 +51,28 @@ while True: ...@@ -43,15 +51,28 @@ while True:
exit() exit()
if jumpstate=="up": if jumpstate=="up":
if y>150: if t>0:
y=y-5 y-=t
t-=2
else: else:
jumpstate="down" jumpstate = "down"
if jumpstate=="down": print (t)
if y<400: print(jumpstate)
y=y+5 if jumpstate =="down":
if t<=30:
y = y+t
t = t+2
else: else:
jumpstate="runing" jumpstate="runing"
t=30
rect=z.get_rect()
rect.x=1000
rect.y=500-rect.width
if rect.x<=0-rect.width:
z=ramdom.choue([stone,cacti,applee])
rect=z.get_rect()
...@@ -59,6 +80,7 @@ while True: ...@@ -59,6 +80,7 @@ while True:
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(road, (0, 500)) screen.blit(road, (0, 500))
screen.blit(hero1, (150, y)) screen.blit(hero1, (150, y))
screen.blit(z,(rect.x,rect.y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(60)
\ 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