add collision detection for whip attack
This commit is contained in:
@@ -51,36 +51,18 @@ struct
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
fun attackEnemies (player: PlayerType.player, enemyMap, enemyTree, fallingMap) =
|
fun helpAttackEnemies
|
||||||
let
|
( player
|
||||||
open PlayerType
|
, defeatedList
|
||||||
val {x, y, facing, mainAttack, ...} = player
|
, enemyMap
|
||||||
in
|
, fallingMap
|
||||||
(* todo: bring back attack
|
|
||||||
case mainAttack of
|
|
||||||
MAIN_ATTACKING {length, ...} =>
|
|
||||||
let
|
|
||||||
open EntityType
|
|
||||||
val height = Constants.playerHeight
|
|
||||||
val x =
|
|
||||||
(case facing of
|
|
||||||
FACING_RIGHT => x + Constants.playerWidth
|
|
||||||
| FACING_LEFT => x - length)
|
|
||||||
|
|
||||||
val (defeatedList, enemyMap) = PlayerAttackEnemy.foldRegion
|
|
||||||
(x, y, length, height, (), ([], enemyMap), enemyTree)
|
|
||||||
|
|
||||||
val fallingTree = FallingEnemies.generateTree fallingMap
|
|
||||||
val (defeatedList, fallingMap) = PlayerAttackFalling.foldRegion
|
|
||||||
( x
|
|
||||||
, y
|
|
||||||
, length
|
|
||||||
, height
|
|
||||||
, ()
|
|
||||||
, (defeatedList, fallingMap)
|
|
||||||
, fallingTree
|
, fallingTree
|
||||||
)
|
, enemyTree
|
||||||
|
, pos
|
||||||
|
, boxes
|
||||||
|
) =
|
||||||
|
if pos = Vector.length boxes then
|
||||||
|
let
|
||||||
val defeatedList = Vector.fromList defeatedList
|
val defeatedList = Vector.fromList defeatedList
|
||||||
val defeatedList = Vector.concat [defeatedList, #enemies player]
|
val defeatedList = Vector.concat [defeatedList, #enemies player]
|
||||||
|
|
||||||
@@ -89,9 +71,63 @@ struct
|
|||||||
in
|
in
|
||||||
(player, enemyMap, fallingMap)
|
(player, enemyMap, fallingMap)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val {x = px, y = py, ...} = player
|
||||||
|
val {x = bx, y = by} = Vector.sub (boxes, pos)
|
||||||
|
|
||||||
|
val x = px + bx
|
||||||
|
val y = py + by
|
||||||
|
val size = Whip.size
|
||||||
|
|
||||||
|
val (defeatedList, enemyMap) = PlayerAttackEnemy.foldRegion
|
||||||
|
(x, y, size, size, (), (defeatedList, enemyMap), enemyTree)
|
||||||
|
|
||||||
|
val (defeatedList, fallingMap) = PlayerAttackFalling.foldRegion
|
||||||
|
(x, y, size, size, (), (defeatedList, fallingMap), fallingTree)
|
||||||
|
in
|
||||||
|
helpAttackEnemies
|
||||||
|
( player
|
||||||
|
, defeatedList
|
||||||
|
, enemyMap
|
||||||
|
, fallingMap
|
||||||
|
, fallingTree
|
||||||
|
, enemyTree
|
||||||
|
, pos + 1
|
||||||
|
, boxes
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun attackEnemies (player: PlayerType.player, enemyMap, enemyTree, fallingMap) =
|
||||||
|
let
|
||||||
|
open PlayerType
|
||||||
|
val {x, y, facing, mainAttack, ...} = player
|
||||||
|
in
|
||||||
|
case mainAttack of
|
||||||
|
MAIN_ATTACKING amt =>
|
||||||
|
let
|
||||||
|
open EntityType
|
||||||
|
val frame = amt div 2
|
||||||
|
val fallingTree = FallingEnemies.generateTree fallingMap
|
||||||
|
val boxes =
|
||||||
|
case facing of
|
||||||
|
FACING_RIGHT => Vector.sub (Whip.rightFrames, frame)
|
||||||
|
| FACING_LEFT =>
|
||||||
|
(* todo: replace rightFrames with leftFrames *)
|
||||||
|
Vector.sub (Whip.rightFrames, frame)
|
||||||
|
in
|
||||||
|
helpAttackEnemies
|
||||||
|
( player
|
||||||
|
, []
|
||||||
|
, enemyMap
|
||||||
|
, fallingMap
|
||||||
|
, fallingTree
|
||||||
|
, enemyTree
|
||||||
|
, 0
|
||||||
|
, boxes
|
||||||
|
)
|
||||||
|
end
|
||||||
| _ => (player, enemyMap, fallingMap)
|
| _ => (player, enemyMap, fallingMap)
|
||||||
*)
|
|
||||||
(player, enemyMap, fallingMap)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
(* - Handle collisions when player's projectile hits enemy - *)
|
(* - Handle collisions when player's projectile hits enemy - *)
|
||||||
|
|||||||
@@ -86,10 +86,8 @@ struct
|
|||||||
fun helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc) =
|
fun helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc) =
|
||||||
let
|
let
|
||||||
val attack =
|
val attack =
|
||||||
if attackHeld andalso not mainAttackPressed then
|
if attackHeld andalso not mainAttackPressed then MAIN_ATTACKING 1
|
||||||
MAIN_ATTACKING 1
|
else MAIN_NOT_ATTACKING
|
||||||
else
|
|
||||||
MAIN_NOT_ATTACKING
|
|
||||||
in
|
in
|
||||||
W_MAIN_ATTACK_PRESSED (attackHeld andalso mainAttackPressed)
|
W_MAIN_ATTACK_PRESSED (attackHeld andalso mainAttackPressed)
|
||||||
:: W_MAIN_ATTACK attack :: acc
|
:: W_MAIN_ATTACK attack :: acc
|
||||||
@@ -165,10 +163,8 @@ struct
|
|||||||
if amt = Constants.mainAttackLimit then
|
if amt = Constants.mainAttackLimit then
|
||||||
W_MAIN_ATTACK MAIN_NOT_ATTACKING :: acc
|
W_MAIN_ATTACK MAIN_NOT_ATTACKING :: acc
|
||||||
else
|
else
|
||||||
let
|
let val amt = amt + 1
|
||||||
val amt = amt + 1
|
in W_MAIN_ATTACK (MAIN_ATTACKING amt) :: acc
|
||||||
in
|
|
||||||
W_MAIN_ATTACK (MAIN_ATTACKING amt) :: acc
|
|
||||||
end
|
end
|
||||||
in
|
in
|
||||||
W_MAIN_ATTACK_PRESSED true :: acc
|
W_MAIN_ATTACK_PRESSED true :: acc
|
||||||
@@ -423,9 +419,7 @@ struct
|
|||||||
in
|
in
|
||||||
if oldYAxis = DROP_BELOW_PLATFORM andalso newYAxis = DROP_BELOW_PLATFORM then
|
if oldYAxis = DROP_BELOW_PLATFORM andalso newYAxis = DROP_BELOW_PLATFORM then
|
||||||
PlayerPatch.withPatch (player, W_ANIM_TIMER (oldAnimTimer + 1))
|
PlayerPatch.withPatch (player, W_ANIM_TIMER (oldAnimTimer + 1))
|
||||||
else if
|
else if oldYAxis = ON_GROUND andalso newYAxis = ON_GROUND then
|
||||||
oldYAxis = ON_GROUND andalso newYAxis = ON_GROUND
|
|
||||||
then
|
|
||||||
if oldXAxis = MOVE_RIGHT andalso newXAxis = MOVE_RIGHT then
|
if oldXAxis = MOVE_RIGHT andalso newXAxis = MOVE_RIGHT then
|
||||||
(* update move-right animation *)
|
(* update move-right animation *)
|
||||||
PlayerPatch.withPatch (player, W_ANIM_TIMER (oldAnimTimer + 1))
|
PlayerPatch.withPatch (player, W_ANIM_TIMER (oldAnimTimer + 1))
|
||||||
@@ -458,7 +452,8 @@ struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
(*** DRAWING FUNCTIONS ***)
|
(*** DRAWING FUNCTIONS ***)
|
||||||
fun helpGetWhipVec (tlx, tly, ratio, xOffset, yOffset, pos, boxes, width, height, acc) =
|
fun helpGetWhipVec
|
||||||
|
(tlx, tly, ratio, xOffset, yOffset, pos, boxes, width, height, acc) =
|
||||||
if pos = Vector.length boxes then
|
if pos = Vector.length boxes then
|
||||||
Vector.concat acc
|
Vector.concat acc
|
||||||
else
|
else
|
||||||
@@ -473,7 +468,18 @@ struct
|
|||||||
val size = Whip.sizeReal
|
val size = Whip.sizeReal
|
||||||
val acc = Box.lerp (x, y, size, size, width, height) :: acc
|
val acc = Box.lerp (x, y, size, size, width, height) :: acc
|
||||||
in
|
in
|
||||||
helpGetWhipVec (tlx, tly, ratio, xOffset, yOffset, pos + 1, boxes, width, height, acc)
|
helpGetWhipVec
|
||||||
|
( tlx
|
||||||
|
, tly
|
||||||
|
, ratio
|
||||||
|
, xOffset
|
||||||
|
, yOffset
|
||||||
|
, pos + 1
|
||||||
|
, boxes
|
||||||
|
, width
|
||||||
|
, height
|
||||||
|
, acc
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun getFieldVec (player: player, width, height) =
|
fun getFieldVec (player: player, width, height) =
|
||||||
@@ -495,13 +501,13 @@ struct
|
|||||||
|
|
||||||
val boxes =
|
val boxes =
|
||||||
case facing of
|
case facing of
|
||||||
FACING_RIGHT =>
|
FACING_RIGHT => Vector.sub (Whip.rightFrames, frame)
|
||||||
Vector.sub (Whip.rightFrames, frame)
|
|
||||||
| FACING_LEFT =>
|
| FACING_LEFT =>
|
||||||
(* todo: change to leftFrames once that is implemented *)
|
(* todo: change to leftFrames once that is implemented *)
|
||||||
Vector.sub (Whip.rightFrames, frame)
|
Vector.sub (Whip.rightFrames, frame)
|
||||||
in
|
in
|
||||||
helpGetWhipVec (x, y, wratio, 0.0, yOffset, 0, boxes, width, height, [])
|
helpGetWhipVec
|
||||||
|
(x, y, wratio, 0.0, yOffset, 0, boxes, width, height, [])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
@@ -513,13 +519,13 @@ struct
|
|||||||
|
|
||||||
val boxes =
|
val boxes =
|
||||||
case facing of
|
case facing of
|
||||||
FACING_RIGHT =>
|
FACING_RIGHT => Vector.sub (Whip.rightFrames, frame)
|
||||||
Vector.sub (Whip.rightFrames, frame)
|
|
||||||
| FACING_LEFT =>
|
| FACING_LEFT =>
|
||||||
(* todo: change to leftFrames once that is implemented *)
|
(* todo: change to leftFrames once that is implemented *)
|
||||||
Vector.sub (Whip.rightFrames, frame)
|
Vector.sub (Whip.rightFrames, frame)
|
||||||
in
|
in
|
||||||
helpGetWhipVec (x, y, hratio, xOffset, 0.0, 0, boxes, width, height, [])
|
helpGetWhipVec
|
||||||
|
(x, y, hratio, xOffset, 0.0, 0, boxes, width, height, [])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
| _ => Vector.fromList []
|
| _ => Vector.fromList []
|
||||||
|
|||||||
Reference in New Issue
Block a user