Skip to content

Commit ce63b3f

Browse files
committed
feat: rose has dynamic stem height with repeating |~ and | rows
1 parent 7516816 commit ce63b3f

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

src/animations/garden.rs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,17 @@ const CLOUD_COLOR: (u8, u8, u8) = (200, 200, 220);
7777
const RAIN_COLOR: (u8, u8, u8) = (150, 200, 255);
7878
const SKY_DIM: (u8, u8, u8) = (15, 25, 50);
7979

80+
// Static rows used to build rose shapes dynamically at spawn time
81+
static ROSE_STEM: &[(i32, char, bool)] = &[(0, '|', false)];
82+
static ROSE_STEM_LEAF: &[(i32, char, bool)] = &[(0, '|', false), (1, '~', false)];
83+
static ROSE_BRANCH: &[(i32, char, bool)] = &[(0, 'Y', false)];
84+
static ROSE_BLOOM: &[(i32, char, bool)] = &[(-1, '(', true), (0, '@', true), (1, ')', true)];
85+
8086
struct Plant {
8187
col: usize,
8288
variety: usize,
83-
stage: usize, // 0 = seed, max_rows = full bloom
84-
max_rows: usize, // randomised height cap: 2–5 rows
89+
stage: usize, // 0 = seed; shape.len() = full bloom
90+
shape: Vec<PRow>, // rows bottom→top, generated at spawn
8591
}
8692

8793
struct Raindrop {
@@ -122,11 +128,29 @@ impl Garden {
122128
let num_plants = ((width as f64 / 8.0) * scale).clamp(3.0, 20.0) as usize;
123129
let spacing = (width / (num_plants + 1)).max(1);
124130
let plants: Vec<Plant> = (0..num_plants)
125-
.map(|i| Plant {
126-
col: spacing * (i + 1),
127-
variety: rng.random_range(0..VARIETIES.len()),
128-
stage: 0,
129-
max_rows: rng.random_range(2..=5),
131+
.map(|i| {
132+
let variety = rng.random_range(0..VARIETIES.len());
133+
let shape: Vec<PRow> = if variety == 0 {
134+
// Rose: plain stems × 1-3, leafed stems × 1-3, branch, bloom
135+
let plain = rng.random_range(1..=3_usize);
136+
let leafed = rng.random_range(1..=3_usize);
137+
let mut s: Vec<PRow> = Vec::new();
138+
for _ in 0..plain {
139+
s.push(ROSE_STEM);
140+
}
141+
for _ in 0..leafed {
142+
s.push(ROSE_STEM_LEAF);
143+
}
144+
s.push(ROSE_BRANCH);
145+
s.push(ROSE_BLOOM);
146+
s
147+
} else {
148+
// Other varieties: take the top N rows so bloom is always included
149+
let v = VARIETIES[variety];
150+
let rows = rng.random_range(3..=v.len());
151+
v[v.len() - rows..].to_vec()
152+
};
153+
Plant { col: spacing * (i + 1), variety, stage: 0, shape }
130154
})
131155
.collect();
132156

@@ -308,7 +332,7 @@ impl Animation for Garden {
308332
for plant in &mut self.plants {
309333
let lo = plant.col.saturating_sub(2);
310334
let hi = plant.col + 2;
311-
if hit_x >= lo && hit_x <= hi && plant.stage < plant.max_rows {
335+
if hit_x >= lo && hit_x <= hi && plant.stage < plant.shape.len() {
312336
plant.stage += 1;
313337
}
314338
}
@@ -356,8 +380,8 @@ impl Animation for Garden {
356380
continue;
357381
}
358382

359-
let rows = VARIETIES[plant.variety];
360-
let rows_to_draw = plant.stage.min(plant.max_rows).min(rows.len());
383+
let rows = &plant.shape;
384+
let rows_to_draw = plant.stage.min(rows.len());
361385

362386
for (row_idx, row) in rows[..rows_to_draw].iter().enumerate() {
363387
let y = ground_y as i32 - 1 - row_idx as i32;

0 commit comments

Comments
 (0)