Commit 714e0e86 by BellCodeEditor

auto save

parent 2d9a1e42
Showing with 17 additions and 16 deletions
......@@ -2,6 +2,15 @@ import pygame
from pygame import locals
import random
pygame.init() # 初始化
class Block(pygame.sprite.Sprite): # 继承精灵类
def __init__(self,image1,image2,image3):
super().__init__()
self.image = random.choice([image1,image2,image3]) #random.choice只能循环列表
self.rect = self.image.get_rect()
self.rect.x = 1000
self.rect.y = 500 - self.rect.height
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -21,13 +30,7 @@ jumpState = "runing"
y =400
t = 30
roadx = 0
obstale = random.choice([stone,cacti,apple])
rect = obstale.get_rect() # 获取当前的x,y 宽高
print(rect.height,"ssssssssssssssssssssssss")
rect.x = 1000
rect.y = 500-rect.height
obstacle = Block(stone,cacti,apple)
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -63,16 +66,14 @@ while True:
screen.blit(background, (0, 0))
if roadx<=-1000:
roadx = 0
road.x -=8
screen.blit(road, (road.x, 500))
roadx -=8
screen.blit(road, (roadx, 500))
screen.blit(wukong, (150, y))
if rect.x < 0-rect.width:
obstale = random.choice([stone,cacti,apple])
rect = obstale.get_rect() # 获取当前的x,y 宽高
rect.x = 1000
rect.y = 500-rect.height
rect.x -=8
screen.blit(obstale,(rect.x,rect.y))
if obstacle.rect.x <= 0-obstacle.rect.width:
obstacle = Block(apple,cacti,stone)
obstacle.rect.x -= 8
# ++++++++++++++++++++++
screen.blit(obstacle.image, (obstacle.rect.x, obstacle.rect.y))
......
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