Target with keyboard
Posted: 25 Mar 2006, 12:29
Hi,
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
The code is working. But has some disadvatages. Like if you want to target only green slimes but definitely not red scorpions, this dosn't help much.
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]
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]