2024-07-18 09:21:25 +00:00
|
|
|
package land
|
|
|
|
|
2024-07-18 09:46:36 +00:00
|
|
|
type PositionedObject interface {
|
|
|
|
GetPosition() Vector2D
|
|
|
|
GetSize() Vector2D
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsOverlapWithPoint(obj PositionedObject, point Vector2D) bool {
|
|
|
|
return point.X >= obj.GetPosition().X && point.X <= obj.GetPosition().X+obj.GetSize().X &&
|
|
|
|
point.Y >= obj.GetPosition().Y && point.Y <= obj.GetPosition().Y+obj.GetSize().Y
|
|
|
|
}
|
|
|
|
|
2024-07-18 09:21:25 +00:00
|
|
|
type CollidableObject interface {
|
|
|
|
GetPosition() Vector2D
|
|
|
|
GetSize() Vector2D
|
|
|
|
OnCollide(other CollidableObject)
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkCollisionBetweenObject(a, b CollidableObject) bool {
|
|
|
|
aPos := a.GetPosition()
|
|
|
|
aSize := a.GetSize()
|
|
|
|
bPos := b.GetPosition()
|
|
|
|
bSize := b.GetSize()
|
|
|
|
return aPos.X < bPos.X+bSize.X &&
|
|
|
|
aPos.X+aSize.X > bPos.X &&
|
|
|
|
aPos.Y < bPos.Y+bSize.Y &&
|
|
|
|
aPos.Y+aSize.Y > bPos.Y
|
|
|
|
}
|