Player cannot walk when stamina is 0
This commit is contained in:
parent
9b484e895b
commit
44f0538b8b
@ -175,7 +175,7 @@ class MainApp(
|
|||||||
15.seconds
|
15.seconds
|
||||||
).toTask
|
).toTask
|
||||||
.void
|
.void
|
||||||
case _ => monix.eval.Task.unit
|
case _ => me.Task.unit
|
||||||
}
|
}
|
||||||
_ <- Resource.make(obs.completedL.toIO.hideErrors.start)(_.cancel)
|
_ <- Resource.make(obs.completedL.toIO.hideErrors.start)(_.cancel)
|
||||||
// _ <-
|
// _ <-
|
||||||
|
@ -29,6 +29,7 @@ import wow.doge.mygame.subsystems.events.PlayerEvent
|
|||||||
import wow.doge.mygame.subsystems.events.TickEvent
|
import wow.doge.mygame.subsystems.events.TickEvent
|
||||||
import wow.doge.mygame.subsystems.events.TickEvent.RenderTick
|
import wow.doge.mygame.subsystems.events.TickEvent.RenderTick
|
||||||
import wow.doge.mygame.subsystems.movement.ImMovementActor
|
import wow.doge.mygame.subsystems.movement.ImMovementActor
|
||||||
|
import wow.doge.mygame.utils.MovementDirection
|
||||||
|
|
||||||
object PlayerActor {
|
object PlayerActor {
|
||||||
|
|
||||||
@ -64,14 +65,15 @@ object PlayerActor {
|
|||||||
replyTo: ActorRef[UIO[Observable[CharacterStats]]]
|
replyTo: ActorRef[UIO[Observable[CharacterStats]]]
|
||||||
) extends Command
|
) extends Command
|
||||||
|
|
||||||
final case class MoveLeft(pressed: Boolean) extends Command
|
final case class Walk(pressed: Boolean, dir: MovementDirection)
|
||||||
final case class MoveUp(pressed: Boolean) extends Command
|
extends Command
|
||||||
final case class MoveRight(pressed: Boolean) extends Command
|
case object StopMoving extends Command
|
||||||
final case class MoveDown(pressed: Boolean) extends Command
|
|
||||||
case object Jump extends Command
|
case object Jump extends Command
|
||||||
private[player] final case class HandleMovement(
|
|
||||||
|
private[player] final case class HandleWalk(
|
||||||
b: CharacterStats,
|
b: CharacterStats,
|
||||||
pressed: Boolean
|
pressed: Boolean,
|
||||||
|
direction: MovementDirection
|
||||||
) extends Command
|
) extends Command
|
||||||
|
|
||||||
private[player] case object Die extends Command
|
private[player] case object Die extends Command
|
||||||
|
@ -18,6 +18,7 @@ import wow.doge.mygame.executors.Schedulers
|
|||||||
import wow.doge.mygame.game.entities.CharacterStats
|
import wow.doge.mygame.game.entities.CharacterStats
|
||||||
import wow.doge.mygame.implicits._
|
import wow.doge.mygame.implicits._
|
||||||
import wow.doge.mygame.subsystems.events.PlayerMovementEvent
|
import wow.doge.mygame.subsystems.events.PlayerMovementEvent
|
||||||
|
import wow.doge.mygame.utils.MovementDirection
|
||||||
|
|
||||||
object PlayerMovementEventListener {
|
object PlayerMovementEventListener {
|
||||||
final case class State(
|
final case class State(
|
||||||
@ -60,14 +61,19 @@ class PlayerMovementEventListener(
|
|||||||
Observable
|
Observable
|
||||||
.interval(250.millis)
|
.interval(250.millis)
|
||||||
.doOnNext(_ => Task(pprint.log("Sending Stamina Consume Item")))
|
.doOnNext(_ => Task(pprint.log("Sending Stamina Consume Item")))
|
||||||
.doOnNextF(_ =>
|
.mapEvalF(_ =>
|
||||||
props.playerActor
|
props.playerActor
|
||||||
.askL(
|
.askL(
|
||||||
PlayerActor
|
PlayerActor
|
||||||
.ConsumeStamina(CharacterStats.DamageStamina(25), _)
|
.ConsumeStamina(CharacterStats.DamageStamina(25), _)
|
||||||
)
|
)
|
||||||
.void
|
|
||||||
)
|
)
|
||||||
|
.doOnNext(stats =>
|
||||||
|
if (stats.stamina.toInt === 0)
|
||||||
|
Task(props.playerActor ! PlayerActor.StopMoving)
|
||||||
|
else Task.unit
|
||||||
|
)
|
||||||
|
.takeWhile(_.stamina.toInt >= 0)
|
||||||
.completedL
|
.completedL
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -121,16 +127,32 @@ class PlayerMovementEventListener(
|
|||||||
Behaviors.receiveMessage {
|
Behaviors.receiveMessage {
|
||||||
case PlayerMovedLeft(pressed) =>
|
case PlayerMovedLeft(pressed) =>
|
||||||
// props.movementActor ! ImMovementActor.MoveLeft(pressed)
|
// props.movementActor ! ImMovementActor.MoveLeft(pressed)
|
||||||
props.playerActor ! PlayerActor.MoveLeft(pressed)
|
// props.playerActor ! PlayerActor.MoveLeft(pressed)
|
||||||
|
props.playerActor ! PlayerActor.Walk(
|
||||||
|
pressed,
|
||||||
|
MovementDirection.Left
|
||||||
|
)
|
||||||
receive(handleStamina(pressed))
|
receive(handleStamina(pressed))
|
||||||
case PlayerMovedRight(pressed) =>
|
case PlayerMovedRight(pressed) =>
|
||||||
props.playerActor ! PlayerActor.MoveRight(pressed)
|
// props.playerActor ! PlayerActor.MoveRight(pressed)
|
||||||
|
props.playerActor ! PlayerActor.Walk(
|
||||||
|
pressed,
|
||||||
|
MovementDirection.Right
|
||||||
|
)
|
||||||
receive(handleStamina(pressed))
|
receive(handleStamina(pressed))
|
||||||
case PlayerMovedForward(pressed) =>
|
case PlayerMovedForward(pressed) =>
|
||||||
props.playerActor ! PlayerActor.MoveUp(pressed)
|
// props.playerActor ! PlayerActor.MoveUp(pressed)
|
||||||
|
props.playerActor ! PlayerActor.Walk(
|
||||||
|
pressed,
|
||||||
|
MovementDirection.Forward
|
||||||
|
)
|
||||||
receive(handleStamina(pressed))
|
receive(handleStamina(pressed))
|
||||||
case PlayerMovedBackward(pressed) =>
|
case PlayerMovedBackward(pressed) =>
|
||||||
props.playerActor ! PlayerActor.MoveDown(pressed)
|
// props.playerActor ! PlayerActor.MoveDown(pressed)
|
||||||
|
props.playerActor ! PlayerActor.Walk(
|
||||||
|
pressed,
|
||||||
|
MovementDirection.Backward
|
||||||
|
)
|
||||||
receive(handleStamina(pressed))
|
receive(handleStamina(pressed))
|
||||||
case PlayerJumped =>
|
case PlayerJumped =>
|
||||||
props.playerActor ! PlayerActor.Jump
|
props.playerActor ! PlayerActor.Jump
|
||||||
|
@ -16,6 +16,7 @@ import wow.doge.mygame.game.entities.character.CharacterStates._
|
|||||||
import wow.doge.mygame.game.entities.player.PlayerActor
|
import wow.doge.mygame.game.entities.player.PlayerActor
|
||||||
import wow.doge.mygame.implicits._
|
import wow.doge.mygame.implicits._
|
||||||
import wow.doge.mygame.subsystems.movement.ImMovementActor
|
import wow.doge.mygame.subsystems.movement.ImMovementActor
|
||||||
|
import wow.doge.mygame.utils.MovementDirection
|
||||||
|
|
||||||
class IdleBehaviorFactory(
|
class IdleBehaviorFactory(
|
||||||
env: PlayerActor.Env,
|
env: PlayerActor.Env,
|
||||||
@ -32,41 +33,43 @@ class IdleBehaviorFactory(
|
|||||||
Behaviors
|
Behaviors
|
||||||
.receiveMessage[PlayerActor.Command] {
|
.receiveMessage[PlayerActor.Command] {
|
||||||
|
|
||||||
case PlayerActor.HandleMovement(curStats, pressed) =>
|
case PlayerActor.HandleWalk(curStats, pressed, direction) =>
|
||||||
if (curStats.stamina.toInt > 0) {
|
if (curStats.stamina.toInt > 0) {
|
||||||
children.movementActor ! ImMovementActor.MoveLeft(pressed)
|
children.movementActor ! (direction match {
|
||||||
|
case MovementDirection.Forward =>
|
||||||
|
ImMovementActor.MoveUp(pressed)
|
||||||
|
case MovementDirection.Backward =>
|
||||||
|
ImMovementActor.MoveDown(pressed)
|
||||||
|
case MovementDirection.Left => ImMovementActor.MoveLeft(pressed)
|
||||||
|
case MovementDirection.Right =>
|
||||||
|
ImMovementActor.MoveRight(pressed)
|
||||||
|
})
|
||||||
if (pressed) nextStateFn(AliveSubstate.Moving(Walking))
|
if (pressed) nextStateFn(AliveSubstate.Moving(Walking))
|
||||||
else nextStateFn(AliveSubstate.Idle)
|
else nextStateFn(AliveSubstate.Idle)
|
||||||
} else {
|
} else {
|
||||||
children.movementActor ! ImMovementActor.MoveLeft(false)
|
children.movementActor ! ImMovementActor.StopMoving
|
||||||
Behaviors.same
|
Behaviors.same
|
||||||
}
|
}
|
||||||
|
|
||||||
case PlayerActor.MoveLeft(pressed) =>
|
// case PlayerActor.Walk(pressed, Direction.Up) => Behaviors.same
|
||||||
|
// case PlayerActor.Walk(pressed, Direction.Down) => Behaviors.same
|
||||||
|
// case PlayerActor.Walk(pressed, Direction.Left) => Behaviors.same
|
||||||
|
// case PlayerActor.Walk(pressed, Direction.Right) => Behaviors.same
|
||||||
|
|
||||||
|
case PlayerActor.StopMoving =>
|
||||||
|
children.movementActor ! ImMovementActor.StopMoving
|
||||||
|
Behaviors.same
|
||||||
|
|
||||||
|
case PlayerActor.Walk(pressed, direction) =>
|
||||||
implicit val ec = props.scheduler.value
|
implicit val ec = props.scheduler.value
|
||||||
for {
|
for {
|
||||||
curStats <- children.statsActor.ask(StatsActor.CurrentStats)
|
curStats <- children.statsActor.ask(StatsActor.CurrentStats)
|
||||||
res <- Future.successful(
|
_ <- Future.successful(
|
||||||
ctx.self ! PlayerActor.HandleMovement(curStats, pressed)
|
ctx.self ! PlayerActor.HandleWalk(curStats, pressed, direction)
|
||||||
)
|
)
|
||||||
} yield res
|
} yield ()
|
||||||
Behaviors.same
|
Behaviors.same
|
||||||
|
|
||||||
case PlayerActor.MoveRight(pressed) =>
|
|
||||||
children.movementActor ! ImMovementActor.MoveRight(pressed)
|
|
||||||
if (pressed) nextStateFn(AliveSubstate.Moving(Walking))
|
|
||||||
else nextStateFn(AliveSubstate.Idle)
|
|
||||||
|
|
||||||
case PlayerActor.MoveUp(pressed) =>
|
|
||||||
children.movementActor ! ImMovementActor.MoveUp(pressed)
|
|
||||||
if (pressed) nextStateFn(AliveSubstate.Moving(Walking))
|
|
||||||
else nextStateFn(AliveSubstate.Idle)
|
|
||||||
|
|
||||||
case PlayerActor.MoveDown(pressed) =>
|
|
||||||
children.movementActor ! ImMovementActor.MoveDown(pressed)
|
|
||||||
if (pressed) nextStateFn(AliveSubstate.Moving(Walking))
|
|
||||||
else nextStateFn(AliveSubstate.Idle)
|
|
||||||
|
|
||||||
case PlayerActor.Jump =>
|
case PlayerActor.Jump =>
|
||||||
children.movementActor ! ImMovementActor.Jump
|
children.movementActor ! ImMovementActor.Jump
|
||||||
ctx.self.ask(
|
ctx.self.ask(
|
||||||
@ -152,7 +155,8 @@ class IdleBehaviorFactory(
|
|||||||
case (status, stats) =>
|
case (status, stats) =>
|
||||||
status match {
|
status match {
|
||||||
case StatsActor.Status.Dead => ctx.self ! PlayerActor.Die
|
case StatsActor.Status.Dead => ctx.self ! PlayerActor.Die
|
||||||
case StatsActor.Status.Alive =>
|
case StatsActor.Status.Alive => ()
|
||||||
|
}
|
||||||
props.statsQueue
|
props.statsQueue
|
||||||
.offer(stats)
|
.offer(stats)
|
||||||
.foreach { _ =>
|
.foreach { _ =>
|
||||||
@ -160,7 +164,6 @@ class IdleBehaviorFactory(
|
|||||||
replyTo ! stats
|
replyTo ! stats
|
||||||
}(props.scheduler.value)
|
}(props.scheduler.value)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Behaviors.same
|
Behaviors.same
|
||||||
|
|
||||||
case PlayerActor.Die => deadState
|
case PlayerActor.Die => deadState
|
||||||
|
@ -36,6 +36,7 @@ object ImMovementActor {
|
|||||||
final case class MoveUp(pressed: Boolean) extends Movement
|
final case class MoveUp(pressed: Boolean) extends Movement
|
||||||
final case class MoveRight(pressed: Boolean) extends Movement
|
final case class MoveRight(pressed: Boolean) extends Movement
|
||||||
final case class MoveDown(pressed: Boolean) extends Movement
|
final case class MoveDown(pressed: Boolean) extends Movement
|
||||||
|
case object StopMoving extends Movement
|
||||||
case object Jump extends Movement
|
case object Jump extends Movement
|
||||||
|
|
||||||
class Props(
|
class Props(
|
||||||
@ -77,6 +78,10 @@ class ImMovementActor[T](
|
|||||||
.receiveMessage[Command] {
|
.receiveMessage[Command] {
|
||||||
case m: Movement =>
|
case m: Movement =>
|
||||||
m match {
|
m match {
|
||||||
|
case StopMoving =>
|
||||||
|
cm.stop(movable)
|
||||||
|
receive(State(CardinalDirection.default), new Vector3f)
|
||||||
|
|
||||||
case MoveLeft(pressed) =>
|
case MoveLeft(pressed) =>
|
||||||
stopIfNotPressed(pressed)
|
stopIfNotPressed(pressed)
|
||||||
receive(
|
receive(
|
||||||
|
18
src/main/scala/wow/doge/mygame/utils/MovementDirection.scala
Normal file
18
src/main/scala/wow/doge/mygame/utils/MovementDirection.scala
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package wow.doge.mygame.utils
|
||||||
|
|
||||||
|
import enumeratum._
|
||||||
|
import cats.kernel.Eq
|
||||||
|
import cats.Show
|
||||||
|
|
||||||
|
sealed trait MovementDirection extends EnumEntry
|
||||||
|
|
||||||
|
object MovementDirection extends Enum[MovementDirection] {
|
||||||
|
val values = findValues
|
||||||
|
case object Forward extends MovementDirection
|
||||||
|
case object Backward extends MovementDirection
|
||||||
|
case object Left extends MovementDirection
|
||||||
|
case object Right extends MovementDirection
|
||||||
|
|
||||||
|
implicit val eq = Eq.fromUniversalEquals[MovementDirection]
|
||||||
|
implicit val show = Show.fromToString[MovementDirection]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user