the alien says "Hello World" if you talk to it
This commit is contained in:
parent
39aa5b04b3
commit
f6b067533c
58
src/actor.rs
58
src/actor.rs
|
@ -1,13 +1,25 @@
|
|||
use bevy::prelude::*;
|
||||
use crate::nature;
|
||||
use crate::{nature, settings, actor, audio, hud};
|
||||
|
||||
const MIN_INTERACT_DISTANCE: f32 = 30.0;
|
||||
|
||||
pub struct ActorPlugin;
|
||||
impl Plugin for ActorPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(FixedUpdate, update);
|
||||
app.add_systems(Update, (
|
||||
handle_conversations,
|
||||
handle_input,
|
||||
));
|
||||
app.add_event::<StartConversationEvent>();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Event)]
|
||||
pub struct StartConversationEvent {
|
||||
pub conv: String
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Actor {
|
||||
pub hp: f32,
|
||||
|
@ -26,6 +38,15 @@ impl Default for Actor {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Component)] pub struct Player;
|
||||
#[derive(Component)] pub struct PlayerInConversation;
|
||||
#[derive(Component)] pub struct InConversationWithPlayer;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Talker {
|
||||
pub conv: String,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct LifeForm {
|
||||
pub adrenaline: f32,
|
||||
|
@ -71,8 +92,39 @@ pub fn update(
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Player;
|
||||
pub fn handle_input(
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
settings: ResMut<settings::Settings>,
|
||||
query: Query<(&Talker, &Transform)>,
|
||||
player: Query<&Transform, With<actor::Player>>,
|
||||
mut ew_conv: EventWriter<StartConversationEvent>,
|
||||
mut ew_click: EventWriter<audio::AudioClickEvent>,
|
||||
)
|
||||
{
|
||||
if keyboard_input.just_pressed(settings.key_interact) {
|
||||
let mindist = MIN_INTERACT_DISTANCE * MIN_INTERACT_DISTANCE;
|
||||
if let Ok(player) = player.get_single() {
|
||||
for (talker, transform) in &query {
|
||||
if transform.translation.distance_squared(player.translation) <= mindist {
|
||||
ew_conv.send(StartConversationEvent{conv: talker.conv.clone()});
|
||||
ew_click.send(audio::AudioClickEvent());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_conversations(
|
||||
mut er_conv: EventReader<StartConversationEvent>,
|
||||
mut log: ResMut<hud::Log>,
|
||||
) {
|
||||
for my_event in er_conv.read() {
|
||||
log.add(my_event.conv.clone());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//pub enum SuitSystemHandler {
|
||||
// Heat,
|
||||
|
|
28
src/hud.rs
28
src/hud.rs
|
@ -21,8 +21,8 @@ impl Plugin for HudPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct GaugesText;
|
||||
#[derive(Component)] struct GaugesText;
|
||||
#[derive(Component)] struct ChatText;
|
||||
|
||||
#[derive(Resource)]
|
||||
struct FPSUpdateTimer(Timer);
|
||||
|
@ -33,7 +33,7 @@ struct Message {
|
|||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
struct Log {
|
||||
pub struct Log {
|
||||
logs: VecDeque<Message>,
|
||||
}
|
||||
|
||||
|
@ -192,6 +192,28 @@ fn setup(
|
|||
bundle_fps,
|
||||
GaugesText,
|
||||
));
|
||||
|
||||
// Add Chat Box
|
||||
// let bundle_chatbox = TextBundle::from_sections([
|
||||
// TextSection::new(
|
||||
// "Hello :D",
|
||||
// TextStyle {
|
||||
// font: asset_server.load(FONT),
|
||||
// font_size: settings.font_size_hud,
|
||||
// color: Color::GRAY,
|
||||
// ..default()
|
||||
// }
|
||||
// ),
|
||||
// ]).with_style(Style {
|
||||
// position_type: PositionType::Absolute,
|
||||
// bottom: Val::VMin(40.0),
|
||||
// left: Val::VMin(30.0),
|
||||
// ..default()
|
||||
// });
|
||||
// commands.spawn((
|
||||
// bundle_chatbox,
|
||||
// ChatText,
|
||||
// ));
|
||||
}
|
||||
|
||||
fn update(
|
||||
|
|
|
@ -21,6 +21,7 @@ pub struct Settings {
|
|||
pub key_down: KeyCode,
|
||||
pub key_run: KeyCode,
|
||||
pub key_stop: KeyCode,
|
||||
pub key_interact: KeyCode,
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
|
@ -45,6 +46,7 @@ impl Default for Settings {
|
|||
key_down: KeyCode::ControlLeft,
|
||||
key_run: KeyCode::KeyR,
|
||||
key_stop: KeyCode::Space,
|
||||
key_interact: KeyCode::KeyE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
13
src/world.rs
13
src/world.rs
|
@ -73,10 +73,7 @@ pub fn setup(
|
|||
actor::Suit {
|
||||
oxygen: nature::OXY_M,
|
||||
..default()
|
||||
}
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
},
|
||||
Camera3dBundle {
|
||||
camera: Camera {
|
||||
hdr: true, // HDR is required for bloom
|
||||
|
@ -193,7 +190,10 @@ pub fn setup(
|
|||
}
|
||||
|
||||
// Add alien
|
||||
commands.spawn(SceneBundle {
|
||||
commands.spawn((
|
||||
actor::Actor::default(),
|
||||
actor::Talker { conv: "Hello World!".to_string() },
|
||||
SceneBundle {
|
||||
transform: Transform {
|
||||
translation: Vec3::new(
|
||||
0.0,
|
||||
|
@ -205,7 +205,8 @@ pub fn setup(
|
|||
},
|
||||
scene: asset_server.load(ASSET_ASTRONAUT),
|
||||
..default()
|
||||
});
|
||||
},
|
||||
));
|
||||
|
||||
// Space is DARK
|
||||
ambient_light.brightness = 0.0;
|
||||
|
|
Loading…
Reference in a new issue