Commit 464914e7 by BellCodeEditor

save project

parent 78e0bcf2
Showing with 27 additions and 6 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
filelist=" " filelist=" "
pygame.init() # 初始化 pygame.init() # 初始化
...@@ -18,10 +20,22 @@ hero = [pygame.image.load('hero1.png'), ...@@ -18,10 +20,22 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero4.png'), pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
index = 0 index = 0
backx=0
y=400 y=400
sd=0 sd=0
nb="runing" nb="running"
stone_x=1000
nm=random.choice([apple,stone,cacti])
rect=nm.get_rect()
rect.x=1000
rect.y=500-rect.height
while True: while True:
if rect.x<0-rect.width:
nm=random.choice([apple,stone,cacti])
rect=nm.get_rect()
rect.x=1000
rect.y=500-rect.height
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
...@@ -46,14 +60,20 @@ while True: ...@@ -46,14 +60,20 @@ while True:
nb="running" nb="running"
y=400 y=400
sd=sd+1
if sd>=5: sb=hero[sd]
sd=0 if nb=="running":
sb=hero[sd] sd+=1
if sd>=5:
sd=0
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (backx, 0))
screen.blit(road, (0, 500)) screen.blit(road, (0, 500))
screen.blit(sb, (150, y)) screen.blit(sb, (150, y))
rect.x-=5
screen.blit(nm,(rect.x,rect.y))
pygame.display.set_caption("悟空酷跑")# 刷新画面 pygame.display.set_caption("悟空酷跑")# 刷新画面
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