diff --git a/fcore/level/player/player-vec.sml b/fcore/level/player/player-vec.sml new file mode 100644 index 0000000..7753379 --- /dev/null +++ b/fcore/level/player/player-vec.sml @@ -0,0 +1,120 @@ +structure PlayerVec = +struct + open EntityType + open PlayerType + + val walkRightFrames = + #[ PlayerWalkRight1.lerp + , PlayerWalkRight2.lerp + , PlayerWalkRight3.lerp + , PlayerWalkRight4.lerp + , PlayerWalkRight5.lerp + , PlayerWalkRight6.lerp + , PlayerWalkRight7.lerp + , PlayerWalkRight8.lerp + , PlayerWalkRight9.lerp + , PlayerWalkRight8.lerp + , PlayerWalkRight7.lerp + , PlayerWalkRight6.lerp + , PlayerWalkRight5.lerp + , PlayerWalkRight4.lerp + , PlayerWalkRight3.lerp + , PlayerWalkRight2.lerp + ] + + fun getIdle (player, rx, ry, dw, dh, ww, wh) = + case #facing player of + FACING_RIGHT => + PlayerStandingRight.lerp (rx, ry, dw, dh, ww, wh, 1.0, 1.0, 1.0) + | FACING_LEFT => + PlayerStandingLeft.lerp (rx, ry, dw, dh, ww, wh, 1.0, 1.0, 1.0) + + fun getWhenOnGround (player, rx, ry, dw, dh, ww, wh) = + case #xAxis player of + MOVE_RIGHT => + let + val animTimer = #animTimer player + val frame = (animTimer div 2) mod Vector.length walkRightFrames + val func = Vector.sub (walkRightFrames, Int.max (frame, 0)) + in + func (rx, ry, dw, dh, ww, wh, 1.0, 1.0, 1.0) + end + | MOVE_LEFT => getIdle (player, rx, ry, dw, dh, ww, wh) + | STAY_STILL => getIdle (player, rx, ry, dw, dh, ww, wh) + + fun getWhenNotAttacked (player, rx, ry, dw, dh, ww, wh) = + case #yAxis player of + ON_GROUND => getWhenOnGround (player, rx, ry, dw, dh, ww, wh) + | _ => PlayerStandingRight.lerp (rx, ry, dw, dh, ww, wh, 1.0, 1.0, 1.0) + + fun getWhenAttacked (player, amt, rx, ry, dw, dh, ww, wh) = + case #facing player of + FACING_RIGHT => + if amt mod 5 = 0 then + PlayerStandingRight.lerp (rx, ry, dw, dh, ww, wh, 1.0, 1.0, 1.0) + else + PlayerStandingRight.lerp (rx, ry, dw, dh, ww, wh, 1.0, 0.75, 0.75) + | FACING_LEFT => + if amt mod 5 = 0 then + PlayerStandingLeft.lerp (rx, ry, dw, dh, ww, wh, 1.0, 1.0, 1.0) + else + PlayerStandingLeft.lerp (rx, ry, dw, dh, ww, wh, 1.0, 0.75, 0.75) + + fun helpGet + (player: player, rx, ry, drawWidth, drawHeight, windowWidth, windowHeight) = + case #attacked player of + NOT_ATTACKED => + getWhenNotAttacked + (player, rx, ry, drawWidth, drawHeight, windowWidth, windowHeight) + | ATTACKED amt => + getWhenAttacked + ( player + , amt + , rx + , ry + , drawWidth + , drawHeight + , windowWidth + , windowHeight + ) + + fun get (player: player, width, height) = + let + val {x, y, attacked, facing, ...} = player + val wratio = width / Constants.worldWidthReal + val hratio = height / Constants.worldHeightReal + in + if wratio < hratio then + let + val scale = Constants.worldHeightReal * 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 * wratio + val y = Real32.fromInt y * wratio + yOffset + + val realWidth = Constants.playerWidthReal * wratio + val realHeight = Constants.playerHeightReal * wratio + in + helpGet (player, x, y, realWidth, realHeight, width, height) + end + else + let + val scale = Constants.worldWidthReal * 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 * hratio + xOffset + val y = Real32.fromInt y * hratio + + val realWidth = Constants.playerWidthReal * hratio + val realHeight = Constants.playerHeightReal * hratio + in + helpGet (player, x, y, realWidth, realHeight, width, height) + end + end +end diff --git a/fcore/level/player/player.sml b/fcore/level/player/player.sml index 43ea016..0629f22 100644 --- a/fcore/level/player/player.sml +++ b/fcore/level/player/player.sml @@ -381,6 +381,10 @@ struct let val player = #player game + val oldAnimTimer = #animTimer player + val oldXAxis = #xAxis player + val oldYAxis = #yAxis player + val patches = getProjectilePatches player val patches = getRecoilPatches (player, patches) val player = PlayerPatch.withPatches (player, patches) @@ -422,8 +426,20 @@ struct val {walls, wallTree, platforms, platformTree, ...} = game val patches = PlayerPhysics.getEnvironmentPatches (player, walls, wallTree, platforms, platformTree) + + val player = PlayerPatch.withPatches (player, patches) + + val newXAxis = #xAxis player + val newYAxis = #yAxis player in - PlayerPatch.withPatches (player, patches) + if + oldYAxis = ON_GROUND andalso newYAxis = ON_GROUND + andalso oldXAxis = MOVE_RIGHT andalso newXAxis = MOVE_RIGHT + then + (* update move-right animation *) + PlayerPatch.withPatch (player, W_ANIM_TIMER (oldAnimTimer + 1)) + else + PlayerPatch.withPatch (player, W_ANIM_TIMER 0) end (* player reaction to collisions with enemies. @@ -493,68 +509,6 @@ struct end (*** DRAWING FUNCTIONS ***) - - (* block is placeholder asset *) - fun helpGetDrawVec - (x, y, realWidth, realHeight, width, height, attacked, facing) = - let - val (r, g, b) = - case attacked of - NOT_ATTACKED => (1.0, 1.0, 1.0) - | ATTACKED amt => - if amt mod 5 = 0 then (1.0, 1.0, 1.0) else (1.0, 0.75, 0.75) - in - case facing of - FACING_RIGHT => - PlayerStandingRight.lerp - (x, y, realWidth, realHeight, width, height, r, g, b) - | FACING_LEFT => - PlayerStandingLeft.lerp - (x, y, realWidth, realHeight, width, height, r, g, b) - end - - fun getDrawVec (player: player, width, height) = - let - val {x, y, attacked, facing, ...} = player - val wratio = width / Constants.worldWidthReal - val hratio = height / Constants.worldHeightReal - in - if wratio < hratio then - let - val scale = Constants.worldHeightReal * 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 * wratio - val y = Real32.fromInt y * wratio + yOffset - - val realWidth = Constants.playerWidthReal * wratio - val realHeight = Constants.playerHeightReal * wratio - in - helpGetDrawVec - (x, y, realWidth, realHeight, width, height, attacked, facing) - end - else - let - val scale = Constants.worldWidthReal * 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 * hratio + xOffset - val y = Real32.fromInt y * hratio - - val realWidth = Constants.playerWidthReal * hratio - val realHeight = Constants.playerHeightReal * hratio - in - helpGetDrawVec - (x, y, realWidth, realHeight, width, height, attacked, facing) - end - end - fun getFieldVec (player: player, width, height) = case #mainAttack player of MAIN_ATTACKING {length, ...} => diff --git a/fcore/level/wall.sml b/fcore/level/wall.sml index cf9fa6a..3f88b0c 100644 --- a/fcore/level/wall.sml +++ b/fcore/level/wall.sml @@ -36,7 +36,7 @@ struct val height = Real32.fromInt height * ratio val block = Block.lerp - (x, y, width, height, winWidth, winHeight, 0.0, 0.0, 0.0) + (x, y, width, height, winWidth, winHeight, 1.0, 1.0, 1.0) val acc = block :: acc in helpGetDrawVecWider @@ -59,7 +59,7 @@ struct val height = Real32.fromInt height * ratio val block = Block.lerp - (x, y, width, height, winWidth, winHeight, 0.0, 0.0, 0.0) + (x, y, width, height, winWidth, winHeight, 1.0, 1.0, 1.0) val acc = block :: acc in helpGetDrawVecTaller diff --git a/oms.mlb b/oms.mlb index 309b8c1..a81dd01 100644 --- a/oms.mlb +++ b/oms.mlb @@ -22,21 +22,6 @@ in fcore/level/chain-edge.sml end -ann - "allowVectorExps true" -in - fcore/level/player/sprites/player-standing-right.sml - fcore/level/player/sprites/player-standing-left.sml - fcore/level/player/sprites/player-walk-right-1.sml - fcore/level/player/sprites/player-walk-right-2.sml - fcore/level/player/sprites/player-walk-right-3.sml - fcore/level/player/sprites/player-walk-right-4.sml - fcore/level/player/sprites/player-walk-right-5.sml - fcore/level/player/sprites/player-walk-right-6.sml - fcore/level/player/sprites/player-walk-right-7.sml - fcore/level/player/sprites/player-walk-right-8.sml - fcore/level/player/sprites/player-walk-right-9.sml -end fcore/make-text-vec.sml @@ -69,8 +54,27 @@ fcore/level/trace-jump.sml fcore/level/enemy/enemy-behaviour.sml fcore/level/enemy/enemy.sml fcore/level/enemy/falling-enemies.sml + +ann + "allowVectorExps true" +in + fcore/level/player/sprites/player-standing-right.sml + fcore/level/player/sprites/player-standing-left.sml + fcore/level/player/sprites/player-walk-right-1.sml + fcore/level/player/sprites/player-walk-right-2.sml + fcore/level/player/sprites/player-walk-right-3.sml + fcore/level/player/sprites/player-walk-right-4.sml + fcore/level/player/sprites/player-walk-right-5.sml + fcore/level/player/sprites/player-walk-right-6.sml + fcore/level/player/sprites/player-walk-right-7.sml + fcore/level/player/sprites/player-walk-right-8.sml + fcore/level/player/sprites/player-walk-right-9.sml + fcore/level/player/player-vec.sml +end + fcore/level/player/player.sml fcore/level/player/player-attack.sml + fcore/level/projectile.sml fcore/level/level-update.sml diff --git a/shell/gl-draw.sml b/shell/gl-draw.sml index 33ca740..a577a0e 100644 --- a/shell/gl-draw.sml +++ b/shell/gl-draw.sml @@ -227,7 +227,7 @@ struct val width = InputState.getWidth () val height = InputState.getHeight () - val playerVec = Player.getDrawVec (#player level, width, height) + val playerVec = PlayerVec.get (#player level, width, height) val enemyVec = Enemy.getDrawVec (#enemies level, width, height) val playerVec = Vector.concat [playerVec, enemyVec]