From 7bf0d9c44857ddfc35a3109d468871f73289e2f6 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 15 Jun 2008 13:23:16 +0100 Subject: [PATCH] Add a MIN_SURFACE_HEIGHT constant --- src/Surface.cpp | 16 ++++++++++------ src/Surface.hpp | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Surface.cpp b/src/Surface.cpp index c9d934b..9bae746 100644 --- a/src/Surface.cpp +++ b/src/Surface.cpp @@ -18,9 +18,10 @@ #include "Surface.hpp" #include "LoadOnce.hpp" -const int Surface::VARIANCE = 65; // Bumpyness of landscape -const int Surface::MAX_SURFACE_HEIGHT = 300; -const int Surface::SURFACE_SIZE = 20; +const int Surface::VARIANCE(65); // Bumpyness of landscape +const int Surface::MAX_SURFACE_HEIGHT(300); +const int Surface::MIN_SURFACE_HEIGHT(10); +const int Surface::SURFACE_SIZE(20); Texture *Surface::surfTexture[Surface::NUM_SURF_TEX]; @@ -88,7 +89,7 @@ void Surface::Generate(int surftex, LandingPadList &pads) do change = surface[i].points[1].y + (rand()%VARIANCE-(VARIANCE/2)); - while (change > MAX_SURFACE_HEIGHT || change < 0); + while (change > MAX_SURFACE_HEIGHT || change < MIN_SURFACE_HEIGHT); surface[i].points[2].x = SURFACE_SIZE; surface[i].points[2].y = change; } @@ -96,8 +97,11 @@ void Surface::Generate(int surftex, LandingPadList &pads) // Make flat terrain for landing pad if (i != 0) change = surface[i-1].points[2].y; - else - change = rand()%MAX_SURFACE_HEIGHT; + else { + do + change = rand()%MAX_SURFACE_HEIGHT; + while (change > MAX_SURFACE_HEIGHT || change < MIN_SURFACE_HEIGHT); + } surface[i].points[1].x = 0; surface[i].points[1].y = change; surface[i].points[2].x = SURFACE_SIZE; diff --git a/src/Surface.hpp b/src/Surface.hpp index dae5940..968b3ff 100644 --- a/src/Surface.hpp +++ b/src/Surface.hpp @@ -36,6 +36,7 @@ public: static const int NUM_SURF_TEX = 5; // Number of available surface textures static const int SURFACE_SIZE; static const int MAX_SURFACE_HEIGHT; + static const int MIN_SURFACE_HEIGHT; static const int VARIANCE; private: -- 2.39.2