I think functions to drop below platforms have been coded and work fine, but I can't manually test because of an exception during compilation. So save progress by pushing to GitHub for now.

This commit is contained in:
2024-12-17 22:45:58 +00:00
parent 8344138c55
commit 3ce2a974ba
2 changed files with 74 additions and 71 deletions

View File

@@ -7,6 +7,7 @@ sig
datatype player_y_axis =
ON_GROUND
| FALLING
| DROP_BELOW_PLATFORM
| JUMPING of int
| FLOATING of int
@@ -42,6 +43,7 @@ struct
datatype player_y_axis =
ON_GROUND
| FALLING
| DROP_BELOW_PLATFORM
| JUMPING of int
| FLOATING of int

View File

@@ -56,7 +56,59 @@ struct
end
| (QUERY_ON_TOP_SIDE, wallID) :: tl =>
checkWalls (yAxis, xAxis, x, y, health, jumpPressed, tl, game)
| [] => mkPlayer (health, xAxis, yAxis, x, y, jumpPressed)
| [] =>
mkPlayer (health, xAxis, yAxis, x, y, jumpPressed)
end
fun helpCheckPlatforms
( yAxis, xAxis, x, y, health
, jumpPressed, platList, wallList, game
) =
let
open QuadTree
in
case platList of
platID :: tl =>
(case yAxis of
DROP_BELOW_PLATFORM =>
helpCheckPlatforms
(yAxis, xAxis, x, y, health, jumpPressed, tl, wallList, game)
| _ =>
let
val {platforms, ...} = game
val {y = platY, ...} = Vector.sub (platforms, platID - 1)
val newY = platY - size
in
helpCheckPlatforms
(ON_GROUND, xAxis, x, newY, health, jumpPressed, tl, wallList, game)
end)
| [] =>
checkWalls (yAxis, xAxis, x, y, health, jumpPressed, wallList, game)
end
(*** MLTON STRANGE TYPES ERROR:
*** Trigger by deleting the longer `checkPlatforms` function
*** and uncommenting the function of the same name that raises Match.
fun checkPlatforms (yAxis, xAxis, x, y, health, jumpPressed, game) =
raise Match
*** *)
fun checkPlatforms (yAxis, xAxis, x, y, health, jumpPressed, game) =
let
val {wallTree, platformTree, ...} = game
val platCollisions = QuadTree.getCollisionsBelow
(y, y, size, size, 0, 0, 1920, 1080, 0, wallTree)
val wallCollisions = QuadTree.getCollisionSides
(y, y, size, size, 0, 0, 1920, 1080, 0, wallTree)
in
helpCheckPlatforms
( yAxis, xAxis, x, y, health, jumpPressed
, platCollisions, wallCollisions, game
)
end
fun helpMove (x, y, xAxis, yAxis, health, jumpPressed, game: game_type) =
@@ -70,99 +122,48 @@ struct
in
case yAxis of
ON_GROUND =>
let
val collisions = QuadTree.getCollisionSides
(desiredX, y, size, size, 0, 0, 1920, 1080, 0, #wallTree game)
in
checkWalls
(yAxis, xAxis, desiredX, y, health, jumpPressed, collisions, game)
end
checkPlatforms
(yAxis, xAxis, desiredX, y, health, jumpPressed, game)
| FLOATING floated =>
let
val collisions = QuadTree.getCollisionSides
(desiredX, y, size, size, 0, 0, 1920, 1080, 0, #wallTree game)
val yAxis =
if floated = floatLimit then FALLING else FLOATING (floated + 1)
in
checkWalls
(yAxis, xAxis, desiredX, y, health, jumpPressed, collisions, game)
checkPlatforms
(yAxis, xAxis, desiredX, y, health, jumpPressed, game)
end
| FALLING =>
let
val desiredY = y + moveBy
val collisions = QuadTree.getCollisionSides
( desiredX
, desiredY
, size
, size
, 0
, 0
, 1920
, 1080
, 0
, #wallTree game
)
in
checkWalls
( yAxis
, xAxis
, desiredX
, desiredY
, health
, jumpPressed
, collisions
, game
)
checkPlatforms
(yAxis, xAxis, desiredX, desiredY, health, jumpPressed, game)
end
| DROP_BELOW_PLATFORM =>
let
val desiredY = y + moveBy
in
checkPlatforms
(yAxis, xAxis, desiredX, desiredY, health, jumpPressed, game)
end
| JUMPING jumped =>
if jumped + moveBy > jumpLimit then
(* if we are above the jump limit, trigger a fall *)
let
val collisions = QuadTree.getCollisionSides
(desiredX, y, size, size, 0, 0, 1920, 1080, 0, #wallTree game)
val newYAxis = FLOATING 0
in
checkWalls
( FLOATING 0
, xAxis
, desiredX
, y
, health
, jumpPressed
, collisions
, game
)
checkPlatforms
(newYAxis, xAxis, desiredX, y, health, jumpPressed, game)
end
else
(* jump *)
let
val newJumped = jumped + moveBy
val yAxis = JUMPING newJumped
val newYAxis = JUMPING newJumped
val desiredY = y - moveBy
val collisions = QuadTree.getCollisionSides
( desiredX
, desiredY
, size
, size
, 0
, 0
, 1920
, 1080
, 0
, #wallTree game
)
in
checkWalls
( yAxis
, xAxis
, desiredX
, desiredY
, health
, jumpPressed
, collisions
, game
)
checkPlatforms
(newYAxis, xAxis, desiredX, desiredY, health, jumpPressed, game)
end
end