Commit c779e0eb by BellCodeEditor

save project

parent 212ace8d
Showing with 18 additions and 2 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
...@@ -13,6 +14,12 @@ cacti = pygame.image.load('cacti.png') # 仙人掌 ...@@ -13,6 +14,12 @@ cacti = pygame.image.load('cacti.png') # 仙人掌
apple = pygame.image.load('bush.png') # 灌木丛 apple = pygame.image.load('bush.png') # 灌木丛
hero = pygame.image.load('hero1.png') hero = pygame.image.load('hero1.png')
list=['hero1.png','hero2.png','hero3.png','hero4.png','hero5.png'] list=['hero1.png','hero2.png','hero3.png','hero4.png','hero5.png']
#l=[stone,cacti,apple]
ob=random.choice([stone,cacti,apple])
rect=ob.get_rect()
rect.x=1000
rect.y=500-rect.height
c=0
b="run" b="run"
t=30 t=30
i=0 i=0
...@@ -30,20 +37,22 @@ while True: ...@@ -30,20 +37,22 @@ while True:
if y > 150: if y > 150:
if t > 0: if t > 0:
y-=t y-=t
t-=1 t-=0.6
else: else:
b='down' b='down'
if b == 'down': if b == 'down':
if y < 400: if y < 400:
if t <= 30 : if t <= 30 :
y+=t y+=t
t+=1 t+=0.6
else: else:
b='run' b='run'
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(road, (0, 500)) screen.blit(road, (0, 500))
if rect.x > 0-rect.width:
screen.blit(ob,(rect.x,rect.y))
screen.blit(hero, (150, y)) screen.blit(hero, (150, y))
if b == 'run': if b == 'run':
i+=1 i+=1
...@@ -52,6 +61,12 @@ while True: ...@@ -52,6 +61,12 @@ while True:
if i == 4: if i == 4:
i=0 i=0
t=30 t=30
rect.x-=5
if rect.x<=0-rect.width:
ob=random.choice([stone,cacti,apple])
rect=ob.get_rect()
rect.x=1000
rect.y=500-rect.height
# 刷新画面 # 刷新画面
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