Commit f9cff980 by BellCodeEditor

auto save

parent abf08c66
Showing with 12 additions and 17 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random from random import*
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=1000
self.rect.y=500-self.rect.height
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
...@@ -31,8 +25,10 @@ index = 0 ...@@ -31,8 +25,10 @@ index = 0
y = 400 y = 400
jumpState = "runing" jumpState = "runing"
t = 60 t = 60
aa=Block(bush,cacti,stone) zhangaiwu=choice([bush,cacti,stone])#随机获得一个障碍物
xingzhuang=zhangaiwu.get_rect()#活得障碍物的坐标,宽,高。
xingzhuang.x=1000#使障碍物的x坐标为1000
xingzhuang.y=500-xingzhuang.height#初始化障碍物的y坐标
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:
...@@ -74,13 +70,13 @@ while True: ...@@ -74,13 +70,13 @@ while True:
screen.blit(road, (lu_x, 500)) # 路 screen.blit(road, (lu_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空 screen.blit(wukong, (150, y)) # 悟空
if aa.rect.x <= 0-aa.rect.width: # 障碍物消失 xingzhuang.x-=8
# 创建障碍物对象 if xingzhuang.x <0-xingzhuang.width:#如果障碍物的x
aa=Block(bush,cacti,stone) zhangaiwu=choice([bush,cacti,stone])
aa.rect.x -= 8 xingzhuang.y=500-xingzhuang.height#初始化障碍物的y坐标
xingzhuang.x=1000#使障碍物的x坐标为1000
screen.blit(zhangaiwu,(xingzhuang.x,xingzhuang.y))
screen.blit(aa.image, (aa.rect.x, aa.rect.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