Changeset f401cac in network-game for common/Player.cpp


Ignore:
Timestamp:
Feb 18, 2013, 7:41:52 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
66906aa
Parents:
093c141
Message:

Fixed some bugs in the player movement code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    r093c141 rf401cac  
    103103   cout << "elapsed nsecs: " << diffTS.tv_nsec << endl;
    104104
    105    // here we move 100 pixels per second
    106    float pixels = 100 * (diffTS.tv_sec+diffTS.tv_nsec/1000000000.0);
    107    cout << "We need to move " << pixels << "pixels" << endl;
     105   // if we're at our target, don't move
     106   if (pos.x == target.x || pos.y == target.y)
     107      cout << "We're already at our target" << endl;
     108   else {
     109      float pixels = speed * (diffTS.tv_sec+diffTS.tv_nsec/1000000000.0);
     110      cout << "We need to move " << pixels << " pixels" << endl;
    108111
    109    double angle = atan2(target.y-pos.y, target.x-pos.x);
     112      double angle = atan2(target.y-pos.y, target.x-pos.x);
    110113
    111    // we just need to check that we don't overjump the target
    112    pos.x += cos(angle)*pixels;
    113    pos.y += sin(angle)*pixels;
     114      // we just need to check that we don't overjump the target
     115      pos.x += cos(angle)*pixels;
     116      pos.y += sin(angle)*pixels;
     117   }
    114118
    115119   timeLastUpdated.tv_sec = curTS.tv_sec;
Note: See TracChangeset for help on using the changeset viewer.