-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35391eb
commit 276ff11
Showing
15 changed files
with
302 additions
and
52 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,29 @@ | ||
export function generateRandomTrees() {} | ||
import { generateId } from "../../../../common/idGenerator.js"; | ||
import { Entity } from "../../../entity/entity.js"; | ||
import { treePrefab } from "../../../prefab/treePrefab.js"; | ||
import { placeRandomEntity } from "../../tilesetPlacer.js"; | ||
import { | ||
BiomeMap, | ||
BiomeMapItem, | ||
BiomeMapItemEntityFactory, | ||
} from "../biomeMap.js"; | ||
|
||
export function generateRandomTrees(map: BiomeMap) { | ||
const randomAmount = 64 + Math.floor(Math.random() * 200); | ||
placeRandomEntity(map, "tree", randomAmount, treeFactory); | ||
} | ||
|
||
export function generateRandomBushes() {} | ||
|
||
function treeFactory( | ||
item: BiomeMapItem, | ||
biome: BiomeMap, | ||
_allMaps: ReadonlyArray<BiomeMap>, | ||
rootEntity: Entity, | ||
) { | ||
const position = biome.worldPosition(item); | ||
const variant = Math.floor(Math.random() * 3); | ||
const tree = treePrefab(generateId("tree"), variant); | ||
tree.worldPosition = position; | ||
rootEntity.addChild(tree); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,54 @@ | ||
export function generateForrest() {} | ||
import { tilesets } from "../../../../../generated/tilesets.js"; | ||
import { sizeOfBounds } from "../../../../common/bounds.js"; | ||
import { generateId } from "../../../../common/idGenerator.js"; | ||
import { addPoint } from "../../../../common/point.js"; | ||
import { Entity } from "../../../entity/entity.js"; | ||
import { treePrefab } from "../../../prefab/treePrefab.js"; | ||
import { TilesetVariant } from "../../tileset.js"; | ||
import { placeTileset } from "../../tilesetPlacer.js"; | ||
import { BiomeMap, BiomeMapItem } from "../biomeMap.js"; | ||
|
||
export function generateForrest(map: BiomeMap) { | ||
const maxBudget = (32 * 32) / 4; | ||
const tileBudget = Math.floor(Math.random() * maxBudget) + maxBudget; | ||
let usedBudget = 0; | ||
while (usedBudget < tileBudget) { | ||
const placedBounds = placeTileset(tilesets.forrest, map, treeFactory); | ||
if (placedBounds) { | ||
const size = sizeOfBounds(placedBounds); | ||
const amount = size.x * size.y; | ||
usedBudget += amount; | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
function treeFactory(tilesetVariant: TilesetVariant) { | ||
return ( | ||
item: BiomeMapItem, | ||
biome: BiomeMap, | ||
_allMaps: ReadonlyArray<BiomeMap>, | ||
rootEntity: Entity, | ||
) => { | ||
for (const entity of tilesetVariant.entities) { | ||
switch (entity.id) { | ||
case "forrest": | ||
const treeVariant = Math.floor(Math.random() * 3); | ||
const treeEntity = treePrefab( | ||
generateId("tree"), | ||
treeVariant, | ||
); | ||
|
||
treeEntity.worldPosition = addPoint( | ||
biome.worldPosition(item), | ||
entity.position, | ||
); | ||
rootEntity.addChild(treeEntity); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,58 @@ | ||
export function generateForrestLake() {} | ||
import { tilesets } from "../../../../../generated/tilesets.js"; | ||
import { randomEntry, shuffleItems } from "../../../../common/array.js"; | ||
import { | ||
getAllPositionsBoundsFitWithinBounds, | ||
sizeOfBounds, | ||
} from "../../../../common/bounds.js"; | ||
import { generateId } from "../../../../common/idGenerator.js"; | ||
import { addPoint } from "../../../../common/point.js"; | ||
import { WaterComponent } from "../../../component/world/waterComponent.js"; | ||
import { Entity } from "../../../entity/entity.js"; | ||
import { Tileset, TilesetVariant, getLargestSize } from "../../tileset.js"; | ||
import { placeTileset } from "../../tilesetPlacer.js"; | ||
import { | ||
BiomeMap, | ||
BiomeMapItem, | ||
BiomeMapItemEntityFactory, | ||
} from "../biomeMap.js"; | ||
|
||
export function generateForrestLake(map: BiomeMap) { | ||
const maxBudget = (32 * 32) / 10; | ||
const tileBudget = Math.floor(Math.random() * maxBudget); | ||
let usedBudget = 0; | ||
while (usedBudget < tileBudget) { | ||
const placedBounds = placeTileset(tilesets.pond, map, lakeFactory); | ||
if (placedBounds) { | ||
const size = sizeOfBounds(placedBounds); | ||
const amount = size.x * size.y; | ||
usedBudget += amount; | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
function lakeFactory(tilesetVariant: TilesetVariant) { | ||
return ( | ||
item: BiomeMapItem, | ||
biome: BiomeMap, | ||
_allMaps: ReadonlyArray<BiomeMap>, | ||
rootEntity: Entity, | ||
) => { | ||
for (const entity of tilesetVariant.entities) { | ||
switch (entity.id) { | ||
case "water": | ||
const waterEntity = new Entity(generateId("water")); | ||
waterEntity.addComponent(new WaterComponent()); | ||
waterEntity.worldPosition = addPoint( | ||
biome.worldPosition(item), | ||
entity.position, | ||
); | ||
rootEntity.addChild(waterEntity); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.