aboutsummaryrefslogtreecommitdiff
path: root/pkg/field/step.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-09-17 00:45:07 +0200
committerJulien Dessaux2021-09-17 00:45:07 +0200
commit2ba8d90815a621d263cd198fe2da8579e46e732d (patch)
tree80eaa2e3327306ea0c281972c252c7203a6198bf /pkg/field/step.go
parentrewrote field data structure for simplicity (diff)
downloadgofunge98-2ba8d90815a621d263cd198fe2da8579e46e732d.tar.gz
gofunge98-2ba8d90815a621d263cd198fe2da8579e46e732d.tar.bz2
gofunge98-2ba8d90815a621d263cd198fe2da8579e46e732d.zip
Added function to calculate a next pointer step on the field
Diffstat (limited to '')
-rw-r--r--pkg/field/step.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/pkg/field/step.go b/pkg/field/step.go
new file mode 100644
index 0000000..50147d2
--- /dev/null
+++ b/pkg/field/step.go
@@ -0,0 +1,20 @@
+package field
+
+func (f Field) Step(x, y, dx, dy int) (int, int) {
+ x2, y2 := x+dx, y+dy
+ 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) {
+ 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
+}