restore working collision detection code to player's attack
This commit is contained in:
@@ -32,6 +32,10 @@ struct
|
|||||||
val projectileDistance: Real32.real = 26.0
|
val projectileDistance: Real32.real = 26.0
|
||||||
val projectileSizeInt = 18
|
val projectileSizeInt = 18
|
||||||
|
|
||||||
|
val projectileHeight = 24
|
||||||
|
val projectileWidth = 96
|
||||||
|
val projectileOffsetY = playerHeight div 3
|
||||||
|
|
||||||
(* constants for enemy *)
|
(* constants for enemy *)
|
||||||
val enemySize = 48
|
val enemySize = 48
|
||||||
val enemySizeReal: Real32.real = 48.0
|
val enemySizeReal: Real32.real = 48.0
|
||||||
|
|||||||
@@ -52,63 +52,69 @@ struct
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
fun helpAttackEnemies
|
fun helpAttackEnemies
|
||||||
(player, defeatedList, enemyMap, fallingMap, enemyTree, pos, boxes) =
|
(projectileX, projectileY, enemyMap, enemyTree, fallingMap, player) =
|
||||||
if pos = Vector.length boxes then
|
let
|
||||||
let
|
val width = Constants.projectileWidth
|
||||||
val defeatedList = Vector.fromList defeatedList
|
val height = Constants.projectileHeight
|
||||||
val defeatedList = Vector.concat [defeatedList, #enemies player]
|
|
||||||
|
|
||||||
val player =
|
val (defeatedList, enemyMap) = PlayerAttackEnemy.foldRegion
|
||||||
PlayerPatch.withPatch (player, PlayerPatch.W_ENEMIES defeatedList)
|
(projectileX, projectileY, width, height, (), ([], enemyMap), enemyTree)
|
||||||
in
|
|
||||||
(player, enemyMap, fallingMap)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val {x = px, y = py, ...} = player
|
|
||||||
val {x = bx, y = by} = Vector.sub (boxes, pos)
|
|
||||||
|
|
||||||
val x = px + bx
|
val fallingTree = FallingEnemies.generateTree fallingMap
|
||||||
val y = py + by
|
val (defeatedList, fallingMap) = PlayerAttackFalling.foldRegion
|
||||||
val size = Whip.size
|
( projectileX
|
||||||
|
, projectileY
|
||||||
|
, width
|
||||||
|
, height
|
||||||
|
, ()
|
||||||
|
, (defeatedList, fallingMap)
|
||||||
|
, fallingTree
|
||||||
|
)
|
||||||
|
|
||||||
val (defeatedList, enemyMap) = PlayerAttackEnemy.foldRegion
|
val defeatedList = Vector.fromList defeatedList
|
||||||
(x, y, size, size, (), (defeatedList, enemyMap), enemyTree)
|
val player =
|
||||||
|
PlayerPatch.withPatch (player, PlayerPatch.W_ENEMIES defeatedList)
|
||||||
val fallingTree = FallingEnemies.generateTree fallingMap
|
in
|
||||||
val (defeatedList, fallingMap) = PlayerAttackFalling.foldRegion
|
(player, enemyMap, fallingMap)
|
||||||
(x, y, size, size, (), (defeatedList, fallingMap), fallingTree)
|
end
|
||||||
in
|
|
||||||
helpAttackEnemies
|
|
||||||
( player
|
|
||||||
, defeatedList
|
|
||||||
, enemyMap
|
|
||||||
, fallingMap
|
|
||||||
, enemyTree
|
|
||||||
, pos + 1
|
|
||||||
, boxes
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
fun attackEnemies (player: PlayerType.player, enemyMap, enemyTree, fallingMap) =
|
fun attackEnemies (player: PlayerType.player, enemyMap, enemyTree, fallingMap) =
|
||||||
let
|
let
|
||||||
open PlayerType
|
open PlayerType
|
||||||
|
open EntityType
|
||||||
val {x, y, facing, mainAttack, ...} = player
|
val {x, y, facing, mainAttack, ...} = player
|
||||||
in
|
in
|
||||||
case mainAttack of
|
case mainAttack of
|
||||||
MAIN_ATTACKING amt =>
|
MAIN_ATTACKING _ =>
|
||||||
let
|
(case facing of
|
||||||
open EntityType
|
FACING_RIGHT =>
|
||||||
val frame = amt div 2
|
let
|
||||||
|
val projectileX = x + Constants.playerWidth
|
||||||
val boxes =
|
val projectileY = y + Constants.projectileOffsetY
|
||||||
case facing of
|
in
|
||||||
FACING_RIGHT => Vector.sub (Whip.rightFrames, frame)
|
helpAttackEnemies
|
||||||
| FACING_LEFT => Vector.sub (Whip.leftFrames, frame)
|
( projectileX
|
||||||
in
|
, projectileY
|
||||||
helpAttackEnemies
|
, enemyMap
|
||||||
(player, [], enemyMap, fallingMap, enemyTree, 0, boxes)
|
, enemyTree
|
||||||
end
|
, fallingMap
|
||||||
|
, player
|
||||||
|
)
|
||||||
|
end
|
||||||
|
| FACING_LEFT =>
|
||||||
|
let
|
||||||
|
val projectileX = x - Constants.projectileWidth
|
||||||
|
val projectileY = y + Constants.projectileOffsetY
|
||||||
|
in
|
||||||
|
helpAttackEnemies
|
||||||
|
( projectileX
|
||||||
|
, projectileY
|
||||||
|
, enemyMap
|
||||||
|
, enemyTree
|
||||||
|
, fallingMap
|
||||||
|
, player
|
||||||
|
)
|
||||||
|
end)
|
||||||
| _ => (player, enemyMap, fallingMap)
|
| _ => (player, enemyMap, fallingMap)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ struct
|
|||||||
(* adding playerWidth to x so that projectile starts from
|
(* adding playerWidth to x so that projectile starts from
|
||||||
* the rightmost pixel of the player *)
|
* the rightmost pixel of the player *)
|
||||||
val projX = x + Constants.playerWidth
|
val projX = x + Constants.playerWidth
|
||||||
val projY = y + (Constants.playerHeight div 3)
|
val projY = y + Constants.projectileOffsetY
|
||||||
val projX = (Real32.fromInt projX + xOffset) * ratio
|
val projX = (Real32.fromInt projX + xOffset) * ratio
|
||||||
val projY = (Real32.fromInt projY + yOffset) * ratio
|
val projY = (Real32.fromInt projY + yOffset) * ratio
|
||||||
|
|
||||||
@@ -173,12 +173,10 @@ struct
|
|||||||
val playerVec = PlayerAttackStandLeft.lerp
|
val playerVec = PlayerAttackStandLeft.lerp
|
||||||
(rx, ry, 3.0, windowWidth, windowHeight)
|
(rx, ry, 3.0, windowWidth, windowHeight)
|
||||||
|
|
||||||
(* subtracting playerHeight from x because projectile
|
(* subtracting projectileWidth from x it looks like
|
||||||
* is the same size as the playerHeight, and it looks like
|
* the projectile starts from player's leftmost side this way. *)
|
||||||
* the projectile starts from player's leftmost side this way.
|
val projX = x - Constants.projectileWidth
|
||||||
* *)
|
val projY = y + Constants.projectileOffsetY
|
||||||
val projX = x - Constants.playerHeight
|
|
||||||
val projY = y + (Constants.playerHeight div 3)
|
|
||||||
val projX = (Real32.fromInt projX + xOffset) * ratio
|
val projX = (Real32.fromInt projX + xOffset) * ratio
|
||||||
val projY = (Real32.fromInt projY + yOffset) * ratio
|
val projY = (Real32.fromInt projY + yOffset) * ratio
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user