enemy dropping below platform (without any bugs) is fully implemented now

This commit is contained in:
2025-01-23 01:06:16 +00:00
parent efbf0c7da9
commit e644160e38
4 changed files with 61 additions and 31 deletions

View File

@@ -187,11 +187,12 @@ struct
val platFinishX = platX + platW val platFinishX = platX + platW
val {x = eX, y = ey, yAxis = eyAxis, ...} = enemy val {x = eX, y = ey, yAxis = eyAxis, ...} = enemy
val ey = ey + Constants.enemySize
val standingOnPlat = standingOnArea (enemy, platformTree) val standingOnPlat = standingOnArea (enemy, platformTree)
in in
isBetween (platX, eX, platFinishX) andalso standingOnPlat isBetween (platX, eX, platFinishX) andalso standingOnPlat
andalso (ey > platY andalso ey + Constants.jumpLimit >= platY) andalso (ey > platY andalso ey >= platY)
end end
fun canDrop (nextPlatform, platformTree, enemy) = fun canDrop (nextPlatform, platformTree, enemy) =

View File

@@ -73,31 +73,30 @@ struct
end end
end end
fun getPlatformPatches (yAxis, platforms: platform vector, lst, acc) = fun standingOnArea (x, y, tree) =
let let
open QuadTree val y = y + Fn.entitySize - 1
in
case lst of
platID :: tl =>
(case yAxis of
DROP_BELOW_PLATFORM =>
(* pass through, allowing player to drop below the platform *)
getPlatformPatches (yAxis, platforms, tl, acc)
| JUMPING _ =>
(* pass through, allowing player to jump above the platform *)
getPlatformPatches (yAxis, platforms, tl, acc)
| _ =>
let
(* default case:
* player will land on platform and stay on the ground there. *)
val {y = platY, ...} = Vector.sub (platforms, platID - 1)
val newY = platY - Fn.entitySize val width = Fn.entitySize
val acc = Fn.W_Y_AXIS ON_GROUND :: Fn.W_Y newY :: acc val height = Platform.platHeight
in
getPlatformPatches (yAxis, platforms, tl, acc) val ww = Constants.worldWidth
end) val wh = Constants.worldHeight
| [] => acc in
QuadTree.hasCollisionAt (x, y, width, height, 0, 0, ww, wh, ~1, tree)
end
fun standingOnAreaID (x, y, tree) =
let
val y = y + Fn.entitySize - 1
val width = Fn.entitySize
val height = Platform.platHeight
val ww = Constants.worldWidth
val wh = Constants.worldHeight
in
QuadTree.getItemID (x, y, width, height, 0, 0, ww, wh, tree)
end end
fun getWallPatches (walls: wall vector, lst, acc) = fun getWallPatches (walls: wall vector, lst, acc) =
@@ -151,7 +150,37 @@ struct
val platCollisions = QuadTree.getCollisionsBelow val platCollisions = QuadTree.getCollisionsBelow
(x, y, size, size, 0, 0, ww, wh, 0, platformTree) (x, y, size, size, 0, 0, ww, wh, 0, platformTree)
val acc = getPlatformPatches (yAxis, platforms, platCollisions, [])
val platID = standingOnAreaID (x, y, platformTree)
val acc = []
val acc =
if platID <> ~1 then
(case yAxis of
DROP_BELOW_PLATFORM =>
(* pass through, allowing player to drop below the platform *)
acc
| JUMPING _ =>
(* pass through, allowing player to jump above the platform *)
acc
| FLOATING _ =>
(* pass through, allowing player to jump above the platform *)
acc
| _ =>
let
(* default case:
* player will land on platform and stay on the ground there. *)
val {y = platY, ...}: GameType.platform =
Vector.sub (platforms, platID - 1)
val newY = platY - Fn.entitySize
val acc = Fn.W_Y_AXIS ON_GROUND :: Fn.W_Y newY :: acc
in
acc
end)
else
acc
val acc = val acc =
case yAxis of case yAxis of

View File

@@ -2,8 +2,8 @@ structure Platform =
struct struct
(* collision height of a platform. (* collision height of a platform.
* Visual height may (and probably will) be different. *) * Visual height may (and probably will) be different. *)
val platHeight = 3 val platHeight = 5
val rPlatHeight = 3.0 val rPlatHeight = 5.0
fun helpGenerateTree (pos, platVec, acc) = fun helpGenerateTree (pos, platVec, acc) =
if pos = Vector.length platVec then if pos = Vector.length platVec then

View File

@@ -1305,7 +1305,7 @@ struct
, quadY , quadY
, halfWidth , halfWidth
, halfHeight , halfHeight
, tree , topLeft
) )
end end
| TOP_RIGHT => | TOP_RIGHT =>
@@ -1323,7 +1323,7 @@ struct
, quadY , quadY
, halfWidth , halfWidth
, halfHeight , halfHeight
, tree , topRight
) )
end end
| BOTTOM_LEFT => | BOTTOM_LEFT =>
@@ -1341,7 +1341,7 @@ struct
, middleY , middleY
, halfWidth , halfWidth
, halfHeight , halfHeight
, tree , bottomLeft
) )
end end
| BOTTOM_RIGHT => | BOTTOM_RIGHT =>
@@ -1360,7 +1360,7 @@ struct
, middleY , middleY
, halfWidth , halfWidth
, halfHeight , halfHeight
, tree , bottomRight
) )
end end
| PARENT_QUADRANT => ~1) | PARENT_QUADRANT => ~1)