| Rev | Line | |
|---|
| [20338] | 1 | /**
|
|---|
| [20400] | 2 | * @file A Terrain is a class that modifies an arbitrary property of a given tile.
|
|---|
| [20338] | 3 | */
|
|---|
| [9096] | 4 |
|
|---|
| [20338] | 5 | /**
|
|---|
| 6 | * SimpleTerrain paints the given texture on the terrain.
|
|---|
| 7 | *
|
|---|
| 8 | * Optionally it places an entity on the affected tiles and
|
|---|
| 9 | * replaces prior entities added by SimpleTerrain on the same tile.
|
|---|
| 10 | */
|
|---|
| 11 | function SimpleTerrain(texture, templateName = undefined)
|
|---|
| [9096] | 12 | {
|
|---|
| 13 | if (texture === undefined)
|
|---|
| [20324] | 14 | throw new Error("SimpleTerrain: texture not defined");
|
|---|
| [18840] | 15 |
|
|---|
| [9096] | 16 | this.texture = texture;
|
|---|
| [20338] | 17 | this.templateName = templateName;
|
|---|
| [9096] | 18 | }
|
|---|
| 19 |
|
|---|
| [20980] | 20 | SimpleTerrain.prototype.place = function(position)
|
|---|
| [9096] | 21 | {
|
|---|
| [21069] | 22 | if (this.templateName && g_Map.validTilePassable(position))
|
|---|
| 23 | g_Map.setTerrainEntity(this.templateName, 0, Vector2D.add(position, new Vector2D(0.5, 0.5)), randomAngle());
|
|---|
| [18840] | 24 |
|
|---|
| [20988] | 25 | g_Map.setTexture(position, this.texture);
|
|---|
| [9096] | 26 | };
|
|---|
| 27 |
|
|---|
| [20338] | 28 | /**
|
|---|
| 29 | * RandomTerrain places one of the given Terrains on the tile.
|
|---|
| 30 | * It choses a random Terrain each tile.
|
|---|
| 31 | * This is commonly used to create heterogeneous forests.
|
|---|
| 32 | */
|
|---|
| [9096] | 33 | function RandomTerrain(terrains)
|
|---|
| 34 | {
|
|---|
| 35 | if (!(terrains instanceof Array) || !terrains.length)
|
|---|
| [20324] | 36 | throw new Error("RandomTerrain: Invalid terrains array");
|
|---|
| [18840] | 37 |
|
|---|
| [9096] | 38 | this.terrains = terrains;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| [20980] | 41 | RandomTerrain.prototype.place = function(position)
|
|---|
| [9096] | 42 | {
|
|---|
| [20980] | 43 | pickRandom(this.terrains).place(position);
|
|---|
| [9096] | 44 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.