changeset 74:10a75a37c0fa

Make ghost2 try to maintain a specific distance in fright mode rather than always running away
author Michael Pavone <pavone@retrodev.com>
date Mon, 28 Jul 2014 01:03:11 -0700
parents 91e7a30a9e27
children 6df7f6372d29
files code/ghost2.gq
diffstat 1 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/code/ghost2.gq	Mon Jul 28 00:42:45 2014 -0700
+++ b/code/ghost2.gq	Mon Jul 28 01:03:11 2014 -0700
@@ -8,6 +8,9 @@
 	lastY <- 0
 	myX <- 0
 	myY <- 0
+	dist <- 0
+	distX <- 0
+	distY <- 0
 	
 	getDirX <- :dir startX {
 		if: dir = right {
@@ -49,7 +52,7 @@
 			//ghost is to the right of target
 			if: myY > targetY {
 				//ghost is below target
-				if: (myX - targetX) > (myY - targetY) {
+				if: distX > distY {
 					//target is more left than up
 					firstChoice <- left
 					secondChoice <- up
@@ -59,7 +62,7 @@
 				}
 			} else: {
 				//ghost is above or directly to the right of target
-				if: (myX - targetX) > (targetY - myY) {
+				if: distX > distY {
 					//target is more left than down
 					firstChoice <- left
 					secondChoice <- down
@@ -73,7 +76,7 @@
 			//ghost is to the left of or directly above/below target
 			if: myY > targetY {
 				//ghost is below target
-				if: (targetX - myX) > (myY - targetY) {
+				if: distX > distY {
 					//target is more right than up
 					firstChoice <- right
 					secondChoice <- up
@@ -83,7 +86,7 @@
 				}
 			} else: {
 				//ghost is above or directly to the left of target
-				if: (targetX - myX) > (targetY - myY) {
+				if: distX > distY {
 					//target is more right than down
 					firstChoice <- right
 					secondChoice <- down
@@ -95,9 +98,11 @@
 			}
 		}
 		if: myVit = 1 {
-			//currently in fright mode, try to run away
-			firstChoice <- (firstChoice + 2) and: 3 //opDir: firstChoice
-			secondChoice <- (secondChoice + 2) and: 3 //opDir: secondChoice
+			//currently in fright mode, try to run away if we are close to LM
+			if: dist < 16 {				
+				firstChoice <- (firstChoice + 2) and: 3 //opDir: firstChoice
+				secondChoice <- (secondChoice + 2) and: 3 //opDir: secondChoice
+			}
 		}
 		
 		
@@ -133,7 +138,7 @@
 	}
 
 	//"wingman" - tries to surround lambda man
-	//position two cells ahead of his current position
+	//by picking a position sideways of his current direction
 	main <- {
 		lmX <- lambdamanPos:
 		lmY <- yCoord