diff --git a/fcore/enemy/enemy-behaviour.sml b/fcore/enemy/enemy-behaviour.sml index c154d37..2c53694 100644 --- a/fcore/enemy/enemy-behaviour.sml +++ b/fcore/enemy/enemy-behaviour.sml @@ -517,8 +517,54 @@ struct EnemyPatch.withPatches (enemy, patches) end + fun getShieldOnPatches (player, enemy) = + if #platID player = #platID enemy then + [] + else + (* turn off shield if player moved to a different platform *) + [EnemyPatch.W_SHIELD_ON false] + + fun getShieldOffPatches + (player, enemy, walls, wallTree, platforms, platformTree) = + let + val {x = ex, y = ey, facing = eFacing, platID = eID, ...} = enemy + val {x = px, y = py, platID = pID, ...} = player + + val shouldTurnShieldOn = + eID = pID + andalso + case eFacing of + FACING_RIGHT => px > ex + | FACING_LEFT => px < ex + in + if shouldTurnShieldOn then + [EnemyPatch.W_SHIELD_ON true, EnemyPatch.W_X_AXIS STAY_STILL] + else + startPatrolPatches (player, enemy, wallTree, platformTree, []) + end + fun updateShieldSlime - (player, enemy, walls, wallTree, platforms, platformTree) = enemy + (player, enemy, walls, wallTree, platforms, platformTree) = + let + val size = Constants.enemySize + val enemy = withDefaultYAxis enemy + + val patches = + if #shieldOn enemy then + getShieldOnPatches (player, enemy) + else + getShieldOffPatches + (player, enemy, walls, wallTree, platforms, platformTree) + val enemy = EnemyPatch.withPatches (enemy, patches) + + val patches = EnemyPhysics.getPhysicsPatches enemy + val enemy = EnemyPatch.withPatches (enemy, patches) + + val patches = EnemyPhysics.getEnvironmentPatches + (enemy, walls, wallTree, platforms, platformTree) + in + EnemyPatch.withPatches (enemy, patches) + end fun updateEnemyState (enemy, walls, wallTree, platforms, platformTree, player, graph) = diff --git a/fcore/enemy/enemy.sml b/fcore/enemy/enemy.sml index 7e9d48b..5706384 100644 --- a/fcore/enemy/enemy.sml +++ b/fcore/enemy/enemy.sml @@ -86,7 +86,9 @@ struct PATROL_SLIME => (0.5, 0.5, 1.0) | FOLLOW_SLIME => (1.0, 0.5, 0.5) | STRAIGHT_BAT => (0.55, 0.55, 0.55) - | SHIELD_SLIME => (0.33, 0.33, 0.11) + | SHIELD_SLIME => + if #shieldOn enemy then (0.33, 0.33, 0.11) + else (0.5, 0.5, 1.0) in if wratio < hratio then let