#ifndef COORDINATE_H #define COORDINATE_H // Programmer: Brett Weiland // Date: 4/30/23 // File: coordinate.h // Assignment: SP-B-finalProject // Purpose: conatins class for coordinates, // as well as namespace for direction parsing and computations. #include //Directions are represented by a 4 bit bitmap, //where north is the least significant bit. //direction typed vars should never have more then 2 bits set, //bits must be next to eachother or wrapped around. namespace direction { //type is used to gaurentee we have an unsigned integer of at least 8 bits typedef uint8_t TYPE; const direction::TYPE NONE = 0; const direction::TYPE N = 0; const direction::TYPE E = 1; const direction::TYPE S = 2; const direction::TYPE W = 3; //used to ensure a direction doesn't contain bits past its MSB const direction::TYPE MASK = ((1 << N) | (1 << E) | (1 << S) | (1 << W)); } class coordinate { private: int x, y; public: //Desc: initilizer for coordinate, sets X/Y to 0 //Pre: none //Post: coordinate initilized coordinate(); //Desc: initilizer for coordinate with X/Y to passed value //Pre: X/Y passed //Post: coordinate initilized coordinate(int pos_x, int pos_y); //Desc: finds the amount of steps it takes from one point to the other, // takes limited movement into account //Pre: objective is passed //Post: returns number of steps it'd take an npc to get to objective int getSteps(const coordinate &objective) const; //Desc: finds the direction an object at this coordinate would need to take // to arrive at objective //Pre: objective with coordinates within city bounds passed //Post: direction returned direction::TYPE getDirection(const coordinate &objective) const; //Desc: modifies this coordinate to step one direction in a certain path //Pre: direction given, does not check for possible obstructions //Post: this modified to take step in path void stepDirection(const direction::TYPE path); //geters and seters int get_x() const; int get_y() const; void set_x(const int pos_x); void set_y(const int pos_y); void set_xy(const int pos_x, const int pos_y); }; #endif