started work on combat subsystem and triggers
This commit is contained in:
parent
e14aab570b
commit
9a3ad7d7b7
4 changed files with 50 additions and 2 deletions
24
src/gameplay/combat.rs
Normal file
24
src/gameplay/combat.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
use bevy::{
|
||||||
|
camera::visibility::RenderLayers, post_process::bloom::Bloom, prelude::*, sprite::Anchor,
|
||||||
|
};
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
GameState, PauseState,
|
||||||
|
utils::input::{GameInputPlugin, InputButton, InputPressStatus},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct CombatPlugin;
|
||||||
|
|
||||||
|
impl Plugin for CombatPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_message::<StartCombat>()
|
||||||
|
.add_message::<FinishedCombat>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Message)]
|
||||||
|
pub struct StartCombat(pub i32);
|
||||||
|
|
||||||
|
#[derive(Message)]
|
||||||
|
pub struct FinishedCombat(pub i32);
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
|
pub mod combat;
|
||||||
pub mod navi;
|
pub mod navi;
|
||||||
pub mod pause;
|
pub mod pause;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use rand::Rng;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
GameState, PauseState,
|
GameState, PauseState,
|
||||||
|
gameplay::combat::StartCombat,
|
||||||
utils::input::{GameInputPlugin, InputButton, InputPressStatus},
|
utils::input::{GameInputPlugin, InputButton, InputPressStatus},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -20,6 +21,8 @@ impl Plugin for NaviGameplayPlugin {
|
||||||
(
|
(
|
||||||
move_player
|
move_player
|
||||||
.run_if(in_state(GameState::Navi).and(in_state(PauseState::Running))),
|
.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,
|
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(
|
pub fn spawn_enemy(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
) {
|
) {
|
||||||
let mut rng = rand::rng();
|
let mut rng = rand::rng();
|
||||||
for _ in 0..10 {
|
for i in 0..10 {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
MapEncounter(i),
|
||||||
Mesh2d(meshes.add(Circle::new(10.))),
|
Mesh2d(meshes.add(Circle::new(10.))),
|
||||||
MeshMaterial2d(materials.add(Color::srgb(1.1, 0.2, 0.3))),
|
MeshMaterial2d(materials.add(Color::srgb(1.1, 0.2, 0.3))),
|
||||||
Transform::from_xyz(
|
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(
|
fn follow_player(
|
||||||
mut camera: Single<&mut Transform, (With<MainCamera>, Without<PlayerVWBus>)>,
|
mut camera: Single<&mut Transform, (With<MainCamera>, Without<PlayerVWBus>)>,
|
||||||
player: Single<&Transform, (With<PlayerVWBus>, Without<MainCamera>)>,
|
player: Single<&Transform, (With<PlayerVWBus>, Without<MainCamera>)>,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use bevy::{post_process::bloom::Bloom, prelude::*, sprite::Anchor};
|
use bevy::{post_process::bloom::Bloom, prelude::*, sprite::Anchor};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
gameplay::{navi::NaviGameplayPlugin, pause::PausePlugin},
|
gameplay::{combat::CombatPlugin, navi::NaviGameplayPlugin, pause::PausePlugin},
|
||||||
utils::input::{GameInputPlugin, InputButton, InputPressStatus},
|
utils::input::{GameInputPlugin, InputButton, InputPressStatus},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -33,6 +33,7 @@ fn main() {
|
||||||
GameInputPlugin,
|
GameInputPlugin,
|
||||||
NaviGameplayPlugin,
|
NaviGameplayPlugin,
|
||||||
PausePlugin,
|
PausePlugin,
|
||||||
|
CombatPlugin,
|
||||||
))
|
))
|
||||||
.init_state::<GameState>()
|
.init_state::<GameState>()
|
||||||
.init_state::<PauseState>()
|
.init_state::<PauseState>()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue