@@ -180,6 +180,29 @@ pub fn spawn_trash(
180
180
mut previous_spawn_position : Local < f32 > ,
181
181
) {
182
182
183
+ static TRASH_WORD_LENGTH_CHANCES : [ u8 ; 20 ] = [
184
+ 2 ,
185
+ 2 ,
186
+ 3 ,
187
+ 3 ,
188
+ 3 ,
189
+ 3 ,
190
+ 4 ,
191
+ 4 ,
192
+ 4 ,
193
+ 4 ,
194
+ 4 ,
195
+ 4 ,
196
+ 4 ,
197
+ 4 ,
198
+ 5 ,
199
+ 5 ,
200
+ 6 ,
201
+ 6 ,
202
+ 7 ,
203
+ 8 ,
204
+ ] ;
205
+
183
206
static SPAWN_CHANCES : [ TrashType ; 9 ] = [
184
207
TrashType :: Bottle ,
185
208
TrashType :: Pizza ,
@@ -212,8 +235,10 @@ pub fn spawn_trash(
212
235
213
236
let random_x = get_random_coordinate ( max_x, * previous_spawn_position) ;
214
237
* previous_spawn_position = random_x;
238
+
215
239
let trash_type: TrashType = SPAWN_CHANCES [ random. gen_range ( 0 ..SPAWN_CHANCES . len ( ) ) ] . clone ( ) ;
216
240
let power_up: PowerUp = POWER_UP_CHANCES [ random. gen_range ( 0 ..POWER_UP_CHANCES . len ( ) ) ] . clone ( ) ;
241
+ let word_length = TRASH_WORD_LENGTH_CHANCES [ random. gen_range ( 0 ..TRASH_WORD_LENGTH_CHANCES . len ( ) ) ] ;
217
242
218
243
// TODO: make sure the same word doesn't appear twice in a row
219
244
// A solution might be to have search to search for a word as long as it's not in a list of
@@ -224,9 +249,8 @@ pub fn spawn_trash(
224
249
trash. power_up = power_up;
225
250
}
226
251
227
- let word = get_random_word ( & available_words) ;
228
252
let trash_text = TrashBundle :: create_text (
229
- word . clone ( ) ,
253
+ get_random_word_with_length ( & available_words , word_length ) ,
230
254
Anchor :: Custom ( Vec2 :: new ( 0.0 , -2.0 ) ) ,
231
255
Color :: GREEN ,
232
256
TextStyle {
@@ -369,6 +393,16 @@ fn delete_all_play_entities(
369
393
}
370
394
}
371
395
396
+ fn get_random_word_with_length ( available_words : & Res < AvailableWords > , length : u8 ) -> String {
397
+ let mut word = "" . to_string ( ) ;
398
+
399
+ while word. len ( ) != length as usize {
400
+ word = get_random_word ( available_words) ;
401
+ }
402
+
403
+ word
404
+ }
405
+
372
406
fn get_random_word ( available_words : & Res < AvailableWords > ) -> String {
373
407
let mut random = rand:: thread_rng ( ) ;
374
408
let mut random_words: Vec < String > = Vec :: new ( ) ;
0 commit comments