Moved isIn function to a util file

This commit is contained in:
Julien Dessaux 2021-09-19 01:10:52 +02:00
parent 2ba8d90815
commit 0c52da6714
4 changed files with 48 additions and 39 deletions

View file

@ -2,19 +2,15 @@ package field
func (f Field) Step(x, y, dx, dy int) (int, int) {
x2, y2 := x+dx, y+dy
if f.IsIn(x2, y2) {
if f.isIn(x2, y2) {
return x2, y2
}
// We are stepping outside, we need to wrap the Lahey-space
for {
x2, y2 := x-dx, y-dy
if !f.IsIn(x2, y2) {
if !f.isIn(x2, y2) {
return x, y
}
x, y = x2, y2
}
}
func (f Field) IsIn(x, y int) bool {
return x >= f.x && x < f.x+f.lx && y >= f.y && y < f.y+f.ly
}