19 lines
408 B
Go
19 lines
408 B
Go
|
package land
|
||
|
|
||
|
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
|
||
|
}
|