Am Freitag, 7. Oktober 2016 22:06:26 UTC+2 schrieb Justin du coeur: > > When the player wants to move, the Player Actor sends an "I'd like to move > to X" message to the Space Actor responsible for that location, and the > Space returns either a "yes, go ahead, you now own that position" or "nope, > somebody's already there". >
Thanks for your answer, I'm gonna try to implement something like a "Space Actor" later. I had another try at getting the walking right (without a Pathfinder) using the scheduler and an actor. sealed trait Walk case class WalkTo(x: Int, y: Int) extends Walk case class WalkOver(x: Int, y: Int) extends Walk case class WalkOn(x: Int, y: Int) extends Walk case class WalkEnd() extends Walk class RoomEntity extends Actor { import context.dispatcher var position = (0, 0) var destination: (Int, Int) = (0, 0) override def preStart() = { // Walk to (10, 10) just to test the actor self ! WalkTo(10, 0) } override def receive = { case action:Walk => action match { // Set goal case WalkTo(x, y) => if ((x, y) != position) { destination = (x, y) val nextStep: Option[(Int, Int)] = Some((position._1 + 1, y)) // Pathfinder.getNextStep(position, destination) if (nextStep.isDefined) { // Check whether next step is possible self ! WalkOver(nextStep.get._1, nextStep.get._2) } } // Animate walk (Walks over tile) case WalkOver(x, y) => // (Start walking animation) context.system.scheduler.scheduleOnce(RoomEntity.WalkingSpeed, self, WalkOn(x, y)) // Set position (Walks on tile) case WalkOn(x, y) => position = (x, y) if (position != destination) { self ! WalkTo(destination._1, destination._2) } else { // (Stop walking animation) self ! WalkEnd() } } } } object RoomEntity { val WalkingSpeed = 500 milliseconds } (https://gist.github.com/SteveWinfield/0c9d50c66e270a7b25feb10dcd90926c) What do you think about it? (it's calling context.system.scheduler.scheduleOnce for every step - too much?) Cheers, Steve Winfield -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.