Untitled
unknown
rust
2 years ago
3.4 kB
10
Indexable
pub fn collect_flowers(
in_field: Res<InField>,
player_q: Query<&Transform, With<Player>>,
tool_q: Query<&Collector>,
mut flowerfields: ResMut<FlowerFields>,
mut event_reader: EventReader<Collect>,
mut pollen_res: ResMut<Pollen>,
mut flower_q: Query<&mut Transform, (With<Flower>, Without<Player>)>,
) {
for _event in event_reader.read() {
let mut which_flower_id_plus = 0;
let mut which_field: usize = 0;
if in_field.is_in_field {
match in_field.which_field.as_str() {
"field_1" => {
which_field = 0;
which_flower_id_plus = 0
}
"field_2" => {
which_field = 1;
which_flower_id_plus = 260
}
_ => println!(
"Field {} has a typo or I forgot to add it!",
in_field.which_field
),
};
let player_position = player_q.single().translation;
let mut vec_i_want: Vec3 = player_position;
let poses = flowerfields.flower_fields[which_field].positions.clone();
vec_i_want.y -= 0.5;
for (what_flower, &position) in poses.iter().enumerate() {
let field_position = flowerfields.flower_fields[which_field].field_pos;
let distance = vec_i_want.distance(position + field_position); // Calculate distance
if (distance < 1.65)
&& (flowerfields.flower_fields[which_field].flowers[what_flower].stage > 0)
{
let tool = tool_q.single();
let mut how_much_pollen: i32 = 0;
let mut times_cause_color: i32 = 1;
match flowerfields.flower_fields[which_field].flowers[what_flower].flower_type {
Type::White => times_cause_color = tool.collect_amount_white as i32,
Type::Blue => times_cause_color = tool.collect_amount_blue as i32,
Type::Red => times_cause_color = tool.collect_amount_red as i32,
};
how_much_pollen = flowerfields.flower_fields[which_field].flowers[what_flower]
.how_many as i32
* tool.collect_amount as i32
* times_cause_color;
pollen_res.pollen_in_backpack += how_much_pollen as i64;
// ==================
// === Other Part ===
// ==================
for (count, mut flower_transform) in flower_q.iter_mut().enumerate() {
if count as i32 == what_flower as i32 + which_flower_id_plus {
let flower_t = &mut *flower_transform; // Dereference Mut to get &mut Transform
flower_gets_harvested(
&mut flowerfields.flower_fields[which_field].flowers[what_flower],
flower_t,
);
break;
}
}
}
}
}
}
}Editor is loading...
Leave a Comment