Changeset f401cac in network-game for common


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

Location:
common
Files:
3 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;
  • common/WorldMap.cpp

    r093c141 rf401cac  
    55#include <fstream>
    66#include <sstream>
     7#include <cstdlib>
    78
    89using namespace std;
     
    6768   WorldMap* m = new WorldMap(12l, 12);
    6869
    69    ifstream file(filename);
     70   ifstream file(filename.c_str());
    7071
    7172   if (file.is_open())
  • common/WorldMap.h

    r093c141 rf401cac  
    11#ifndef _WORLDMAP_H
    22#define _WORLDMAP_H
     3
     4#include <string>
    35
    46#include <vector>
Note: See TracChangeset for help on using the changeset viewer.