クラス内での関数の使い方

実現したいこと

同クラス内の関数をselfだけではなくobjectにも用いたい

前提

発生している問題・エラーメッセージ

AttributeError: type object 'object' has no attribute 'getCoords'

該当のソースコード

python

1class Ball:2 3 def getCoords(self): # 左上と右下の座標取得4 return (self.rect.x, self.rect.y, self.rect.x + s.block_width - 5, self.rect.y + s.block_height - 5)5 6 7 8 def getCollisionCoords(self, object):9 # ボールとオブジェクトの座標取得10 ball_x1, ball_y1, ball_x2, ball_y2 = self.getCoords()11 object_x1, object_y1, object_x2, object_y2 = object.getCoords()12 13 # 短形の座標取得14 x1 = max(ball_x1, object_x1)15 y1 = max(ball_y1, object_y1)16 x2 = min(ball_x2, object_x2)17 y2 = min(ball_y2, object_y2)18 19 if x1 < x2 and y1 < y2:20 return (x1, y1, x2, y2)21 else:22 return None

試したこと

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

コメントを投稿

0 コメント