Skip to content

Commit

Permalink
Add apples, lilies and blossoms
Browse files Browse the repository at this point in the history
  • Loading branch information
ottosichert committed Nov 28, 2023
1 parent e453c28 commit 88d4186
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/components/App/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ body,
color: var(--green);
}

.Lily {
color: var(--green);
}

.Bush {
color: var(--olive);
z-index: 20;
Expand Down
7 changes: 6 additions & 1 deletion src/engine/biomes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TileType } from "worldmap-generator";
import { Cell, Flower, Ice, Path, Rock, Sand, Water } from "./entities";
import { Cell, Flower, Ice, Lily, Path, Rock, Sand, Water } from "./entities";

export class World {
tileTypes: TileType[] = [];
Expand Down Expand Up @@ -51,6 +51,11 @@ export const basic = new Biome({
cell: { sprite: <Flower /> },
connections: { air: 50 }
},
lily: {
size: 5,
cell: { grounds: [<Lily amount={1} />] },
connections: { water: 1 }
},
ice: {
size: 50,
cell: { grounds: [<Ice amount={1} />] },
Expand Down
20 changes: 14 additions & 6 deletions src/engine/entities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ export const Ice: Ground = ({ amount }) => {
return <span className="Entity Ice">{densities[amount - 1]}</span>
}

/*
export const Lily: Ground = ({ amount }) => {
return <span className="Entity Plant">{'\u221e'}</span>;
return <span className="Entity Lily">{'\u221e'}</span>;
}
*/

export const grounds = [Water, Ice, Sand, Path];
export const grounds = [Water, Ice, Sand, Path, Lily];


// ------------------------ TERRAIN --------------------------------
Expand Down Expand Up @@ -152,10 +150,18 @@ export const Life: Item = ({ amount }) => {
return <span className="Entity Life">{'\u0102'}</span>;
}

export const Apple: Item = ({ amount }) => {
return <span className="Entity Life">.</span>;
}

export const Mana: Item = ({ amount }) => {
return <span className="Entity Mana">{'\u0103'}</span>;
}

export const Blossom: Item = ({ amount }) => {
return <span className="Entity Mana">{'\u011c'}</span>;
}

export const Experience: Item = ({ amount }) => {
if (amount === 1) return <span className="Entity Experience">{'+'}</span>;
if (amount === 2) return (
Expand Down Expand Up @@ -197,7 +203,7 @@ export const Iron: Item = ({ amount }) => {
return <span className="Entity Ore">{'\u00f7'}</span>;
}

export const items = [Life, Mana, Wood, Iron, Herb, Seed, Gold, Experience];
export const items = [Life, Apple, Blossom, Mana, Wood, Iron, Herb, Seed, Gold, Experience];


// ------------------------ SPRITE --------------------------------
Expand Down Expand Up @@ -388,6 +394,8 @@ export const counters = new Map<Item | undefined, Counters>([
[Seed, 'seed'],
[Wood, 'wood'],
[Iron, 'iron'],
[Apple, 'hp'],
[Blossom, 'mp'],
]);

export const bars = ['\u0127', '\u0126', '\u0125', '\u0124', '\u0123', '\u0122', '\u0121', '\u0120'];
Expand Down Expand Up @@ -415,7 +423,7 @@ export type Mode = 'equipped' | 'using';
export const materials = ['wood', 'iron', 'gold', 'fire', 'ice', 'plant', 'water'] as const;
export type Material = typeof materials[number];

export const containers = new Map<Sprite | Terrain | undefined, Item>([[Flower, Herb], [Bush, Seed], [Tree, Wood], [Rock, Iron]]);
export const containers = new Map<Sprite | Terrain | Ground | undefined, Item>([[Flower, Herb], [Bush, Seed], [Tree, Wood], [Rock, Iron], [Water, Blossom]]);

// ------------------------ ENTITY --------------------------------

Expand Down
32 changes: 27 additions & 5 deletions src/engine/generate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MapCell } from 'worldmap-generator';
import { creatureSpawns, creatureStats, getRandomDistribution } from './balancing';
import { World, world } from './biomes';

import { Player, Cell, SingleCategories, MultipleCategories, Entity, Rock, Flower, Tree, Bush, grounds, containers, Spell, Armor, Terrain, Sand, Water, Skin, CharacterSelect, Interaction } from "./entities";
import { Player, Cell, SingleCategories, MultipleCategories, Entity, Rock, Flower, Tree, Bush, grounds, containers, Spell, Armor, Terrain, Sand, Water, Skin, CharacterSelect, Interaction, Lily, Apple, Blossom } from "./entities";
import { generateFog } from './fog';
import { createMatrix, generateWhiteNoise, valueNoise } from './noise';
import { corners, createCreature, createEquipment, createInteraction, createParticle, getDeterministicRandomInt, orientations, Processor, sum, TerminalState, updateCell, wrapCoordinates } from "./utils";
Expand Down Expand Up @@ -99,6 +99,7 @@ function generateLevel(state: TerminalState): TerminalState {
}
//if (temperatureNoise <= 30 && height + temperatureNoise <= -45) name = 'ice';
if (name === 'air' && greenNoise >= 20) name = 'green';
if (name === 'water' && greenNoise >= 33 && height <= -47) name = 'lily';

return {
name,
Expand Down Expand Up @@ -130,6 +131,7 @@ function generateLevel(state: TerminalState): TerminalState {
}, {});
const sand = groundAmounts.find(({ ground }) => ground === Sand);
const water = groundAmounts.find(({ ground }) => ground === Water);
const lily = groundAmounts.find(({ ground }) => ground === Lily);
if (sand && sand.amount > 0) {
cell.grounds = [<Sand amount={1} />];
}
Expand All @@ -139,6 +141,9 @@ function generateLevel(state: TerminalState): TerminalState {
cell.grounds = [<Water amount={newWaterAmount} />, ...(cell.grounds || [])];
}
}
if (lily && lily.amount > 2 && !(sand && sand.amount > 0)) {
cell.grounds = [<Water amount={4} />, <Lily amount={1} />];
}

// Terrain: use quarter sized rocks
const terrainElements = getSingleElements(world, mapCells, 'terrain');
Expand All @@ -161,12 +166,29 @@ function generateLevel(state: TerminalState): TerminalState {

// Item: add container item if overlapping with noise
const itemNoise = itemMatrix[rowIndex][columnIndex];
const CellItem = containers.get(cell.sprite?.type || cell.terrain?.type);
if (CellItem && itemNoise > 48) {
cell.item = <CellItem amount={Math.floor(itemNoise - 46.5 )} />;
const CellItem = containers.get(cell.sprite?.type || cell.terrain?.type || cell.grounds?.[0]?.type);
if (CellItem && itemNoise > 46) {
const amount = Math.max(1, Math.floor((itemNoise - 48.7) * 2) + 1);
cell.item = <CellItem amount={amount} />;

if (cell.terrain?.type === Tree) {
cell.terrain = undefined;
if (Math.random() < 0.11) {
// apple tree
cell.item = <Apple amount={1} />;
} else {
// wood
cell.terrain = undefined;
}
}

// ensure only 1 mana
if (CellItem === Blossom) {
if (itemNoise > 49.87) {
cell.item = <Blossom amount={1} />;
cell.grounds = [<Water amount={4} />, <Lily amount={1} />];
} else {
cell.item = undefined;
}
}
}

Expand Down

0 comments on commit 88d4186

Please sign in to comment.