Commit cb8730b6 by BellCodeEditor

save project

parent 135e92cc
Showing with 14 additions and 15 deletions
......@@ -2,14 +2,13 @@ import pygame
from pygame import locals
import random
class Jingling(pygame.sprite.Sprite):
class Block(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 = 0
self.rect.y = 400 - self.rect.height
self.image=random.choice([image1,image2,image3])
self.rect=self.image.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height
pygame.init() # 初始化
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
......@@ -26,11 +25,12 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
# shan_x=0
index = 0
y = 400
jumpState = "runing"
t = 30
thing = Jingling(bush,cacti,stone)
things = Block(bush,cacti,stone)
road_x = 0
mountain_x = 0
......@@ -67,24 +67,22 @@ while True:
# 将背景图画上去
mountain_x -= 5
if mountain_x < -1000:
mountain_x = 0 # 远处背景
mountain_x = 0
screen.blit(background, (mountain_x, 0)) # 远处背景
road_x -= 8
if road_x <= -1000:
road_x = 0
screen.blit(road, (road_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空
# thing = Jingling(bush,cacti,stone)
if thing.rect.x <= 0-thing.rect.width:
thing = Jingling(bush,cacti,stone)
# 障碍物消失
if things.rect.x <= 0-things.rect.width: # 障碍物消失
# 创建障碍物对象
thing.rect.x -= 8
things = Block(bush,cacti,stone)
things.rect.x -= 8
screen.blit(thing.image, (thing.rect.x, thing.rect.y))
screen.blit(things.image, (things.rect.x, things.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