blob: 451df121521f8a81f42c25fd1da066b5455164a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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 <cstdint>
//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
|