add xAxis and yAxis fields to enemy type
This commit is contained in:
@@ -4,7 +4,7 @@ struct
|
|||||||
* to adjust enemy data on collision with projectile *)
|
* to adjust enemy data on collision with projectile *)
|
||||||
fun onCollisionWithProjectile (enemy, projectileTree, acc) =
|
fun onCollisionWithProjectile (enemy, projectileTree, acc) =
|
||||||
let
|
let
|
||||||
val {x, y, health, id} = enemy
|
val {x, y, health, id, xAxis, yAxis} = enemy
|
||||||
|
|
||||||
val size = Constants.enemySize
|
val size = Constants.enemySize
|
||||||
val ww = Constants.worldWidth
|
val ww = Constants.worldWidth
|
||||||
@@ -18,7 +18,13 @@ struct
|
|||||||
(* filter out if decrementing health by one = 0 *)
|
(* filter out if decrementing health by one = 0 *)
|
||||||
acc
|
acc
|
||||||
else
|
else
|
||||||
{health = health - 1, x = x, y = y, id = id} :: acc
|
{ health = health - 1
|
||||||
|
, x = x
|
||||||
|
, y = y
|
||||||
|
, id = id
|
||||||
|
, xAxis = xAxis
|
||||||
|
, yAxis = yAxis
|
||||||
|
} :: acc
|
||||||
else
|
else
|
||||||
enemy :: acc
|
enemy :: acc
|
||||||
end
|
end
|
||||||
@@ -28,7 +34,8 @@ struct
|
|||||||
acc
|
acc
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val {id, x, y, health = _} = Vector.sub (enemyVec, pos)
|
val {id, x, y, health = _, xAxis = _, yAxis = _} =
|
||||||
|
Vector.sub (enemyVec, pos)
|
||||||
|
|
||||||
val size = Constants.enemySize
|
val size = Constants.enemySize
|
||||||
val ww = Constants.worldWidth
|
val ww = Constants.worldWidth
|
||||||
@@ -46,7 +53,7 @@ struct
|
|||||||
let
|
let
|
||||||
val mid = low + ((high - low) div 2)
|
val mid = low + ((high - low) div 2)
|
||||||
val enemy = Vector.sub (vec, mid)
|
val enemy = Vector.sub (vec, mid)
|
||||||
val {id = curNum, x = _, y = _, health = _} = enemy
|
val {id = curNum, x = _, y = _, health = _, xAxis = _, yAxis = _} = enemy
|
||||||
in
|
in
|
||||||
if curNum = findNum then enemy
|
if curNum = findNum then enemy
|
||||||
else if curNum < findNum then helpFind (findNum, vec, mid + 1, high)
|
else if curNum < findNum then helpFind (findNum, vec, mid + 1, high)
|
||||||
@@ -56,8 +63,9 @@ struct
|
|||||||
fun find (findNum, vec) =
|
fun find (findNum, vec) =
|
||||||
helpFind (findNum, vec, 0, Vector.length vec - 1)
|
helpFind (findNum, vec, 0, Vector.length vec - 1)
|
||||||
|
|
||||||
fun helpGetDrawVec ({x, y, id = _, health = _}, width, height) =
|
fun helpGetDrawVec (enemy, width, height) =
|
||||||
let
|
let
|
||||||
|
val {x, y, id = _, health = _, xAxis = _, yAxis = _} = enemy
|
||||||
val wratio = width / Constants.worldWidthReal
|
val wratio = width / Constants.worldWidthReal
|
||||||
val hratio = height / Constants.worldHeightReal
|
val hratio = height / Constants.worldHeightReal
|
||||||
in
|
in
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ sig
|
|||||||
| W_CHARGE of int
|
| W_CHARGE of int
|
||||||
| W_PROJECTILES of player_projectile vector
|
| W_PROJECTILES of player_projectile vector
|
||||||
|
|
||||||
type enemy = {id: int, health: int, x: int, y: int}
|
type enemy =
|
||||||
|
{id: int, health: int, x: int, y: int, xAxis: x_axis, yAxis: y_axis}
|
||||||
|
|
||||||
type game_type =
|
type game_type =
|
||||||
{ player: player
|
{ player: player
|
||||||
@@ -139,7 +140,8 @@ struct
|
|||||||
| W_CHARGE of int
|
| W_CHARGE of int
|
||||||
| W_PROJECTILES of player_projectile vector
|
| W_PROJECTILES of player_projectile vector
|
||||||
|
|
||||||
type enemy = {id: int, health: int, x: int, y: int}
|
type enemy =
|
||||||
|
{id: int, health: int, x: int, y: int, xAxis: x_axis, yAxis: y_axis}
|
||||||
|
|
||||||
type game_type =
|
type game_type =
|
||||||
{ player: player
|
{ player: player
|
||||||
@@ -179,9 +181,30 @@ struct
|
|||||||
val platforms = Vector.fromList [plat1]
|
val platforms = Vector.fromList [plat1]
|
||||||
val platformTree = Platform.generateTree platforms
|
val platformTree = Platform.generateTree platforms
|
||||||
|
|
||||||
val enemy1 = {id = 1, x = 300, y = 945, health = 5}
|
val enemy1 =
|
||||||
val enemy2 = {id = 2, x = 555, y = 945, health = 5}
|
{ id = 1
|
||||||
val enemy3 = {id = 3, x = 979, y = 945, health = 5}
|
, x = 300
|
||||||
|
, y = 945
|
||||||
|
, health = 5
|
||||||
|
, xAxis = STAY_STILL
|
||||||
|
, yAxis = ON_GROUND
|
||||||
|
}
|
||||||
|
val enemy2 =
|
||||||
|
{ id = 2
|
||||||
|
, x = 555
|
||||||
|
, y = 945
|
||||||
|
, health = 5
|
||||||
|
, xAxis = STAY_STILL
|
||||||
|
, yAxis = ON_GROUND
|
||||||
|
}
|
||||||
|
val enemy3 =
|
||||||
|
{ id = 3
|
||||||
|
, x = 979
|
||||||
|
, y = 945
|
||||||
|
, health = 5
|
||||||
|
, xAxis = STAY_STILL
|
||||||
|
, yAxis = ON_GROUND
|
||||||
|
}
|
||||||
val enemies = Vector.fromList [enemy1, enemy2, enemy3]
|
val enemies = Vector.fromList [enemy1, enemy2, enemy3]
|
||||||
in
|
in
|
||||||
{ player = player
|
{ player = player
|
||||||
|
|||||||
Reference in New Issue
Block a user