Commit 281556ad by BellCodeEditor

save project

parent 393c607d
Showing with 19 additions and 9 deletions
import pygame
from pygame import locals
import random
pygame.init() # 初始化
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock()
......@@ -20,15 +20,18 @@ a = 0
y=400
c="runing"
t=30
d=random.choice([stone,apple,cacti])
rect=d.get_rect()
rect.x=1000
rect.y=500-rect.height
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN:
if c=="runing":
if event.key == locals.K_SPACE:
c="up"
if event.key == locals.K_SPACE:
c="up"
if c=="up":
if t > 0:
y-=t
......@@ -44,15 +47,21 @@ while True:
t=30
b=hero[a]
if c=="runing":
a+=1
if a==5:
a=0
a+=1
if a==5:
a=0
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
screen.blit(b, (150, y))
# 刷新画面
if rect.x <0-rect.width:
d=random.choice([stone,apple,cacti])
rest=d.get_rect()
rect.x=1000
rect.y=500-rect.height
rect.x-=8
screen.blit(d,(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