Exemplo n.º 1
0
func GetHitbox(sprite message.Sprite) hitbox.Hitbox {
	switch sprite {
	case PlaceholderSprite:
		return hitbox.NewNull()
	case PlayerSprite:
		return hitbox.NewCircle(10)
	case BallSprite:
		return hitbox.NewCircle(10)
	}
	return nil
}
Exemplo n.º 2
0
func TestCircle(t *testing.T) {
	hb := hitbox.NewCircle(10)
	contour := hb.Contour(&terrain.Position{10, 22})

	if len(contour) != 4 {
		t.Fatal("Circle hitbox contour must contain 4 points")
	}

	expected := []*terrain.Position{
		&terrain.Position{20, 22},
		&terrain.Position{10, 32},
		&terrain.Position{0, 22},
		&terrain.Position{10, 12},
	}

	// Compare rounded values, because of precision errors
	for i, pt := range contour {
		if !pt.ToMessage().Equals(expected[i].ToMessage()) {
			t.Error("Invalid contour point at index", i, "expected", expected[i], "but got", pt)
		}
	}
}