Exemplo n.º 1
0
  /* 
	 * Called by the world that's holding the entity every tick (50ms).
	 * A return value of true will cause the world to destroy the entity.
	 */
	bool
	player_bot::tick (world &w)
	{
	  if (entity::tick (w))
	    return true;
	  
	  if (this->ticks == 0)
	    this->dest = this->pos;
	  
	  std::uniform_int_distribution<> act (0, 4);
	  if (act (this->rnd) == 0)
	    {
	      std::uniform_int_distribution<> dis (0, 3);
	      switch (dis (this->rnd))
	        {
	        case 0: if (_check_pos (w, this->dest.x + 1, this->dest.y, this->dest.z)) ++ this->dest.x; break;
	        case 1: if (_check_pos (w, this->dest.x - 1, this->dest.y, this->dest.z)) -- this->dest.x; break;
	        case 2: if (_check_pos (w, this->dest.x, this->dest.y, this->dest.z + 1)) ++ this->dest.z; break;
	        case 3: if (_check_pos (w, this->dest.x, this->dest.y, this->dest.z - 1)) -- this->dest.z; break;
	        }
	    }
	  
	  int dx = dest.x - (int)this->pos.x;
    int dz = dest.z - (int)this->pos.z;
    this->velocity.x = dx * 0.4;
    this->velocity.z = dz * 0.4;
	  
	  ++ this->ticks;
	  return false;
	}
Exemplo n.º 2
0
void	change_pos(t_player *player, t_game *game)
{
  if (player->team != 0)
    {
      if (_check_pos(player, game, 0, 0))
	{
	  game->map[player->x * SIZE_AREA + player->y] = 0;
	  --game->teams[player->team - 1];
	  player->team = 0;
	}
      else
	move(player, game);
    }
}