 |
Jypeli
9
The simple game programming library
|
Siirry tämän tiedoston dokumentaatioon.
39 public Surface(
double width,
double height )
47 this.heights =
new double[1] { height };
51 this.TextureFillsShape =
true;
60 this.TextureFillsShape =
true;
72 public Surface(
double width,
double min,
double max,
int points )
73 : this( width,
RandomGen.NextDoubleArray( Math.Max( min, 1.0f ), max, points ), 1.0 )
86 public Surface(
double width,
double min,
double max,
int points,
int maxchange )
87 : this( width,
RandomGen.NextDoubleArray( Math.Max( min, 1.0f ), max, points, maxchange ), 1.0 )
93 #region Static private methods for constructors
98 throw new Exception(
"At least two Y-points needed in order to create ground" );
100 throw new Exception(
"The heights must be positive and at least 1" );
108 double step = width / ( n - 1 );
113 double halfHeight = maxHeight / 2;
118 Vector bottomRight =
new Vector( width / 2, -halfHeight );
121 for (
int i = 0; i < n; i++ )
123 vertexes[i] =
new Vector( bottomRight.
X - ( i * step ), bottomRight.
Y );
126 double left = -width / 2;
129 for (
int i = 0; i < n; i++ )
146 double step = width / ( n - 1 );
148 Int16[] outlineIndices =
new Int16[n * 2];
150 for (
int i = 0; i < n * 2; i++ )
151 outlineIndices[i] = (Int16)i;
152 for (
int i = 0; i < n - 1; i++ )
154 triangles[2 * i] =
new IndexTriangle( i, 2 * n - i - 2, 2 * n - i - 1 );
155 triangles[2 * i + 1] =
new IndexTriangle( i, i + 1, 2 * n - i - 2 );
158 Vector[] outlineVertices =
new Vector[outlineIndices.Length];
159 for (
int i = 0; i < outlineIndices.Length; i++ )
160 outlineVertices[i] = vertexes[outlineIndices[i]];
162 return new Polygon(
new ShapeCache( vertexes, triangles, outlineIndices ),
false );
168 double minHeightDifference =
double.PositiveInfinity;
170 for (
int i = 0; i < n - 1; i++ )
173 if ( diff >
double.Epsilon && diff < minHeightDifference ) minHeightDifference = diff;
176 return minHeightDifference;
181 #region Factory methods
440 #region Public methods
444 if (
heights ==
null || x < Left || x >
Right )
return Top;
447 double step = Width / ( n - 1 );
450 double indexX = ( Width / 2 + x ) / step;
451 int lowerIndex = (int)Math.Floor( indexX );
452 int upperIndex = (int)Math.Ceiling( indexX );
454 if ( upperIndex >= n )
return Top;
458 double relX = ( Width / 2 + x ) % step;
468 double step = Width / ( n - 1 );
471 double indexX = ( Width / 2 + x ) / step;
472 int lowerIndex = (int)Math.Floor( indexX );
473 int upperIndex = (int)Math.Ceiling( indexX );
476 if ( lowerIndex == upperIndex )
double GetBorderThickness()
static Direction Left
Suunta vasemmalle.
double GetGroundHeight(double x)
static readonly Vector UnitY
Pystysuuntainen yksikkövektori (pituus 1, suunta ylös).
static Polygon CreateShape(double width, double[] heights, Vector[] vertexes)
double Height
Kentän korkeus.
static Direction Up
Suunta ylös.
Vector GetGroundNormal(double x)
static Surface CreateTop(Level level, double min, double max, int points)
Luo kentälle epätasaisen yläreunan. Ei lisää reunaa automaattisesti kenttään.
Sisältää valmiiksi lasketut kolmiot, joiden avulla piirtäminen on suoraviivaista.
double Width
Kentän leveys.
Surface(double width, double min, double max, int points)
Luo satunnaisen pinnan.
double Bottom
Kentän alareunan y-koordinaatti.
static Surface CreateRight(Level level, double min, double max, int points)
Luo kentälle epätasaisen oikean reunan. Ei lisää reunaa automaattisesti kenttään.
static readonly Color ForestGreen
Metsänvihreä.
void InitializeFlat(double height)
static Surface CreateLeft(Level level, double min, double max, int points)
Luo kentälle epätasaisen vasemman reunan. Ei lisää reunaa automaattisesti kenttään.
static Direction Down
Suunta alas.
Pelikenttä, johon voi lisätä olioita. Kentällä voi myös olla reunat ja taustaväri tai taustakuva.
double Top
Kentän yläreunan y-koordinaatti.
static Surface Create(Level level, Direction direction, double min, double max, int points)
Luo kentälle epätasaisen reunan. Ei lisää reunaa automaattisesti kenttään.
static Surface Create(Level level, Direction direction)
Luo kentälle tasaisen reunan. Ei lisää reunaa automaattisesti kenttään.
Surface(double width, double min, double max, int points, int maxchange)
Luo satunnaisen pinnan.
static Angle ArcTan(double d)
Palauttaa kulman joka vastaa d:n arcus-tangentti.
Satunnaisgeneraattori. Luo satunnaisia arvoja, mm. lukuja, vektoreita sekä kulmia.
void InitializeRugged(double[] heights, double scale)
static Surface Create(Level level, Direction direction, double min, double max, int points, int maxchange)
Luo kentälle epätasaisen reunan. Ei lisää reunaa automaattisesti kenttään.
static double GetMinHeightDifference(double[] heights)
static Surface CreateLeft(Level level)
Luo kentälle tasaisen vasemman reunan. Ei lisää reunaa automaattisesti kenttään.
static Surface CreateLeft(Level level, double min, double max, int points, int maxchange)
Luo kentälle epätasaisen vasemman reunan. Ei lisää reunaa automaattisesti kenttään.
static Surface CreateRight(Level level, double min, double max, int points, int maxchange)
Luo kentälle epätasaisen oikean reunan. Ei lisää reunaa automaattisesti kenttään.
readonly Vector Center
Kentän keskipiste.
Surface(double width, double height)
Luo tasaisen pinnan.
static Vector[] CalculateVertexes(double width, double[] heights, double scale)
static Surface CreateRight(Level level)
Luo kentälle tasaisen oikean reunan. Ei lisää reunaa automaattisesti kenttään.
static Surface CreateTop(Level level)
Luo kentälle tasaisen yläreunan. Ei lisää reunaa automaattisesti kenttään.
static Surface CreateBottom(Level level, double min, double max, int points)
Luo kentälle epätasaisen alareunan. Ei lisää reunaa automaattisesti kenttään.
static Polygon CreateRuggedShape(double width, double[] heights, double scale)
static Vector FromLengthAndAngle(double length, double angle)
Luo vektorin pituuden ja kulman perusteella.
Muotojen määrityksessä käytettävä kolmio.
Surface(double width, double[] heights, double scale)
Helppo tapa lisätä kenttään epätasainen pinta. Pinta kuvataan luettelemalla Y-koordinaatteja vasemmal...
static Surface CreateBottom(Level level, double min, double max, int points, int maxchange)
Luo kentälle epätasaisen alareunan. Ei lisää reunaa automaattisesti kenttään.
static readonly Angle RightAngle
Suora kulma (90 astetta).
static Surface CreateBottom(Level level)
Luo kentälle tasaisen alareunan. Ei lisää reunaa automaattisesti kenttään.
double Right
Kentän oikean reunan x-koordinaatti.
Tasainen tai epätasainen pinta.
static Surface CreateTop(Level level, double min, double max, int points, int maxchange)
Luo kentälle epätasaisen yläreunan. Ei lisää reunaa automaattisesti kenttään.
static double CalculateHeight(double[] heights, double scale)
double Left
Kentän vasemman reunan x-koordinaatti.
static Direction Right
Suunta oikealle.
static readonly Angle StraightAngle
Oikokulma (180 astetta).
Suuntakulma (rajoitettu -180 ja 180 asteen välille) asteina ja radiaaneina. Tietoja kulmasta: http://...
void MakeStatic()
Tekee oliosta staattisen eli liikkumattoman.