Changeset ff2133a in network-game for common


Ignore:
Timestamp:
Jun 11, 2013, 1:24:09 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
5b1e31e
Parents:
11d21ee
Message:

Move player chasing behavior to the Player class so the same behavior can be run client-side

Location:
common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    r11d21ee rff2133a  
    191191   return moving;
    192192}
     193
     194void Player::updateTarget(map<unsigned int, Player>& mapPlayers) {
     195   if (this->isChasing) {
     196      this->target.x = mapPlayers[this->targetPlayer].pos.x;
     197      this->target.y = mapPlayers[this->targetPlayer].pos.y;
     198
     199      if (posDistance(this->pos, this->target.toFloat()) <= this->range) {
     200         this->target.x = this->pos.x;
     201         this->target.y = this->pos.y;
     202
     203         this->isChasing = false;
     204         this->isAttacking = true;
     205         this->timeAttackStarted = getCurrentMillis();
     206      }
     207   }
     208}
  • common/Player.h

    r11d21ee rff2133a  
    1212
    1313#include <string>
     14#include <map>
    1415
    1516#include "Common.h"
     
    4647   void deserialize(char* buffer);
    4748
     49   void updateTarget(map<unsigned int, Player>& mapPlayers);
    4850   bool move(WorldMap *map);
    4951
    50    void takeFlag(int flag, WorldMap *map);
    51    void dropFlag(int flag, WorldMap *map);
     52   void takeFlag(int flag, WorldMap* map);
     53   void dropFlag(int flag, WorldMap* map);
    5254
    5355   int id;
  • common/Projectile.cpp

    r11d21ee rff2133a  
    7272
    7373bool Projectile::move(map<unsigned int, Player>& mapPlayers) {
     74   // if the current target logs off, this method will run into problems
     75
     76   //cout << "Inside projectile move" << endl;
     77
    7478   unsigned long long curTime = getCurrentMillis();
    7579   Player targetP = mapPlayers[target];
     
    8589   float dist = sqrt(pow(targetP.pos.x-pos.x, 2) + pow(targetP.pos.y-pos.y, 2));
    8690
     91   //cout << "About to finish projectile move" << endl;
     92
    8793   if (dist <= pixels) {
    8894      pos.x = targetP.pos.x;
Note: See TracChangeset for help on using the changeset viewer.