I relly don't like targeting with mouse. Since I use arrows (in game and on keyboard ) It isn't comfortable to move right hand from keyboard to mouse.
So I created targeting on keyboard. It is only a simple targeting of nearest living enemy. The code is here. It goes to game.cpp around line 650
Code: Select all
// Target the nearest monster
if (keys[SDLK_a])
{
Being *target = 0;
int dist = 0;
Beings* all = beingManager->getAll();
// cycle all monsters
for (BeingIterator i = all->begin(); i != all->end(); i++)
{
Being *being = (*i);
int d = abs(being->x - x) + abs(being->y - y);
if (being->getType() == Being::MONSTER &&
being->action != Being::MONSTER_DEAD &&
(d < dist || target == 0))
{
dist = d;
target = being;
}
}
if (target)
player_node->attack(target, true);
}
On the other hand in mine where all monsters attack you this is quite useful.
Maybe there could be some list of monsters and plyer may choose wich monsters will be targeted and which wont be.
What you think?[/code]