Commit 6f9f7676 by BellCodeEditor

save project

parent 46e93d09
Showing with 15 additions and 8 deletions
...@@ -4,6 +4,16 @@ import random ...@@ -4,6 +4,16 @@ import random
from pygame import locals from pygame import locals
pygame.init() # 初始化 pygame.init() # 初始化
class Block(pygame.sprite.Sprite):
def _init_ (self,image1,image2,image3):
surper()._init_()
self.image = random.choice([image1,image2,image3])
self.rect = image.get_rect()
self.rect.x = 1000
self.rect.y = 500-self.rect.height
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
pygame.display.set_caption('wukongkupao') pygame.display.set_caption('wukongkupao')
...@@ -31,7 +41,7 @@ hero = [pygame.image.load('hero1.png'), ...@@ -31,7 +41,7 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
zhang_ai = random.choice([stone,cacti,bush]) zhang_ai = Block(stone,cacti,bush)
rect = zhang_ai.get_rect() rect = zhang_ai.get_rect()
rect.x=1000 rect.x=1000
rect.y = 500-rect.height rect.y = 500-rect.height
...@@ -84,13 +94,10 @@ while True: ...@@ -84,13 +94,10 @@ while True:
#障碍:随机,移动 #障碍:随机,移动
if rect.x <= 0-rect.width: if zhang_ai.rect.x <= 0-zhang_ai.rect.width:
zhang_ai = random.choice([stone,cacti,bush]) zhang_ai = Block([stone,cacti,bush])
rect = zhang_ai.get_rect() zhang_ai.rect.x -=8
rect.x = 1000 screen.blit(zhang_ai,(zhang_ai.image,zhang_ai.rect.x,zhang_ai.rect.y))
rect.y = 500-rect.height
rect.x -=8
screen.blit(zhang_ai,(rect.x,rect.y))
pygame.display.update()#保存 pygame.display.update()#保存
......
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