diff --git a/fcore/enemy.sml b/fcore/enemy.sml index cbfa802..7f9ea59 100644 --- a/fcore/enemy.sml +++ b/fcore/enemy.sml @@ -12,6 +12,24 @@ struct fun exists (id, collisions) = helpExists (0, id, collisions) + fun canWalkAhead (x, y, wallTree, platformTree) = + let + val ww = Constants.worldWidth + val wh = Constants.worldHeight + + val searchWidth = Constants.enemySize + + val y = y + Constants.enemySize - 5 + val searchHeight = 10 + in + QuadTree.hasCollisionAt + (x, y, searchWidth, searchHeight, 0, 0, ww, wh, ~1, wallTree) + orelse + QuadTree.hasCollisionAt + (x, y, searchWidth, searchHeight, 0, 0, ww, wh, ~1, platformTree) + end + + fun getPatrollPatches (enemy: enemy, wallTree, platformTree, acc) = let (* This function is meant to check @@ -58,12 +76,14 @@ struct , wallTree ) in - if hasWallAhead then - EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc - else - (* todo: invert direction if moving further left - * will result in falling down *) - acc + if + hasWallAhead + then EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc + else (* invert direction if moving further left + * will result in falling down *) if + canWalkAhead (searchStartX, y, wallTree, platformTree) + then acc + else EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc end | MOVE_RIGHT => let @@ -90,12 +110,14 @@ struct , wallTree ) in - if hasWallAhead then - EnemyPatch.W_X_AXIS MOVE_LEFT :: acc - else - (* todo: invert direction if moving further left - * will result in falling down *) - acc + if + hasWallAhead + then EnemyPatch.W_X_AXIS MOVE_LEFT :: acc + else (* invert direction if moving further right + * will result in falling down *) if + canWalkAhead (searchStartX, y, wallTree, platformTree) + then acc + else EnemyPatch.W_X_AXIS MOVE_LEFT :: acc end | STAY_STILL => acc end diff --git a/fcore/game-type.sml b/fcore/game-type.sml index 3e58b88..8a24d4a 100644 --- a/fcore/game-type.sml +++ b/fcore/game-type.sml @@ -147,15 +147,15 @@ struct val walls = Vector.fromList [wall1, wall2, wall3] val wallTree = Wall.generateTree walls - val plat1 = {id = 1, x = 155, y = 911, width = 155} + val plat1 = {id = 1, x = 155, y = 911, width = 199} val platforms = Vector.fromList [plat1] val platformTree = Platform.generateTree platforms val enemy1 = { id = 1 , x = 300 - , y = 745 - , health = 5 + , y = 855 + , health = 1 , xAxis = MOVE_LEFT , yAxis = FALLING } @@ -163,7 +163,7 @@ struct { id = 2 , x = 555 , y = 945 - , health = 5 + , health = 1 , xAxis = MOVE_LEFT , yAxis = FALLING } @@ -171,7 +171,7 @@ struct { id = 3 , x = 979 , y = 945 - , health = 5 + , health = 1 , xAxis = MOVE_RIGHT , yAxis = FALLING }