File: Water.h

package info (click to toggle)
caveexpress 2.4+git20160609-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 48,824 kB
  • sloc: cpp: 66,239; ansic: 1,135; sh: 471; xml: 186; python: 74; makefile: 20
file content (93 lines) | stat: -rw-r--r-- 2,152 bytes parent folder | download | duplicates (2)
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
#pragma once

#include "caveexpress/server/entities/IEntity.h"
#include "caveexpress/server/entities/WorldParticle.h"
#include <set>
#include <vector>

namespace caveexpress {

// forward decl
class Map;

typedef enum {
	WATER_UNINITIALIZED,
	WATER_RISING,
	WATER_FALLING
} WaterState;

class Water: public IEntity {
private:
	const float _waterChangeSpeed;
	const uint32_t _waterRisingDelay;
	const uint32_t _waterFallingDelay;
	float _mapHeight;
	WaterState _waterRisingState;
	float _currentHeightLevel;
	uint32_t _waterRisingTime;
	uint32_t _waterFallingTime;

	typedef std::pair<b2Fixture*, b2Fixture*> FixturePair;
	typedef std::set<FixturePair>::iterator FixturePairIter;
	std::set<FixturePair> _fixturePairs;

	WorldParticle *_waterParticle;

	void updateFixtures ();
public:
	Water (Map& map, float waterChangeSpeed, uint32_t waterRisingDelay, uint32_t waterFallingDelay);
	virtual ~Water ();

	float getHeight () const;
	bool isWaterRisingDue () const;
	bool isWaterFallingDue () const;

	// will return true if this map will at some point rise the water
	bool isWaterRisingEnabled () const;
	bool isWaterFallingEnabled () const;
	bool isWaterChangeOver () const;

	void createBody (float waterHeight);

	// IEntity
	SpriteDefPtr getSpriteDef () const override;
	void update (uint32_t deltaTime) override;
	void onContact (b2Contact* contact, IEntity* entity) override;
	void endContact (b2Contact* contact, IEntity* entity) override;
	bool shouldCollide (const IEntity* entity) const override;
};

inline float Water::getHeight () const
{
	return getPos().y - _mapHeight;
}

inline bool Water::isWaterRisingDue () const
{
	if (_time < _waterRisingTime)
		return false;
	return _waterChangeSpeed > 0.00001f;
}

inline bool Water::isWaterRisingEnabled () const
{
	return _waterChangeSpeed > 0.00001f;
}

inline bool Water::isWaterFallingEnabled () const {
	return _waterFallingTime > 0;
}

inline bool Water::isWaterChangeOver () const
{
	return _time > _waterRisingTime && _time > _waterFallingTime;
}

inline bool Water::isWaterFallingDue () const
{
	if (_time < _waterFallingTime)
		return false;
	return _waterChangeSpeed > 0.00001f;
}

}