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:
@@ -7,6 +7,7 @@ sig
|
|||||||
datatype player_y_axis =
|
datatype player_y_axis =
|
||||||
ON_GROUND
|
ON_GROUND
|
||||||
| FALLING
|
| FALLING
|
||||||
|
| DROP_BELOW_PLATFORM
|
||||||
| JUMPING of int
|
| JUMPING of int
|
||||||
| FLOATING of int
|
| FLOATING of int
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ struct
|
|||||||
datatype player_y_axis =
|
datatype player_y_axis =
|
||||||
ON_GROUND
|
ON_GROUND
|
||||||
| FALLING
|
| FALLING
|
||||||
|
| DROP_BELOW_PLATFORM
|
||||||
| JUMPING of int
|
| JUMPING of int
|
||||||
| FLOATING of int
|
| FLOATING of int
|
||||||
|
|
||||||
|
|||||||
143
fcore/player.sml
143
fcore/player.sml
@@ -56,7 +56,59 @@ struct
|
|||||||
end
|
end
|
||||||
| (QUERY_ON_TOP_SIDE, wallID) :: tl =>
|
| (QUERY_ON_TOP_SIDE, wallID) :: tl =>
|
||||||
checkWalls (yAxis, xAxis, x, y, health, jumpPressed, tl, game)
|
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
|
end
|
||||||
|
|
||||||
fun helpMove (x, y, xAxis, yAxis, health, jumpPressed, game: game_type) =
|
fun helpMove (x, y, xAxis, yAxis, health, jumpPressed, game: game_type) =
|
||||||
@@ -70,99 +122,48 @@ struct
|
|||||||
in
|
in
|
||||||
case yAxis of
|
case yAxis of
|
||||||
ON_GROUND =>
|
ON_GROUND =>
|
||||||
let
|
checkPlatforms
|
||||||
val collisions = QuadTree.getCollisionSides
|
(yAxis, xAxis, desiredX, y, health, jumpPressed, game)
|
||||||
(desiredX, y, size, size, 0, 0, 1920, 1080, 0, #wallTree game)
|
|
||||||
in
|
|
||||||
checkWalls
|
|
||||||
(yAxis, xAxis, desiredX, y, health, jumpPressed, collisions, game)
|
|
||||||
end
|
|
||||||
| FLOATING floated =>
|
| FLOATING floated =>
|
||||||
let
|
let
|
||||||
val collisions = QuadTree.getCollisionSides
|
|
||||||
(desiredX, y, size, size, 0, 0, 1920, 1080, 0, #wallTree game)
|
|
||||||
|
|
||||||
val yAxis =
|
val yAxis =
|
||||||
if floated = floatLimit then FALLING else FLOATING (floated + 1)
|
if floated = floatLimit then FALLING else FLOATING (floated + 1)
|
||||||
in
|
in
|
||||||
checkWalls
|
checkPlatforms
|
||||||
(yAxis, xAxis, desiredX, y, health, jumpPressed, collisions, game)
|
(yAxis, xAxis, desiredX, y, health, jumpPressed, game)
|
||||||
end
|
end
|
||||||
| FALLING =>
|
| FALLING =>
|
||||||
let
|
let
|
||||||
val desiredY = y + moveBy
|
val desiredY = y + moveBy
|
||||||
val collisions = QuadTree.getCollisionSides
|
|
||||||
( desiredX
|
|
||||||
, desiredY
|
|
||||||
, size
|
|
||||||
, size
|
|
||||||
, 0
|
|
||||||
, 0
|
|
||||||
, 1920
|
|
||||||
, 1080
|
|
||||||
, 0
|
|
||||||
, #wallTree game
|
|
||||||
)
|
|
||||||
in
|
in
|
||||||
checkWalls
|
checkPlatforms
|
||||||
( yAxis
|
(yAxis, xAxis, desiredX, desiredY, health, jumpPressed, game)
|
||||||
, xAxis
|
end
|
||||||
, desiredX
|
| DROP_BELOW_PLATFORM =>
|
||||||
, desiredY
|
let
|
||||||
, health
|
val desiredY = y + moveBy
|
||||||
, jumpPressed
|
in
|
||||||
, collisions
|
checkPlatforms
|
||||||
, game
|
(yAxis, xAxis, desiredX, desiredY, health, jumpPressed, game)
|
||||||
)
|
|
||||||
end
|
end
|
||||||
| JUMPING jumped =>
|
| JUMPING jumped =>
|
||||||
if jumped + moveBy > jumpLimit then
|
if jumped + moveBy > jumpLimit then
|
||||||
(* if we are above the jump limit, trigger a fall *)
|
(* if we are above the jump limit, trigger a fall *)
|
||||||
let
|
let
|
||||||
val collisions = QuadTree.getCollisionSides
|
val newYAxis = FLOATING 0
|
||||||
(desiredX, y, size, size, 0, 0, 1920, 1080, 0, #wallTree game)
|
|
||||||
in
|
in
|
||||||
checkWalls
|
checkPlatforms
|
||||||
( FLOATING 0
|
(newYAxis, xAxis, desiredX, y, health, jumpPressed, game)
|
||||||
, xAxis
|
|
||||||
, desiredX
|
|
||||||
, y
|
|
||||||
, health
|
|
||||||
, jumpPressed
|
|
||||||
, collisions
|
|
||||||
, game
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
(* jump *)
|
(* jump *)
|
||||||
let
|
let
|
||||||
val newJumped = jumped + moveBy
|
val newJumped = jumped + moveBy
|
||||||
val yAxis = JUMPING newJumped
|
val newYAxis = JUMPING newJumped
|
||||||
val desiredY = y - moveBy
|
val desiredY = y - moveBy
|
||||||
|
|
||||||
val collisions = QuadTree.getCollisionSides
|
|
||||||
( desiredX
|
|
||||||
, desiredY
|
|
||||||
, size
|
|
||||||
, size
|
|
||||||
, 0
|
|
||||||
, 0
|
|
||||||
, 1920
|
|
||||||
, 1080
|
|
||||||
, 0
|
|
||||||
, #wallTree game
|
|
||||||
)
|
|
||||||
in
|
in
|
||||||
checkWalls
|
checkPlatforms
|
||||||
( yAxis
|
(newYAxis, xAxis, desiredX, desiredY, health, jumpPressed, game)
|
||||||
, xAxis
|
|
||||||
, desiredX
|
|
||||||
, desiredY
|
|
||||||
, health
|
|
||||||
, jumpPressed
|
|
||||||
, collisions
|
|
||||||
, game
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user