Commit 22f5efe7 by BellCodeEditor

save project

parent 5a0c6e2e
Showing with 21 additions and 14 deletions
......@@ -2,6 +2,13 @@ import pygame
from pygame import locals
import random
pygame.init() # 初始化
class Books(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
super().__init__()
self.image=random.choice([image1,image2,image3])
self.rect = self.image.get_rect()
self.rect.x = 1000
self.rect.y = 500 - self.rect.height
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
pygame.display.set_caption("悟空跑酷")
......@@ -17,18 +24,16 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
class Books(pygame.sprite.sprite):
index = 0
y = 400
t = 35
road_x = 0
beijing_x = 0
jump = "running"
rect = cacti.get_rect()
rect.x = 1000
rect.y = 455 - rect.width
obstacle=random.choice([stone,cacti,apple])
#rect = cacti.get_rect()
#rect.x = 1000
#rect.y = 455 - rect.width
obstacle=Books(stone,cacti,apple)
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -52,29 +57,30 @@ while True:
else:
jump = "running"
t = 35
wukong = hero[index]
if jump == "running":
index += 1
if index == 5:
index = 0
# 将背景图画上去
beijing_x -= 4
if beijing_x <= -1000:
beijing_x = 0
screen.blit(background, (beijing_x, 0))
screen.blit(background,(beijing_x, 0))
#路
road_x -= 8
if road_x <= -1000:
road_x = 0
screen.blit(road, (road_x, 500))
screen.blit(wukong, (150, y))
if rect.x < 0-rect.width:
obstacle=random.choice([stone,cacti,apple])
rect = cacti.get_rect()
rect.x = 1000
rect.y = 455 - rect.width
#障碍物
if obstacle.rect.x < 0-obstacle.rect.width:
obstacle = Books(stone,cacti,apple)
else:
rect.x -= 8
screen.blit(obstacle,(rect.x, rect.y))
obstacle.rect.x -= 8
screen.blit(obstacle.image,(obstacle.rect.x, obstacle.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