def block_animation(self, direction='', block=None): def add_block(function): self.item_animation_list.append(function) # 近づくとアニメーション開始 if block is None: for block in Stage.block_object_list: # ジャンプするとビームを放つ if block.data == 9.3 and not block.isBeam and not self.player.isGrounding: if block.rect.left - self.player.rect.left < 82: if block.y - self.player.y > -10: block.isHide = False block.isBeam = True add_block(Block.Beam(block)) Text.set(self.screen, 'ビーー', sprite=block, tweak_x=10) # 近づくと落ちるブロック if block.data == 1.3 and not block.isAnimation: if block.rect.left - self.player.rect.left < 0: if block.rect.bottom - self.player.rect.bottom < 0: add_block(Block.NearFall(block)) # 近づくと敵出現イベント発生 if block.data == 39 and not block.isAnimation: if block.rect.left - self.player.rect.left < 25: if self.player.rect.left - block.rect.left < 40: add_block(Block.EventEnemy(block)) # 当たるとアニメーション開始 else: # 壊れるブロック if block.name == 'block1': # 近づくと落ちるブロックの当たり判定 if block.data == 1.3 and block.isAnimation and direction == 'TOP_BLOCK': self.player.isDeath = True if direction == 'TOP': # 叩くと壊れる if block.data == 1: add_block(Block.Break(self.screen, block)) # 叩くと大量のコインが出る if block.data == 1.6: add_block(Block.Coin(self.screen, block, isLot=True)) # 叩くとPスイッチ if block.data == 2.2: Sound.play_SE('brockkinoko') # ブロックデータの置き換え block.name = 'block3' block.data = 5 block.image = LoadImage.image_list[block.name] # Pスイッチを表示 for p in Stage.block_object_list: if p.data == 2.2 and block.x == p.x: p.isHide = False # はてなブロック if block.name == 'block2': # 叩くとコイン if direction == 'TOP' and block.data == 3: add_block(Block.Coin(self.screen, block)) # 叩けないブロック if direction == 'TOP_BLOCK' and block.data == 3.1 and self.player.y_speed < 0: block.rect.bottom = self.player.rect.top - 10 # 隠しブロック if block.name == 'block3' and direction == 'TOP' and block.isHide: block.isHide = False # 叩くとコイン if block.data in [5, 5.1]: add_block(Block.Coin(self.screen, block)) # 針 if block.name == 'block7' and direction == 'TOP': self.player.isDeath = True Text.set(self.screen, '刺さった!!', sprite=self.player) # 叩くアニメーション if direction == 'TOP': # 赤キノコ if block.data in [1.7, 3.2, 5.2]: add_block(Block.Kinoko(self.screen, block)) # 毒キノコ if block.data in [1.9, 3.4, 5.4]: add_block(Block.PoisonKinoko(self.screen, block)) # 大量の毒キノコ if block.data in [3.5, 5.5]: add_block( Block.PoisonKinoko(self.screen, block, isLot=True)) # まるい敵 if block.data in [2.3, 3.8, 5.8]: add_block(Block.Enemy(self.screen, block, 'enemy')) # 甲羅敵 if block.data in [2.4, 3.9, 5.9]: add_block( Block.Enemy(self.screen, block, 'koura1', tweak=10)) # スター if block.data in [2.1, 3.7, 5.7]: add_block(Block.Star(self.screen, block)) # 乗ると壊れるブロック if direction == 'BOTTOM' and block.data in [1.4, 5.1]: add_block(Block.Break(self.screen, block)) self.jump_disable_list.append(block) # コイン if block.name == 'item1': Sound.play_SE('coin') block.remove() Stage.block_object_list.remove(block) # トゲを生やす if block.data in [1.1, 7.1, 8.3]: block.isThorns = True self.player.isDeath = True Text.set(self.screen, 'シャキーン', sprite=block) # Pスイッチ if direction == 'BOTTOM' and block.name == 'block39' and not block.isHide: Sound.play_SE('Pswitch') Sound.stop_BGM() block.isHide = True self.jump_disable_list.append(block) # 全てコインに置き換え for b in Stage.block_object_list: b.name = 'item1' b.data = 25 b.image = LoadImage.image_list[b.name] # 土管に入る if block.name == 'dokan1': # 上から入る場合 if direction == 'BOTTOM': if block.data in [ 20.2, 20.3, 20.5 ] and block.rect.left + 25 < self.player.rect.right - 5: if block.rect.right - 25 > self.player.rect.left + 6 and pygame.key.get_pressed( )[K_DOWN]: self.player.dive_dokan = block # 横からはいる場合 if direction == 'SIDE' and block.data in [ 20.6, 20.8 ] and self.player.isGrounding: pass # うめぇ if block.data == 19.2: self.player.isDeath = True block.name = 'cloud3' block.image = LoadImage.image_list[block.name] Text.set(self.screen, 'うめぇ!!', sprite=block) # 透明のうめぇ if block.data == 19.3: self.player.isDeath = True block.isHide = False Text.set(self.screen, 'うめぇ!!', sprite=block) # 乗ると落ちる足場ブロック if direction == 'BOTTOM' and block.data == 8.1 and not block.isAnimation: add_block(Block.RideFall()) # ビームの当たり判定 if block.name == 'beam' and not block.isHide and self.player.y + self.player.height > block.y + 25: self.player.isDeath = True # 中間地点 if block.name == 'halfway': SpritePlayer.initial_x = 210 SpritePlayer.initial_y = block.y SpritePlayer.initial_scroll_sum = block.x - 210 block.remove() Stage.block_object_list.remove(block) # ゴールポール if block.name == 'goal_pole': if block.data == 9.1 and not self.goal_isMove: self.player.goal = block # ゴール塔 if block.name == 'end' and self.goal_isMove: start_x = block.x - SpritePlayer.scroll_sum + 60 start_y = block.rect.top + 45 end_x = block.width - 80 end_y = block.height - 45 block_rect = Rect(start_x, start_y, end_x, end_y) player_rect = Rect(self.player.x, self.player.y, self.player.width, self.player.height) # ゴール塔の中に入る if player_rect.colliderect(block_rect): self._inGoal_tower = True self._goal_init = False self.goal_isMove = False
def block_animation(self, direction='', block=None): def add_block(function): self.item_animation_list.append(function) # 近づくとアニメーション開始 if block is None: for block in Stage.block_object_list: # ジャンプするとビームを放つ if block.data == 9.3 and not Block.Beam.instance and not self.player.isGrounding: if block.rect.left - self.player.rect.left < 82: if block.y - self.player.y > -10: block.isHide = False add_block(Block.Beam(block)) Text.set(self.screen, 'ビーー', sprite=block, tweak_x=10) # 近づくと落ちるブロック if block.data == 1.3 and not block.isAnimation: if block.rect.left - self.player.rect.left < 0: if block.rect.bottom - self.player.rect.bottom < 0: add_block(Block.NearFall(block)) # 近づくと敵出現イベント発生 if block.data == 39 and not block.isAnimation: if block.rect.left - self.player.rect.left < 25: if self.player.rect.left - block.rect.left < 40: add_block(Block.EventEnemy(block)) # 当たるとアニメーション開始 else: # 壊れるブロック if block.name == 'block1': # トゲを生やす if block.data == 1.1: block.isThorns = True self.player.isDeath = True Text.set(self.screen, 'シャキーン', sprite=block) # 近づくと落ちるブロックの当たり判定 if block.data == 1.3 and block.isAnimation and direction == 'TOP_BLOCK': self.player.isDeath = True if direction == 'TOP': # 叩くと壊れる if block.data == 1: add_block(Block.Break(self.screen, block)) block.remove() Stage.block_object_list.remove(block) # 叩くと大量のコインが出る if block.data == 1.6: add_block(Block.Coin(self.screen, block, isLot=True)) # 叩くとスター if block.data == 2.1: add_block(Block.Star(self.screen, block)) # はてなブロック if block.name == 'block2': if direction == 'TOP': # 叩くとコインが出る if block.data == 3: add_block(Block.Coin(self.screen, block)) # 叩くと赤キノコが出る if block.data == 3.2: add_block(Block.Kinoko(self.screen, block)) # 叩くと敵が出る if block.data == 3.8: add_block(Block.Enemy(self.screen, block, 'enemy')) # 叩けないブロック elif direction == 'TOP_BLOCK' and block.data == 3.1 and self.player.y_speed < 0: block.rect.bottom = self.player.rect.top - 10 # 隠しブロック if direction == 'TOP' and block.name == 'block3' and block.isHide: block.isHide = False # 叩くとコインが出る if block.data == 5: add_block(Block.Coin(self.screen, block)) # 叩くと大量の毒キノコが出る if block.data == 5.5: add_block( Block.PoisonKinoko(self.screen, block, isLot=True)) # 土管に入る if block.name == 'dokan1': # 上から入る場合 if direction == 'BOTTOM': if block.data in [ 20.2, 20.3, 20.5 ] and block.rect.left + 25 < self.player.rect.right - 5: if block.rect.right - 25 > self.player.rect.left + 6 and pygame.key.get_pressed( )[K_DOWN]: self.player.dive_dokan = block # 横からはいる場合 if direction == 'SIDE' and block.data in [ 20.6, 20.8 ] and self.player.isGrounding: pass # うめぇ if block.data == 19.2: self.player.isDeath = True block.name = 'cloud3' block.image = LoadImage.image_list[block.name] Text.set(self.screen, 'うめぇ!!', sprite=block) # 透明のうめぇ if block.data == 19.3: self.player.isDeath = True block.isHide = False Text.set(self.screen, 'うめぇ!!', sprite=block) # 落ちる足場ブロック if direction == 'BOTTOM' and block.data == 8.1 and not block.isAnimation: add_block(Block.RideFall()) # ビームの当たり判定 if block.name == 'beam' and not block.isHide and self.player.y + self.player.height > block.y + 25: self.player.isDeath = True # 中間地点 if block.name == 'halfway': SpritePlayer.initial_x = 210 SpritePlayer.initial_y = block.y SpritePlayer.initial_scroll_sum = block.x - 210 block.remove() Stage.block_object_list.remove(block) # ゴールポール if block.name == 'goal_pole': if block.data == 9.1 and not self.goal_isMove: self.player.goal = block # ゴール塔 if block.name == 'end' and self.goal_isMove: start_x = block.x - SpritePlayer.scroll_sum + 60 start_y = block.rect.top + 45 end_x = block.width - 80 end_y = block.height - 45 block_rect = Rect(start_x, start_y, end_x, end_y) player_rect = Rect(self.player.x, self.player.y, self.player.width, self.player.height) # ゴール塔の中に入る if player_rect.colliderect(block_rect): self._inGoal_tower = True self._goal_init = False self.goal_isMove = False