diff options
author | Bertram <bertram@cegetel.net> | 2010-02-09 01:42:50 +0100 |
---|---|---|
committer | Bertram <bertram@cegetel.net> | 2010-02-09 01:42:50 +0100 |
commit | 56f501c8148b1061a02547d37b20eeeeb64029db (patch) | |
tree | 718e48289066706bc3851830f3c6b03150e66b97 /src/being.cpp | |
parent | 8b4d9f9b5eaf175baf0c4209c312133bb457742c (diff) | |
download | mana-56f501c8148b1061a02547d37b20eeeeb64029db.tar.gz mana-56f501c8148b1061a02547d37b20eeeeb64029db.tar.bz2 mana-56f501c8148b1061a02547d37b20eeeeb64029db.tar.xz mana-56f501c8148b1061a02547d37b20eeeeb64029db.zip |
Made the Beings' logic be able to handle any tile height/width.
This is the First step to get rid of most hardcoded 32 values.
Diffstat (limited to 'src/being.cpp')
-rw-r--r-- | src/being.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/being.cpp b/src/being.cpp index 20d7319a..33f38255 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -503,7 +503,7 @@ void Being::nextTile() mX = pos.x; mY = pos.y; setAction(WALK); - mWalkTime += (int)(mWalkSpeed / 10); + mWalkTime += (int)(mWalkSpeed.x / 10); } void Being::logic() @@ -537,8 +537,8 @@ void Being::logic() // The deplacement of a point along a vector is calculated // using the Unit Vector (â) multiplied by the point speed. // â = a / ||a|| (||a|| is the a length.) - // Then, diff = (dir/||dir||)*speed, or (dir / ||dir|| / 1/speed). - Vector diff = (dir / (nominalLength / mWalkSpeed)); + // Then, diff = (dir/||dir||) * speed. + Vector diff = dir.normalized() * mWalkSpeed; // Test if we don't miss the destination by a move too far: if (diff.length() > nominalLength) @@ -799,7 +799,21 @@ int Being::getOffset(char pos, char neg) const if (mAction != WALK || !(mDirection & (pos | neg))) return 0; - int offset = (int)((get_elapsed_time(mWalkTime) * 32) / mWalkSpeed); + int offset; + + if (mMap) + { + offset = (pos == LEFT && neg == RIGHT) ? + (int)((get_elapsed_time(mWalkTime) + * mMap->getTileWidth()) / mWalkSpeed.x) : + (int)((get_elapsed_time(mWalkTime) + * mMap->getTileHeight()) / mWalkSpeed.y); + } + else + { + offset = (int)((get_elapsed_time(mWalkTime) + * DEFAULT_TILE_SIDE_LENGTH) / mWalkSpeed.x); + } // We calculate the offset _from_ the _target_ location offset -= 32; |