From afa02f645056c5823b0d8a29d37c1ff10aedce7a Mon Sep 17 00:00:00 2001 From: root Date: Tue, 27 Feb 2024 21:53:44 -0600 Subject: init --- coordinate.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 coordinate.h (limited to 'coordinate.h') diff --git a/coordinate.h b/coordinate.h new file mode 100644 index 0000000..451df12 --- /dev/null +++ b/coordinate.h @@ -0,0 +1,70 @@ +#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 -- cgit v1.2.3