Commit 5197f94d by BellCodeEditor

auto save

parent 90c8e2ed
Showing with 30 additions and 9 deletions
import pygame
import time
import random
from pygame import locals
pygame.init() # 初始化
......@@ -21,6 +21,12 @@ hero = [pygame.image.load('hero1.png'),
y=400
b=0
c="r"
t=30
k=1
z=random.choice([stone,apple,cacti])
rect=z.get_rect()
rect.x=1000
rect.y=500-rect.height
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -28,25 +34,39 @@ while True:
exit()
if event.type == locals.KEYDOWN:
if event.key==locals.K_SPACE:
c="u"
if k==1:
c="u"
k= 0
if c=="u":
if y>150:
y=y-5
if t>0:
y=y-t
t=t-2
else:
c="d"
if c=="d":
if y<400:
y=y+5
if t<32:
y=y+t
t=t+2
else:
c="r"
k=1
t=30
a=hero[b]
b=b+1
if b==5:
b=0
if c=="r":
b=b+1
if b==5:
b=0
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
screen.blit(a, (150, y))
if rect.x<rect.x-z.rect.width:
rect.x=rect.x-8
screen.blit(z, (rect.x,rect.y))
rect.x=rect.x-8
screen.blit(z, (rect.x,rect.y))
# 刷新画面
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