Commit c779e0eb by BellCodeEditor

save project

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