diff --git a/fcore/enemy-behaviour.sml b/fcore/enemy-behaviour.sml index f9e40f7..38dd3c3 100644 --- a/fcore/enemy-behaviour.sml +++ b/fcore/enemy-behaviour.sml @@ -181,18 +181,46 @@ struct getHighestPlatform (collisions, platforms, wh, ~1) end - fun canJump (nextPlatform, platformTree, enemy) = + fun canJump (prevPlatform, nextPlatform) = let - val {x = platX, y = platY, width = platW, ...} = nextPlatform - val platFinishX = platX + platW + val {x = pPlatX, y = pPlatY, width = pPlatW, ...} = prevPlatform + val pPlatFinishX = pPlatX + pPlatW - val {x = eX, y = ey, yAxis = eyAxis, ...} = enemy + val {x = nPlatX, y = nPlatY, width = nPlatW, ...} = nextPlatform + val nPlatFinishX = nPlatX + nPlatW + in + isBetween (nPlatX, pPlatX, nPlatFinishX) + orelse isBetween (nPlatX, pPlatFinishX, nPlatFinishX) + end + + fun getJumpPatches (nextPlatform, platformTree, enemy, acc) = + let + val {x = platX, y = platY, width = platWidth, ...} = nextPlatform + val platFinishX = platX + platWidth + + val {x = eX, y = ey, yAxis = eyAxis, xAxis = exAxis, ...} = enemy + val ecx = eX + (Constants.enemySize div 2) val ey = ey + Constants.enemySize val standingOnPlat = standingOnArea (enemy, platformTree) in - isBetween (platX, eX, platFinishX) andalso standingOnPlat - andalso (ey > platY andalso ey >= platY) + if ey > platY andalso ey >= platY andalso standingOnPlat then + if isBetween (platX, ecx, platFinishX) then + (* can jump from same position enemy is at *) + case eyAxis of + ON_GROUND => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc + | FALLING => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc + | _ => acc + else + (* have to travel left/right before jumping *) + if eX < platX then + (* have to move right to jump to platform *) + EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc + else + (* have to move left to jump to platform *) + EnemyPatch.W_X_AXIS MOVE_LEFT :: acc + else + acc end fun canDrop (nextPlatform, platformTree, enemy) = @@ -212,22 +240,17 @@ struct fun getPathToNextPlatform (nextPlatformID, platforms, platformTree, enemy, eID, pID, acc) = let + val currentPlatform = Platform.find (eID, platforms) val nextPlatform = Platform.find (nextPlatformID, platforms) val {x = eX, y = ey, yAxis = eyAxis, ...} = enemy - val canJump = canJump (nextPlatform, platformTree, enemy) + val canJump = canJump (currentPlatform, nextPlatform) val canDrop = canDrop (nextPlatform, platformTree, enemy) in - if canJump then - case eyAxis of - ON_GROUND => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc - | FALLING => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc - | _ => acc - else if canDrop then - EnemyPatch.W_Y_AXIS DROP_BELOW_PLATFORM :: acc - else - acc + if canJump then getJumpPatches (nextPlatform, platformTree, enemy, acc) + else if canDrop then EnemyPatch.W_Y_AXIS DROP_BELOW_PLATFORM :: acc + else acc end fun canJumpOnPlatform (player, platforms, enemy: enemy, platformTree, acc) = diff --git a/fcore/game-type.sml b/fcore/game-type.sml index c8a8607..753a0f2 100644 --- a/fcore/game-type.sml +++ b/fcore/game-type.sml @@ -164,15 +164,17 @@ struct val plat1 = {id = 1, x = 155, y = 911, width = 199} val plat2 = {id = 2, x = 355, y = 759, width = 555} val plat3 = {id = 3, x = 355, y = 659, width = 555} - val plat4 = {id = 4, x = 155, y = 855, width = 199} + val plat4 = {id = 4, x = 155, y = 855, width = 99} val plat5 = {id = 5, x = 155, y = 811, width = 199} val plat6 = {id = 6, x = 155, y = 710, width = 199} - val platforms = Vector.fromList [plat1, plat2, plat3, plat4, plat5, plat6] + val plat7 = {id = 7, x = 301, y = 855, width = 99} + val platforms = Vector.fromList + [plat1, plat2, plat3, plat4, plat5, plat6, plat7] val platformTree = Platform.generateTree platforms val enemy1 = { id = 1 - , x = 300 + , x = 251 , y = 855 , health = 1 , xAxis = MOVE_LEFT