-
Notifications
You must be signed in to change notification settings - Fork 9
/
Land.h
65 lines (62 loc) · 1.64 KB
/
Land.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
#ifndef Land_H
#define Land_H
#include "WorldObject.h"
#include <vector>
#include <list>
#include "utilities.h"
#include "Tank.h"
struct slManifest //sliding columns information structure
{
int src,dest; //describes the cavity in the range [src,dest)
double velocity;
void inline merge(slManifest b)
{
src = std::min(b.src,src);
dest = std::max(b.dest,dest);
}
bool inline intersects(slManifest b)
{
slManifest *minRange = (dest-src < b.dest-b.src)?this:&b;
slManifest *maxRange = (dest-src > b.dest-b.src)?this:&b;
if(isInRange(minRange->src,maxRange->src,maxRange->dest))
return true;
if(isInRange(minRange->dest,maxRange->src,maxRange->dest))
return true;
return false;
}
};
class Land : public WorldObject
{
public:
Land();
~Land() = default;
enum Landtype
{
Flats,
Valley,
Hilly,
Random,
TotalTypes
};
void genHeightMap(Landtype Land_t);
void step(float dt);
void draw(sf::RenderTarget &target);
void reset();
void handleCollision(WorldObject &b);
void receiveMessage(const Message& msg);
sf::Vector2f getNormal(int x,int y);
float getNormAngle(int x,int y);//get normal angle
int getHeight(int x);
bool LandModified;
friend Tank;
private:
void destroyCircle(int x0,int y0, int radius);
void destroyColumn(int x,int top,int bottom);
bool isPixelSolid(int x,int y);
std::vector<int> hmap;
std::map<int,std::list<slManifest>> slColumns;
sf::Sprite LandSpr;
sf::Image LandImg;
sf::Texture LandTexture;
};
#endif // Land_H