Commit 5197f94d by BellCodeEditor

auto save

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