draw basic field over player when player is attacking

This commit is contained in:
2024-12-28 04:06:27 +00:00
parent fccbb15f15
commit 5f437ae76d
5 changed files with 162 additions and 6 deletions

26
fcore/field.sml Normal file
View File

@@ -0,0 +1,26 @@
structure Field =
struct
fun lerp (startX, startY, drawWidth, drawHeight, windowWidth, windowHeight
, r, g, b, a) : Real32.real vector =
let
val endY = windowHeight - startY
val startY = windowHeight - (startY + drawHeight)
val endX = startX + drawWidth
val windowHeight = windowHeight / 2.0
val windowWidth = windowWidth / 2.0
in
#[ (((startX * (1.0 - 1.0)) + (endX * 1.0)) / windowWidth) - 1.0,
(((startY * (1.0 - 0.0)) + (endY * 0.0)) / windowHeight) - 1.0, r, g, b, a,
(((startX * (1.0 - 0.0)) + (endX * 0.0)) / windowWidth) - 1.0,
(((startY * (1.0 - 0.0)) + (endY * 0.0)) / windowHeight) - 1.0, r, g, b, a,
(((startX * (1.0 - 0.0)) + (endX * 0.0)) / windowWidth) - 1.0,
(((startY * (1.0 - 1.0)) + (endY * 1.0)) / windowHeight) - 1.0, r, g, b, a,
(((startX * (1.0 - 0.0)) + (endX * 0.0)) / windowWidth) - 1.0,
(((startY * (1.0 - 1.0)) + (endY * 1.0)) / windowHeight) - 1.0, r, g, b, a,
(((startX * (1.0 - 1.0)) + (endX * 1.0)) / windowWidth) - 1.0,
(((startY * (1.0 - 1.0)) + (endY * 1.0)) / windowHeight) - 1.0, r, g, b, a,
(((startX * (1.0 - 1.0)) + (endX * 1.0)) / windowWidth) - 1.0,
(((startY * (1.0 - 0.0)) + (endY * 0.0)) / windowHeight) - 1.0, r, g, b, a
]
end
end

View File

@@ -242,6 +242,9 @@ struct
val size = 35
val realSize = 35.0
val halfSize = 35 div 2
val halfRealSize = 35.0 / 2.0
val moveBy = 5
(* timing variables; always start at 0,
@@ -659,4 +662,49 @@ struct
helpGetDrawVec (x, y, realSize, width, height, attacked, mainAttack)
end
end
fun getFieldVec (player: player, width, height) =
case #mainAttack player of
MAIN_NOT_ATTACKING => Vector.fromList []
| MAIN_ATTACKING amt =>
let
val {x, y, ...} = player
val wratio = width / 1920.0
val hratio = height / 1080.0
in
if wratio < hratio then
let
val scale = 1080.0 * wratio
val yOffset =
if height > scale then (height - scale) / 2.0
else if height < scale then (scale - height) / 2.0
else 0.0
val x = (Real32.fromInt x - halfRealSize) * wratio
val y = (Real32.fromInt y - halfRealSize) * wratio + yOffset
val realSize = (realSize * 2.0) * wratio
val alpha = Real32.fromInt amt / Real32.fromInt mainAttackLimit
in
Field.lerp
(x, y, realSize, realSize, width, height, 0.7, 0.7, 1.0, alpha)
end
else
let
val scale = 1920.0 * hratio
val xOffset =
if width > scale then (width - scale) / 2.0
else if width < scale then (scale - width) / 2.0
else 0.0
val x = (Real32.fromInt x - halfRealSize) * hratio + xOffset
val y = (Real32.fromInt y - halfRealSize) * hratio
val realSize = (realSize * 2.0) * hratio
val alpha = Real32.fromInt amt / Real32.fromInt mainAttackLimit
in
Field.lerp
(x, y, realSize, realSize, width, height, 0.7, 0.7, 1.0, alpha)
end
end
end