Beispiel #1
0
 public function update(World $world)
 {
     $positionPlayer = $this->player->getPosition();
     if ($positionPlayer->getX() == $this->destination->getX() && $positionPlayer->getY() == $this->destination->getY()) {
         $this->end = true;
         return;
     }
     $direction = array("X" => 0, "Y" => 0);
     $world->getMap()->setItem($positionPlayer, MapBuilder::HERBE);
     if ($positionPlayer->getX() < $this->destination->getX()) {
         $direction["X"] = 1;
     }
     if ($positionPlayer->getX() > $this->destination->getX()) {
         $direction["X"] = -1;
     }
     if ($positionPlayer->getY() < $this->destination->getY()) {
         $direction["Y"] = 1;
     }
     if ($positionPlayer->getY() > $this->destination->getY()) {
         $direction["Y"] = -1;
     }
     $positionPlayer->setDirection(new Direction($direction["X"], $direction["Y"]));
     $positionPlayer->move();
     $world->getLogger()->log(LogLevel::INFO, "le joeur " . get_class($this->player) . " est en X : " . $positionPlayer->getX() . " Y : " . $positionPlayer->getY() . " et il se déplace en X : " . $direction["X"] . " Y : " . $direction["Y"]);
 }
Beispiel #2
0
 public function update(World $world)
 {
     $players = $world->getPlayerCollection();
     foreach ($players as $player) {
         /** @var $player Player */
         $player->getIa()->update($world);
         $player->update($world);
     }
     if ($world->getTimer()->isTime(100)) {
         gc_collect_cycles();
     }
 }
Beispiel #3
0
 public function update(World $world)
 {
     if ($this->path !== null && $this->path->isEnd()) {
         $item = $world->getMap()->getItem($this->path->getDestination());
         if (1 == 1 || $item == MapBuilder::FLEUR) {
             $world->getLogger()->log(LogLevel::INFO, "le chat mange");
             $this->player->getEstomac()->setNouriture($this->player->getEstomac()->getNouriture() + 10);
             $world->getMap()->setItem($this->path->getDestination(), MapBuilder::HERBE);
         }
         $this->path = null;
     }
     if ($this->path === null) {
         $newPoint = $world->getMap()->findItem(MapBuilder::FLEUR);
         if ($newPoint !== null) {
             $world->getLogger()->log(LogLevel::INFO, "le chat part vers le point " . $newPoint->getX() . ", " . $newPoint->getY());
             $this->path = new PathPoint($this->player, $newPoint);
         }
     }
     if ($this->path !== null) {
         $world->getLogger()->log(LogLevel::INFO, "le chat est à la recherche de nourriture");
         $this->path->update($world);
     } else {
         $world->getLogger()->log(LogLevel::INFO, "le chat n'a plus de nourriture");
     }
 }
 public function render(MapRenderInterface $mapRender, World $world)
 {
     $world->update();
     if ($world->getInputController()->getKey() == "x") {
         $world->getMemoryManager()->persist();
         return;
     }
     $players = $world->getPlayerCollection();
     foreach ($players as $player) {
         $world->getMap()->setItem($player->getPosition(), "P");
     }
     $mapRender->render($world->getMap()->getMap());
     //usleep(200);
     $mapRender->clear($world->getMap()->getMap());
 }
Beispiel #5
0
 public function update()
 {
     $this->setItems(array(array("title" => "memory : " . $this->convert(memory_get_usage()), "bold" => false), array("title" => "timer : " . World::getInstance()->getTimer()->getTick(), "bold" => false)));
     $this->setChanged(true);
 }