summaryrefslogtreecommitdiff
path: root/src/localplayer.cpp
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2008-10-24 19:13:04 +0000
committerJared Adams <jaxad0127@gmail.com>2008-10-24 19:13:04 +0000
commitf8f3e17f72d1216bacd5aaa975789b0b790068f6 (patch)
treef75af23708c746f0139e044ebccc78ceac36c6e2 /src/localplayer.cpp
parent0b2235dfff7f7c0f534746271ff66275297fd328 (diff)
downloadmana-f8f3e17f72d1216bacd5aaa975789b0b790068f6.tar.gz
mana-f8f3e17f72d1216bacd5aaa975789b0b790068f6.tar.bz2
mana-f8f3e17f72d1216bacd5aaa975789b0b790068f6.tar.xz
mana-f8f3e17f72d1216bacd5aaa975789b0b790068f6.zip
Made it so the player will auto face its target
Fixed it so the correct direction will be Patch by Chuck Miller
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r--src/localplayer.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index d272caaf..77fd5b90 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -391,6 +391,32 @@ void LocalPlayer::attack()
if (mAction != STAND && mAction != ATTACK)
return;
+ //Face direction of the target
+ if(mTarget){
+ unsigned char dir = 0;
+ int x = 0, y = 0;
+ Vector plaPos = this->getPosition();
+ Vector tarPos = mTarget->getPosition();
+ x = plaPos.x - tarPos.x;
+ y = plaPos.y - tarPos.y;
+ if(abs(x) < abs(y)){
+ //Check to see if target is above me or below me
+ if(y > 0){
+ dir = UP;
+ } else {
+ dir = DOWN;
+ }
+ } else {
+ //check to see if the target is to the left or right of me
+ if(x > 0){
+ dir = LEFT;
+ } else {
+ dir = RIGHT;
+ }
+ }
+ setDirection(dir);
+ }
+
mLastAction = tick_time;
setAction(ATTACK);