Itutorial
Legendary OT User
- Joined
- Dec 23, 2014
- Messages
- 2,391
- Solutions
- 68
- Reaction score
- 1,063
I want to make it so players can only see creatures in their visibility range. Right now creatures will only update when they leave or enter the screen area. However, I need it to update if they are within the screen area as well.
Here is the main part of the code I am trying to do.
In player.cpp Player::canSeeCreature()
It checks if the creature is within their visibility range. If the creature is too far away it returns false so the player cannot see the creature. Again this only happens once the creature is off the screen and the player moves back to the creature. It will not appear on the screen.
Then in Player:
nWalk() where I want the code to check if the player can see the creature every time they walk
I know there is something with known creatures and unknown creatures however, it only seems to update creatures off the screen which I want it to be able to in real time.
Here is the main part of the code I am trying to do.
In player.cpp Player::canSeeCreature()
C++:
int16_t visibility = getVisibility();
const Position& position = getPosition();
const Position& creaturePosition = creature->getPosition();
const uint8_t distance = position.getDistanceX(creaturePosition) + position.getDistanceY(creaturePosition);
if (visibility < 2) {
visibility = 2;
}
if (distance > visibility) {
return false;
}
It checks if the creature is within their visibility range. If the creature is too far away it returns false so the player cannot see the creature. Again this only happens once the creature is off the screen and the player moves back to the creature. It will not appear on the screen.
Then in Player:

C++:
uint8_t distance = std::round(getVisibility() / 2);
SpectatorVec spectators;
map.getSpectators(spectators, getPosition(), false, false, 0, distance, 0, distance);
for (Creature* spectator : spectators) {
if (canSeeCreature(spectator)) {
sendCreatureAppear(spectator, spectator->getPosition());
}
}
I know there is something with known creatures and unknown creatures however, it only seems to update creatures off the screen which I want it to be able to in real time.