started work on combat subsystem and triggers

This commit is contained in:
gyoder 2026-01-05 20:00:46 -07:00
parent e14aab570b
commit 9a3ad7d7b7
4 changed files with 50 additions and 2 deletions

View file

@ -5,6 +5,7 @@ use rand::Rng;
use crate::{
GameState, PauseState,
gameplay::combat::StartCombat,
utils::input::{GameInputPlugin, InputButton, InputPressStatus},
};
@ -20,6 +21,8 @@ impl Plugin for NaviGameplayPlugin {
(
move_player
.run_if(in_state(GameState::Navi).and(in_state(PauseState::Running))),
detect_colision
.run_if(in_state(GameState::Navi).and(in_state(PauseState::Running))),
follow_player,
),
);
@ -68,14 +71,18 @@ pub fn spawn_bus(mut commands: Commands, asset_server: Res<AssetServer>) {
));
}
#[derive(Component)]
pub struct MapEncounter(i32);
pub fn spawn_enemy(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
let mut rng = rand::rng();
for _ in 0..10 {
for i in 0..10 {
commands.spawn((
MapEncounter(i),
Mesh2d(meshes.add(Circle::new(10.))),
MeshMaterial2d(materials.add(Color::srgb(1.1, 0.2, 0.3))),
Transform::from_xyz(
@ -121,6 +128,21 @@ pub fn move_player(
}
}
fn detect_colision(
player: Single<&Transform, With<PlayerVWBus>>,
enemies: Query<(&Transform, &MapEncounter), (With<MapEncounter>, Without<MainCamera>)>,
mut start_combat_writer: MessageWriter<StartCombat>,
mut next_state: ResMut<NextState<GameState>>, // May or may not need
) {
for (en_trans, enc) in enemies {
if (en_trans.translation - player.translation).length() < 30. {
info!("colide {}", enc.0);
start_combat_writer.write(StartCombat(enc.0));
next_state.set(GameState::Combat);
}
}
}
fn follow_player(
mut camera: Single<&mut Transform, (With<MainCamera>, Without<PlayerVWBus>)>,
player: Single<&Transform, (With<PlayerVWBus>, Without<MainCamera>)>,