src/IEnvironmentObject.cpp

Go to the documentation of this file.
00001 /* Crown and Cutlass
00002  * Environment Object Code
00003  *
00004  * This class is a parent to any object which may appear
00005  * in the game. Initially the things that come to mind which
00006  * this would be used as a parent class would be cities,
00007  * hidden treasures, and perhaps enemy pirate ships.
00008  */
00009 
00010 #include <string>
00011 #include "ccmath.h"
00012 #include "Log.h"
00013 #include "IEnvironmentObject.h"
00014 
00015 using namespace std;
00016 
00017 IEnvironmentObject::IEnvironmentObject() {
00018   locX = 0;
00019   locZ = 0;
00020   visible = false;
00021   name = "";
00022 }
00023 
00024 IEnvironmentObject::IEnvironmentObject(string objName, int objLocX, int objLocZ, bool objVisible) {
00025   locX = objLocX;
00026   locZ = objLocZ;
00027   visible = objVisible;
00028   name = objName;
00029 }
00030 
00031 string IEnvironmentObject::getName() {
00032   return name;
00033 }
00034 
00035 float IEnvironmentObject::calcDist(float x, float z) {
00036   return sqrt((x-locX)*(x-locX)+(z-locZ)*(z-locZ));
00037 }
00038 
00039 float IEnvironmentObject::calcAngle(float x, float z) {
00040   // This is weird, but because of the strange coords setup it works
00041   float angle = atan2(z - locZ, locX - x);
00042 
00043   // atan2 returns from -PI to PI, so move to 0 to 2*PI
00044   if (angle < 0) angle = 2*M_PI + angle;
00045 
00046   return angle;
00047 }
00048 
00049 int IEnvironmentObject::GetLocX() {
00050   return locX;
00051 }
00052 
00053 int IEnvironmentObject::GetLocZ() {
00054   return locZ;
00055 }

Generated on Mon Jan 8 22:34:12 2007 for CrownandCutlass by  doxygen 1.4.7