Commit 281556ad by BellCodeEditor

save project

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