Fosma
This commit is contained in:
parent
3562560a6e
commit
952818c5be
7 changed files with 81 additions and 14 deletions
26
src/grid.rs
26
src/grid.rs
|
|
@ -7,10 +7,16 @@ pub struct GridPlugin;
|
|||
impl Plugin for GridPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, setup_grid)
|
||||
.add_systems(Update, snap_grid_elements);
|
||||
.add_systems(Update, snap_grid_elements)
|
||||
.add_observer(grid_despawn_check);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(EntityEvent)]
|
||||
pub struct GridDespawn {
|
||||
pub entity: Entity,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Grid {
|
||||
bounds: Rect,
|
||||
|
|
@ -131,3 +137,21 @@ fn snap_grid_elements(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn grid_despawn_check(event: On<GridDespawn>, mut grid_query: Single<&mut Grid>) {
|
||||
for i in 0..grid_query.elements.len() {
|
||||
match grid_query.elements[i] {
|
||||
CellState::Empty => continue,
|
||||
CellState::Filled(entity) => {
|
||||
if entity == event.entity {
|
||||
grid_query.elements[i] = CellState::Empty
|
||||
}
|
||||
}
|
||||
CellState::Part(entity) => {
|
||||
if entity == event.entity {
|
||||
grid_query.elements[i] = CellState::Empty
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ fn try_play(
|
|||
commands.entity(music_player.entity()).insert((
|
||||
AudioPlayer::new(soundtrack.0[random_range(0..soundtrack.0.len())].clone()),
|
||||
PlaybackSettings {
|
||||
volume: Volume::Linear(0.2),
|
||||
volume: Volume::Linear(2.0),
|
||||
mode: bevy::audio::PlaybackMode::Remove,
|
||||
..default()
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::{
|
||||
animation::transform::AnimatedTransform,
|
||||
grid::Grid,
|
||||
grid::{Grid, grid_despawn_check},
|
||||
mouse_position::MousePosition,
|
||||
turns::{TurnBusy, TurnState, TurnUnit},
|
||||
turns::{TurnBusy, TurnUnit},
|
||||
unit::{UnitTextures, health::Health},
|
||||
};
|
||||
use bevy::prelude::*;
|
||||
|
|
@ -23,7 +23,7 @@ pub fn spawn_doh(
|
|||
Health::new(10),
|
||||
Transform::from_xyz(mouse_position.position.x, mouse_position.position.y, 1.),
|
||||
AnimatedTransform::from_xyz(mouse_position.position.x, mouse_position.position.y, 1.),
|
||||
TurnUnit,
|
||||
//TurnUnit,
|
||||
))
|
||||
.id();
|
||||
grid.try_set(mouse_position.position.truncate(), doh);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::{
|
||||
animation::transform::AnimatedTransform,
|
||||
grid::Grid,
|
||||
grid::{Grid, grid_despawn_check},
|
||||
mouse_position::MousePosition,
|
||||
turns::{TurnBusy, TurnState, TurnUnit},
|
||||
turns::{TurnBusy, TurnUnit},
|
||||
unit::{UnitTextures, health::Health},
|
||||
};
|
||||
use bevy::prelude::*;
|
||||
|
|
@ -28,3 +28,24 @@ pub fn spawn_fosma(
|
|||
.id();
|
||||
grid.try_set(mouse_position.position.truncate(), fosma);
|
||||
}
|
||||
|
||||
pub fn fosma_action(
|
||||
mut commands: Commands,
|
||||
grid: Single<&Grid>,
|
||||
fosma_query: Query<(Entity, &Transform), (With<Fosma>, With<TurnBusy>)>,
|
||||
mut health_query: Query<&mut Health>,
|
||||
) {
|
||||
for (entity, transform) in fosma_query {
|
||||
let Some(unit) =
|
||||
grid.get_entity_in_direction(transform.translation.truncate(), Vec2::new(1., 0.))
|
||||
else {
|
||||
commands.entity(entity).remove::<TurnBusy>();
|
||||
return;
|
||||
};
|
||||
|
||||
if let Ok(mut health) = health_query.get_mut(unit) {
|
||||
health.damage(10);
|
||||
}
|
||||
commands.entity(entity).remove::<TurnBusy>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,28 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::grid::GridDespawn;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Health {
|
||||
pub max_hp: u32,
|
||||
pub hp: u32,
|
||||
pub max_hp: i32,
|
||||
pub hp: i32,
|
||||
}
|
||||
|
||||
impl Health {
|
||||
pub fn new(max_hp: u32) -> Self {
|
||||
pub fn new(max_hp: i32) -> Self {
|
||||
Self { max_hp, hp: max_hp }
|
||||
}
|
||||
|
||||
pub fn damage(&mut self, damage: i32) {
|
||||
self.hp -= damage;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn health_despawn_system(mut commands: Commands, query: Query<(Entity, &Health)>) {
|
||||
for (entity, health) in query {
|
||||
if health.hp <= 0 {
|
||||
commands.trigger(GridDespawn { entity });
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
turns::TurnState,
|
||||
unit::{fosma::fosma_action, health::health_despawn_system},
|
||||
};
|
||||
|
||||
pub mod doh;
|
||||
pub mod fosma;
|
||||
pub mod health;
|
||||
|
|
@ -8,7 +13,9 @@ pub mod zlosma;
|
|||
pub struct UnitPlugin;
|
||||
impl Plugin for UnitPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, unit_setup);
|
||||
app.add_systems(Startup, unit_setup)
|
||||
.add_systems(OnEnter(TurnState::Turn), health_despawn_system)
|
||||
.add_systems(Update, fosma_action);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::{
|
||||
animation::transform::AnimatedTransform,
|
||||
grid::Grid,
|
||||
grid::{Grid, grid_despawn_check},
|
||||
mouse_position::MousePosition,
|
||||
turns::{TurnBusy, TurnState, TurnUnit},
|
||||
turns::{TurnBusy, TurnUnit},
|
||||
unit::{UnitTextures, health::Health},
|
||||
};
|
||||
use bevy::prelude::*;
|
||||
|
|
@ -23,7 +23,7 @@ pub fn spawn_zlosma(
|
|||
Health::new(10),
|
||||
Transform::from_xyz(mouse_position.position.x, mouse_position.position.y, 1.),
|
||||
AnimatedTransform::from_xyz(mouse_position.position.x, mouse_position.position.y, 1.),
|
||||
TurnUnit,
|
||||
//TurnUnit,
|
||||
))
|
||||
.id();
|
||||
grid.try_set(mouse_position.position.truncate(), zlosma);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue