@@ -107,13 +107,17 @@ def update(self):
107107 # 地面にいるか、空中で1回目のジャンプができるか
108108 if self .dy == 10 and not self .is_falling :
109109 # 地面からのジャンプ
110- self .dy = - 6
110+ self .dy = - 8
111111 self .jump_count = 1
112112 elif self .jump_count < 2 and self .dy > 0 :
113113 # 空中での二段飛び
114- self .dy = - 6
114+ self .dy = - 4
115115 self .jump_count += 1
116116 else :
117+ # スペースを離した
118+ if self .space_pressed and self .dy < 0 :
119+ # 上昇中に離されたら上昇を止める
120+ self .dy = 0
117121 self .space_pressed = False
118122
119123 self .x , self .y = push_back (self .x , self .y , self .dx , self .dy )
@@ -185,6 +189,32 @@ def __init__(self, x, y, img):
185189 self .character = 32
186190
187191
192+ class Flower2 (Obstacle ):
193+ def __init__ (self , x , y , img ):
194+ super ().__init__ (x , y , img )
195+ self .character = 32
196+
197+ def draw (self ):
198+ if self .is_show :
199+ u = (self .frame_count // 10 % 2 ) * 8
200+ w = 8 if self .direction > 0 else - 8
201+ self .img .blt (self .x - player .x , self .y , 0 , u + 16 , self .character , w , 8 , TRANSPARENT_COLOR )
202+ self .img .blt (self .x - player .x , self .y - 8 , 0 , u , self .character , w , 8 , TRANSPARENT_COLOR )
203+
204+ def is_colliding (self , x , y ):
205+ if not self .is_show :
206+ return False
207+ # もしobsとplayerが4ピクセル以上重なっていたら衝突
208+ if abs (self .x - x ) <= 4 and abs (self .y - y ) <= 4 :
209+ return True
210+ # もしobsとplayerが4ピクセル以上重なっていたら衝突
211+ if abs (self .x - x ) <= 4 and abs (self .y - 8 - y ) <= 4 :
212+ return True
213+
214+ return False
215+
216+
217+
188218class Bird (Obstacle ):
189219 def __init__ (self , x , y , img , speed = 1 ):
190220 super ().__init__ (x , y , img )
@@ -219,22 +249,34 @@ def reset(self):
219249 for i in range (100 ):
220250 if x < 500 :
221251 x += random .randint (4 , 12 ) * 8
222- self .obstacles .append (Flower1 (x , 72 , self .img ))
252+ if random .randint (0 , 10 ) == 0 :
253+ self .obstacles .append (Flower2 (x + 8 , 72 , self .img ))
254+ else :
255+ self .obstacles .append (Flower1 (x , 72 , self .img ))
223256 if i % 6 == 7 :
224257 self .obstacles .append (Bird (x , random .randint (24 , 72 ), self .img , speed = 1 ))
225258 elif x < 1000 :
226259 x += random .randint (3 , 10 ) * 8
227- self .obstacles .append (Flower1 (x , 72 , self .img ))
260+ if random .randint (0 , 7 ) == 0 :
261+ self .obstacles .append (Flower2 (x + 8 , 72 , self .img ))
262+ else :
263+ self .obstacles .append (Flower1 (x , 72 , self .img ))
228264 if i % 6 == 0 :
229265 self .obstacles .append (Bird (x , random .randint (24 , 72 ), self .img , speed = i % 2 + 1 ))
230266 elif x < 1500 :
231267 x += random .randint (2 , 7 ) * 8
232- self .obstacles .append (Flower1 (x , 72 , self .img ))
268+ if random .randint (0 , 4 ) == 0 :
269+ self .obstacles .append (Flower2 (x + 8 , 72 , self .img ))
270+ else :
271+ self .obstacles .append (Flower1 (x , 72 , self .img ))
233272 if i % 3 == 0 :
234273 self .obstacles .append (Bird (x , random .randint (36 , 72 ), self .img , speed = 2 ))
235274 else :
236275 x += random .randint (1 , 4 ) * 8
237- self .obstacles .append (Flower1 (x , 72 , self .img ))
276+ if random .randint (0 , 2 ) == 0 :
277+ self .obstacles .append (Flower2 (x + 8 , 72 , self .img ))
278+ else :
279+ self .obstacles .append (Flower1 (x , 72 , self .img ))
238280 self .obstacles .append (Bird (x , random .randint (48 , 72 ), self .img , speed = 3 ))
239281
240282 reset ()
0 commit comments