-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapTypes.h
executable file
·151 lines (114 loc) · 3.5 KB
/
MapTypes.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#ifndef MapTypes_h
#define MapTypes_h
/**
MapTypes.h
Description:
Definition of all map types!
*/
#include <SFML/Graphics.hpp>
#include "Geometry.h"
#include <vector>
#include <memory>
class Thing;
class Enemy;
using things_up_t = std::vector<std::unique_ptr<Thing>>;
using things_p_t = std::vector<Thing*>;
/**
Sectors are used to define areas with different floor and ceiling height and textures.
Sectors do not have to be convex.
*/
struct Sector {
virtual ~Sector() = default;
Sector(int floor_h, int ceiling_h, sf::Texture* floor_t, sf::Texture* ceiling_t) :
fh(floor_h),
ch(ceiling_h),
ft(floor_t),
ct(ceiling_t){}
int fh;
int ch;
sf::Texture* ft;
sf::Texture* ct;
things_p_t thgs;
virtual bool is_door() { return false; }
};
using sectors_t = std::vector<std::unique_ptr<Sector>>;
/**
Line has one or two sides. These sides are defined using this structure. It specifies textures
and shift of the textures.
*/
struct Side {
sf::Texture* lower;
sf::Texture* middle;
sf::Texture* upper;
size_t tx;
size_t ty;
Sector* sector;
};
using sides_p_t = std::vector<Side*>;
using sides_t = std::vector<Side>;
/**
Door is derived from Sector. If you want to have a pretty door, avoid the difference between
door and neighbour sectors floor, door cannot have middle texture! Door should have own side definition!
*/
struct Door : public Sector {
enum State { open, closed, moving_up, moving_down };
Door(int floor_h, int ceiling_h, sf::Texture* floor_t, sf::Texture* ceiling_t)
: Sector(floor_h, floor_h, floor_t, ceiling_t),
seconds_opened(0),
open_ch(ceiling_h),
s(Door::closed) {}
float seconds_opened;
int open_ch;
State s;
sides_p_t sides;
static const int door_speed = 200;
static const int door_open_time = 3;
// must be in harm with blocksize, should be in (200,0)
static const int door_open_distance = 150;
bool is_door() override { return true; }
};
using doors_p_t = std::vector<Door*>;
/**
Line defines a wall. One sided Line is solid wall. Two sided line is not wall, but empty space
between two sectors. By specifing two sided line with transparent textures, special transparent
wall (player can walk through this wall) is defined.
*/
struct Line {
Vector* start;
Vector* end;
Side* left;
// nullptr if onesided
Side* right;
/**
@param test_s Start of the segment being checked.
@param test_e End of the segment being checked.
@return Returns true if the segment collides with the Line
*/
bool in_collision(const Vector& test_s, const Vector& test_e) const;
private:
/**
@return Returns 0 if p, q and r are colinear, 1 if clockwise, 2 if counterclockwise
*/
static int orientation(Vector p, Vector q, Vector r);
bool on_segment(Vector p, Vector q, Vector r) const;
};
/**
Segment is a part of Line. It is used by BSP tree to define sub-sectors.
*/
struct Segment {
Vector start;
Vector end;
const Line* line;
bool direction;
// 0 left side
// 1 right side
float offset;
bool operator==(const Segment& s) const { return (start == s.start) && (end == s.end) && (direction == s.direction); }
};
using segments_t = std::vector<Segment>;
using textures_up_t = std::vector<std::unique_ptr<sf::Texture>>;
using vertices_t = std::vector<Vector>;
using lines_t = std::vector<Line>;
using lines_p_t = std::vector<const Line*>;
using enemies_p_t = std::vector<std::unique_ptr<Enemy>>;
#endif // MapTypes_h