From 6f9f7676906c02113ae556943b322d9980094903 Mon Sep 17 00:00:00 2001
From: BellCodeEditor <bellcode_dev@bell.ai>
Date: Sat, 28 May 2022 14:37:34 +0800
Subject: [PATCH] save project

---
 my_game.py | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/my_game.py b/my_game.py
index b72212f..b58f5ab 100644
--- a/my_game.py
+++ b/my_game.py
@@ -4,6 +4,16 @@ import random
 from pygame import locals
 
 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))
 pygame.display.set_caption('wukongkupao')
@@ -31,7 +41,7 @@ hero = [pygame.image.load('hero1.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.x=1000
 rect.y = 500-rect.height
@@ -84,13 +94,10 @@ while True:                                                                     
 
 
     #障碍:随机,移动
-    if  rect.x <= 0-rect.width:
-        zhang_ai = random.choice([stone,cacti,bush])
-        rect = zhang_ai.get_rect()
-        rect.x = 1000
-        rect.y = 500-rect.height
-    rect.x -=8
-    screen.blit(zhang_ai,(rect.x,rect.y))
+    if  zhang_ai.rect.x <= 0-zhang_ai.rect.width:
+        zhang_ai = Block([stone,cacti,bush])
+    zhang_ai.rect.x -=8
+    screen.blit(zhang_ai,(zhang_ai.image,zhang_ai.rect.x,zhang_ai.rect.y))
 
 
     pygame.display.update()#保存
--
libgit2 0.25.0