--- a/src/proto2/Terrain.cc Sun Nov 30 13:31:32 2008 +0000
+++ b/src/proto2/Terrain.cc Sun Nov 30 13:52:48 2008 +0000
@@ -4,8 +4,8 @@
#include <algorithm>
#include <ClanLib/display.h>
-Terrain::Terrain(const Vector &scale) : scale(scale) {}
-Terrain::Terrain(const Vector &scale, const int &seed) : scale(scale) {
+Terrain::Terrain() {}
+Terrain::Terrain(const int &seed) {
this->generateTerrain(seed);
}
Terrain::Terrain(const Terrain &t) {
@@ -14,11 +14,6 @@
}
void Terrain::generatePixelBuffer() {
- // These could be somewhere else
- const CL_Color colorEmpty(86, 41, 0);
- const CL_Color colorDirt(144, 82, 23);
- const CL_Color colorRock(132, 136, 135);
-
this->pixbuf = CL_PixelBuffer(MAP_WIDTH, MAP_HEIGHT, 4*MAP_WIDTH,
CL_PixelFormat::rgba8888);
@@ -27,13 +22,13 @@
for (uint16_t j = 0; j < MAP_HEIGHT; j++) {
switch(terrain[i][j]) {
case EMPTY:
- color = colorEmpty;
+ color = COLOR_EMPTY;
break;
case DIRT:
- color = colorDirt;
+ color = COLOR_DIRT;
break;
case ROCK:
- color = colorRock;
+ color = COLOR_ROCK;
break;
default: // TODO: Shouldn't be here.
break;
@@ -44,9 +39,12 @@
}
Vector Terrain::getPixelLocation(Vector point) {
- Vector scal(scale.x/MAP_WIDTH, scale.y/MAP_HEIGHT);
- return Vector((int)round(point.x/scal.x),
- (int)round(point.y/scal.y));
+ return Vector(scale(point.x),
+ scale(point.y));
+}
+
+uint16_t Terrain::scale(float x) {
+ return (uint16_t)round(x/MAP_SCALE);
}
TerrainType Terrain::getType(uint16_t x, uint16_t y) {
@@ -107,9 +105,11 @@
}
void Terrain::removeGround(const Vector &pos, const float r) {
- // TODO: Implement. Some circle algoritmh should be usefull here.
+ // TODO: Implement. Some circle algoritmh should be usefull here,
+ // though the current impelementation doesn't seem too bad either.
- // Remember also to redraw the pixelbuffer
+ Vector midpoint = getPixelLocation(pos);
+
}
--- a/src/proto2/Terrain.hh Sun Nov 30 13:31:32 2008 +0000
+++ b/src/proto2/Terrain.hh Sun Nov 30 13:52:48 2008 +0000
@@ -20,7 +20,6 @@
*/
class Terrain {
private:
- const Vector scale;
std::vector<std::vector<TerrainType> > terrain;
// Terrain graphic
@@ -40,6 +39,13 @@
*/
Vector getPixelLocation(Vector point);
+ /**
+ * Scale parameter to "pixels"
+ *
+ * @param x Scaled value
+ * @return Corresponding value in pixels
+ */
+ uint16_t scale(float x);
/**
* Return the type of terrain at given position. Returns ROCK if
@@ -57,7 +63,7 @@
*
* @param scale The "real" width and height of the terrain.
*/
- Terrain(const Vector &scale);
+ Terrain();
/**
* Constructor.
*
@@ -65,7 +71,7 @@
* @param seed Random number generator seed used to create the
* terrain.
*/
- Terrain(const Vector &scale, const int &seed);
+ Terrain(const int &seed);
/**
* Copy constructor.
*