Commit 42119789 by BellCodeEditor

save project

parent c0cf0460
Showing with 16 additions and 1 deletions
import pygame import pygame
import random
from pygame import locals from pygame import locals
y=400 y=400
pygame.init() # 初始化 pygame.init() # 初始化
...@@ -12,7 +13,11 @@ stone = pygame.image.load('stone.png') # 石头 ...@@ -12,7 +13,11 @@ stone = pygame.image.load('stone.png') # 石头
cacti = pygame.image.load('cacti.png') # 仙人掌 cacti = pygame.image.load('cacti.png') # 仙人掌
apple = pygame.image.load('bush.png') # 灌木丛 apple = pygame.image.load('bush.png') # 灌木丛
hero = [pygame.image.load('hero1.png'),pygame.image.load('hero2.png'),pygame.image.load('hero3.png'),pygame.image.load('hero4.png'),pygame.image.load('hero5.png')] hero = [pygame.image.load('hero1.png'),pygame.image.load('hero2.png'),pygame.image.load('hero3.png'),pygame.image.load('hero4.png'),pygame.image.load('hero5.png')]
index = 0 index = 0
stones=random.choice([stone ,cacti,apple ])
rect=stones.get_rect()
stones_x=1000;
stones_y=500-rect[3]
speed=30 speed=30
sport="running" sport="running"
pygame.display.set_caption("悟空酷跑") pygame.display.set_caption("悟空酷跑")
...@@ -43,10 +48,19 @@ while True: ...@@ -43,10 +48,19 @@ while True:
index+=1 index+=1
if index >=len(hero): if index >=len(hero):
index=0 index=0
if stones_x+rect[2]< 0:
stones=random.choice([stone ,cacti,apple ])
rect=stones.get_rect()
stones_x=1000;
stones_y=500-rect[3]
else:
stones_x -= 2
rect = stones.get_rect()
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(road, (0, 500)) screen.blit(road, (0, 500))
screen.blit(hero[index], (150, y)) screen.blit(hero[index], (150, y))
screen.blit(stones,(stones_x,stones_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