Commit 22a0217d by BellCodeEditor

save project

parent 704b27d8
Showing with 14 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))
...@@ -10,8 +10,8 @@ pygame.display.set_caption("燕子没你我怎么活啊!") ...@@ -10,8 +10,8 @@ pygame.display.set_caption("燕子没你我怎么活啊!")
background = pygame.image.load('bg.png') # 背景 background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路 road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头 stone = pygame.image.load('stone.png') # 石头
cacti = pygame.image.load('cacti.png') # 仙人掌 cati = pygame.image.load('cacti.png') # 仙人掌
apple = pygame.image.load('bush.png') # 灌木丛 bush = pygame.image.load('bush.png') # 灌木丛
hero = [pygame.image.load('hero1.png'), hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero2.png'), pygame.image.load('hero2.png'),
pygame.image.load('hero3.png'), pygame.image.load('hero3.png'),
...@@ -23,9 +23,9 @@ y = 400 ...@@ -23,9 +23,9 @@ y = 400
u = 10 u = 10
douzou = "runing" douzou = "runing"
obstacle = random.choice([bush,stone,cati]) obstacle = random.choice([bush,stone,cati])
rext = obstacle.get_ rect = obstacle.get_rect
rext.x = rect.x = 1000
rext.y = 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:
...@@ -47,9 +47,12 @@ while True: ...@@ -47,9 +47,12 @@ while True:
u += 0.2 u += 0.2
else: else:
douzou = "runing" douzou = "runing"
if rect.x <= 0 - rect.width:
obstacle = random.choice([bush,stone,cati])
rect = obstacle.get_rect
rect.x = 1000
rect.y = 500 - height
rect.x -= 8
yee = hero[index] yee = hero[index]
if douzou == "runing": if douzou == "runing":
index += 1 index += 1
...@@ -60,6 +63,7 @@ while True: ...@@ -60,6 +63,7 @@ while True:
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(road, (0, 500)) screen.blit(road, (0, 500))
screen.blit(yee, (150, y)) screen.blit(yee, (150, y))
screen.blit(obstacle,(rect.x,rect.y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(10) FPS.tick(10)
\ 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