Skip to content

Commit

Permalink
feat: multi species support #2
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-85 authored and Sceat committed Jun 20, 2024
1 parent d4317e1 commit c791100
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/procgen/BlocksMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum BlockType {
WATER,
TREE_TRUNK,
TREE_FOLIAGE,
TREE_FOLIAGE_2,
SAND,
GRASS,
MUD,
Expand Down
4 changes: 2 additions & 2 deletions src/procgen/Vegetation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export class Vegetation {
treeBuffer = new Array(count).fill(BlockType.NONE)
// tree foliage
for (let y = -treeRadius; y < treeRadius; y++) {
const isFoliage = TreeGenerators[treeType](xzProj, y, treeRadius)//TreeGenerator.AppleTree(xzProj, y, treeRadius)
treeBuffer.push(isFoliage ? BlockType.TREE_FOLIAGE : BlockType.NONE)
const blockType = TreeGenerators[treeType](xzProj, y, treeRadius)//TreeGenerator.AppleTree(xzProj, y, treeRadius)
treeBuffer.push(blockType)
}
} else {
try {
Expand Down
8 changes: 5 additions & 3 deletions src/tools/TreeGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type TreeGenerator = (xzProj: number, y: number, range: number) => Boolean
import { BlockType } from "../index"

export type TreeGenerator = (xzProj: number, y: number, range: number) => BlockType

export enum TreeType {
PineTree = 'pine_tree',
Expand All @@ -8,13 +10,13 @@ export enum TreeType {
const AppleTree = (xzProj: number, y: number, range: number) => {
const dist = Math.sqrt(Math.pow(xzProj, 2) + Math.pow(y, 2))
const isFoliage = dist <= range
return isFoliage
return isFoliage? BlockType.TREE_FOLIAGE: BlockType.NONE
}

const PineTree = (xzProj: number, y: number, range: number) => {
const dist = xzProj // xzProj*(y+radius)
const isFoliage = dist <= range * (1 - 0.35 * (y + range) / range)
return isFoliage
return isFoliage? BlockType.TREE_FOLIAGE_2: BlockType.NONE
}

export const TreeGenerators: Record<TreeType, TreeGenerator> = {
Expand Down

0 comments on commit c791100

Please sign in to comment.