New progress

Add target goal

Add a goal for notes.

struct TargetNote;

fn setup_target_notes(mut commands: Commands, materials: Res<NoteMaterialResource>) {
    let transform = Transform::from_translation(Vec3::new(TARGET_POSITION, 150., 1.));
    commands
        .spawn_bundle(SpriteBundle {
            material: materials.target_texture.clone(),
            sprite: Sprite::new(Vec2::new(90., 90.)),
            transform,
            ..Default::default()
        })
        .insert(TargetNote);
}

Despawn Note

Make despawn_notes function in notes.rs to make notes

  • Despawn after notes go out of screen
  • note.types.key_just_pressed is same as &keyboard_input and note is in goal threshold
fn despawn_notes(
    mut commands: Commands,
    query: Query<(Entity, &Transform, &Note)>,
    keyboard_input: Res<Input<KeyCode>>,
) {
    for (entity, transform, note) in query.iter() {
        let pos = transform.translation.x;

        // Check if note is inside clicking threshold
        if (TARGET_POSITION - THRESHOLD..=TARGET_POSITION + THRESHOLD).contains(&pos)
            && note.types.key_just_pressed(&keyboard_input)
        {
            commands.entity(entity).despawn();
        }

        // Despawn notes after they leave the screen
        if pos <= 2. * TARGET_POSITION {
            commands.entity(entity).despawn();
        }
    }
}

Implement note types

Add NoteTypes to determine on spawn_notes that which texture (Don or Kat) to load.

Code quality

Delete dead code

Delete struct SpawnTimer(Timer); that we harded code to make spawn_note to spawn a note every second (But we have SongConfig now that’s why this code is dead now.)