CGE2: Implement CGE2Engine::mapCross().

Rework Map during the process.
This commit is contained in:
uruk 2014-06-08 14:26:42 +02:00
parent ba8bc2e40b
commit 93010a8407
3 changed files with 21 additions and 5 deletions

View file

@ -28,6 +28,7 @@
#include "cge2/hero.h"
#include "cge2/text.h"
#include "cge2/cge2_main.h"
#include "cge2/map.h"
namespace CGE2 {
@ -437,8 +438,23 @@ int Hero::mapCross(const V3D &a, const V3D &b) {
}
int CGE2Engine::mapCross(const V2D &a, const V2D &b) {
warning("STUB: CGE2Engine::mapCross()");
return 0;
int cnt = 0;
V2D *n0 = nullptr;
V2D *p = nullptr;
for (int i = 0; i < _map->size(); i++) {
V2D *n = _map->getCoord(i);
if (p) {
if (cross(a, b, *n0, *n))
++cnt;
if (n == p)
p = nullptr;
} else {
p = n;
}
n0 = n;
}
return cnt;
}
void Hero::setCave(int c) {

View file

@ -86,8 +86,8 @@ int Map::size() {
return _container.size();
}
V2D &Map::operator[](int idx) {
return _container[idx];
V2D *Map::getCoord(int idx) {
return &_container[idx];
}
} // End of namespace CGE2

View file

@ -47,7 +47,7 @@ public:
void clear();
void load(int scene);
int size();
V2D &operator[](int idx);
V2D *getCoord(int idx);
};
} // End of namespace CGE2