 |
Jypeli
9
The simple game programming library
|
Siirry tämän tiedoston dokumentaatioon.
2 using System.Collections.Generic;
14 public delegate
void RouteMethod( List<Vector> route,
double width,
double height );
29 public void Invoke(
double tileWidth,
double tileHeight )
33 method(
new Vector( realX, realY ), tileWidth, tileHeight );
37 private List<TileMethodCall>
optimized =
new List<TileMethodCall>();
38 protected Dictionary<TileType, TileMethod>
legend =
new Dictionary<TileType, TileMethod>();
41 protected abstract TileType
Null {
get; }
45 if (
tiles.GetLength( 0 ) == 0 ||
tiles.GetLength( 1 ) == 0 )
46 throw new ArgumentException(
"All dimensions of tiles must be at least 1" );
56 get {
return tiles.GetLength( 0 ); }
64 get {
return tiles.GetLength( 1 ); }
90 legend[tileSymbol] = delegate(
Vector p,
double w,
double h ) { f( p, w, h, p1 ); };
106 legend[tileSymbol] = delegate(
Vector p,
double w,
double h ) { f( p, w, h, p1, p2 ); };
124 legend[tileSymbol] = delegate(
Vector p,
double w,
double h ) { f( p, w, h, p1, p2, p3 ); };
138 if ( tileSymbols ==
null || tileSymbols.Length < 1 )
139 throw new ArgumentException(
"Pass at least one tile symbol!" );
142 int vectorsAdded = 0;
144 for (
int i = 0; i < tileSymbols.Length; i++ )
147 legend[tileSymbols[i]] = delegate(
Vector p,
double w,
double h )
149 vectorTable[index] = p;
150 if ( ++vectorsAdded >= tileSymbols.Length )
151 f( vectorTable.ToList(), w, h );
179 public void Execute(
double tileWidth,
double tileHeight )
182 int width =
tiles.GetLength( 1 );
183 int height =
tiles.GetLength( 0 );
190 m.Invoke( tileWidth, tileHeight );
193 for (
int y = height - 1; y >= 0; y-- )
195 for (
int x = 0; x < width; x++ )
199 if ( method !=
null )
201 double realX = game.Level.Left + ( x * tileWidth ) + ( tileWidth / 2 );
202 double realY = game.Level.Top - ( y * tileHeight ) - ( tileHeight / 2 );
203 method(
new Vector( realX, realY ), tileWidth, tileHeight );
211 if ( symbol.Equals(
Null) )
return null;
213 foreach ( var key
in legend.Keys )
224 return a.Equals( b );
234 for (
int i = 0; i < symbols.Length; i++ )
248 throw new ArgumentException(
"Symbol " + sym +
" not added, cannot optimize.");
250 for (
int row = 0; row <
RowCount; row++ )
257 if ( w > 0 && h > 0 )
259 TileMethod newMethod = delegate (
Vector oldPos,
double oldWidth,
double oldHeight)
262 Vector newAdjust =
new Vector(oldWidth * w, -oldHeight * h);
263 Vector newPos = oldPos + ( oldAdjust + newAdjust ) / 2;
264 method( newPos, oldWidth * w, oldHeight * h );
266 optimized.Add(
new TileMethodCall( newMethod, row, col ) );
276 for ( width = 0; width <
ColumnCount - col; width++ )
288 for ( height = 1; height <
RowCount - row; height++ )
290 if ( !
RowEquals( row + height, col, width, sym ) )
295 private bool RowEquals(
int row,
int col,
int length, TileType sym )
297 for (
int i = col; i < col + length; i++ )
305 private void SetArea(
int row,
int col,
int width,
int height, TileType sym )
307 for (
int j = row; j < row + height; j++ )
309 for (
int i = col; i < col + width; i++ )
323 return tiles.GetLength( dimension );
334 return tiles[row,col];
344 public void SetTile(
int row,
int col, TileType c )
358 return new TileMethod( delegate(
Vector p,
double w,
double h ) { m( p, newWidth, newHeight ); } );
370 return new TileMethod( delegate(
Vector p,
double w,
double h ) { m( p, w * widthMultiplier, h * heightMultiplier ); } );
delegate void TileMethod< T1, T2 >(Vector position, double width, double height, T1 p1, T2 p2)
void Invoke(double tileWidth, double tileHeight)
List< TileMethodCall > optimized
void SetTile(int row, int col, TileType c)
Asettaa ruudussa olevan symbolin.
int ColumnCount
Sarakkeiden määrä kentässä (vaakasuoraan).
double Height
Kentän korkeus.
AbstractTileMap(TileType[,] tiles)
double Width
Kentän leveys.
delegate void TileMethod< T1, T2, T3 >(Vector position, double width, double height, T1 p1, T2 p2, T3 p3)
TileMethodCall(TileMethod m, int row, int col)
delegate void TileMethod(Vector position, double width, double height)
virtual bool SymbolEquals(TileType a, TileType b)
double Top
Kentän yläreunan y-koordinaatti.
int GetLength(int dimension)
Palauttaa annetun dimension pituuden (merkkeinä, ei pikseleinä).
delegate void RouteMethod(List< Vector > route, double width, double height)
static Game Instance
Käynnissä olevan pelin pääolio.
void SetArea(int row, int col, int width, int height, TileType sym)
static TileMethod ChangeSize(TileMethod m, double newWidth, double newHeight)
Muuttaa luontialiohjelman tekemän olion kokoa.
void Execute()
Käy kentän kaikki merkit läpi ja kutsuu SetTileMethod-metodilla annettuja aliohjelmia kunkin merkin k...
void SetTileMethod< T1 >(TileType tileSymbol, TileMethod< T1 > f, T1 p1)
Määrittää, että tietyn ruutukentän symbolin (tileSymbol) kohdalla kutsutaan aliohjelmaa f....
void Optimize(TileType sym)
Optimoi annetut ruudut niin, että useammat vierekkäiset oliot yhdistetään isommiksi olioiksi....
void SetTileMethod< T1, T2 >(TileType tileSymbol, TileMethod< T1, T2 > f, T1 p1, T2 p2)
Määrittää, että tietyn ruutukentän symbolin (tileSymbol) kohdalla kutsutaan aliohjelmaa f....
int RowCount
Rivien määrä kentässä (pystysuoraan).
void SetTileMethod< T1, T2, T3 >(TileType tileSymbol, TileMethod< T1, T2, T3 > f, T1 p1, T2 p2, T3 p3)
Määrittää, että tietyn ruutukentän symbolin (tileSymbol) kohdalla kutsutaan aliohjelmaa f....
void GetGreatestMatchingRectangle(TileType sym, int row, int col, out int width, out int height)
bool RowEquals(int row, int col, int length, TileType sym)
double Left
Kentän vasemman reunan x-koordinaatti.
void Optimize(params TileType[] symbols)
Optimoi annetut ruudut niin, että useammat vierekkäiset oliot yhdistetään isommiksi olioiksi....
delegate void TileMethod< T1 >(Vector position, double width, double height, T1 p1)
Dictionary< TileType, TileMethod > legend
void SetTileMethod(TileType tileSymbol, TileMethod f)
Määrittää, että tietyn ruutukentän symbolin (tileSymbol) kohdalla kutsutaan aliohjelmaa f....
TileMethod GetMethodForSymbol(TileType symbol)
static TileMethod ChangeSizeMultiplier(TileMethod m, double widthMultiplier, double heightMultiplier)
Muuttaa luontialiohjelman tekemän olion kokoa tietyllä kertoimilla.
TileType GetTile(int row, int col)
Palauttaa ruudussa olevan symbolin.
void SetRouteMethod(RouteMethod f, params TileType[] tileSymbols)
Kokoaa reitin useammasta ruutukentän symbolista.
void Execute(double tileWidth, double tileHeight)
Käy kentän kaikki merkit läpi ja kutsuu SetTileMethod-metodilla annettuja aliohjelmia kunkin merkin k...
Level Level
Aktiivinen kenttä.