aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-24 15:01:04 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-24 15:01:04 +0100
commit876fd9d60de9c09e8657a2cb70fd55fd041d1f97 (patch)
tree8d30385f6b795f706888b036e30506e51985f922
parentf7428e317d282856d05ffc37b6ba474c5e9973ce (diff)
feat: color projectiles
-rw-r--r--src/client.rs8
-rw-r--r--src/protocol.rs1
-rw-r--r--src/server.rs13
-rw-r--r--src/shared/ability.rs103
-rw-r--r--src/shared/projectile.rs8
5 files changed, 74 insertions, 59 deletions
diff --git a/src/client.rs b/src/client.rs
index 12f12c0..d536dce 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -230,9 +230,9 @@ fn render_projectiles(
mut commands: Commands,
mut materials: ResMut<Assets<ColorMaterial>>,
mut meshes: ResMut<Assets<Mesh>>,
- projectiles: Query<(Entity, &Projectile), Added<Projectile>>,
+ projectiles: Query<(Entity, &Projectile, &ProjectileColor), Added<Projectile>>,
) {
- for (entity, projectile) in projectiles.iter() {
+ for (entity, projectile, projectile_color) in projectiles.iter() {
let Some(position) = (match projectile.type_ {
ProjectileType::Free(FreeProjectile { position, .. }) => Some(position),
ProjectileType::Instant(InstantProjectile { .. }) => None,
@@ -241,8 +241,8 @@ fn render_projectiles(
continue;
};
commands.entity(entity).insert(MaterialMesh2dBundle {
- mesh: Mesh2dHandle(meshes.add(Circle { radius: 2. })),
- material: materials.add(Color::RED),
+ mesh: Mesh2dHandle(meshes.add(Circle { radius: 1. })),
+ material: materials.add(projectile_color.0),
transform: Transform::from_xyz(position.x, position.y, 1.),
..Default::default()
});
diff --git a/src/protocol.rs b/src/protocol.rs
index 87fa9c0..f4c77bb 100644
--- a/src/protocol.rs
+++ b/src/protocol.rs
@@ -47,6 +47,7 @@ pub enum Components {
PlayerPosition(PlayerPosition),
PlayerColor(PlayerColor),
Projectile(Projectile),
+ ProjectileColor(ProjectileColor),
Cooldown(Cooldown),
Health(Health),
Champion(Champion),
diff --git a/src/server.rs b/src/server.rs
index 4169178..84f9235 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -319,12 +319,12 @@ fn imperative_attack_attack(
entity_map: Res<EntityMap>,
mut commands: Commands,
mut cooldowns: Query<&mut Cooldown>,
- mut players: Query<(&PlayerId, &mut Imperative, &EffectiveStats)>,
+ mut players: Query<(&PlayerId, &mut Imperative, &EffectiveStats, &PlayerColor)>,
mut positions: Query<&mut PlayerPosition>,
shapes: Query<&Shape>,
champions: Query<&Champion>,
) {
- for (id, mut imperative, effective_stats) in players.iter_mut() {
+ for (id, mut imperative, effective_stats, player_color) in players.iter_mut() {
let Some(entity) = entity_map.0.get(&id.0) else {
*imperative = Imperative::Idle;
continue;
@@ -366,11 +366,10 @@ fn imperative_attack_attack(
} else {
base_cooldown.0[ability_slot]
};
- commands.spawn(ProjectileBundle::new(ability.to_projectile(
- *id,
- position.0,
- target_player,
- )));
+ commands.spawn(ProjectileBundle::new(
+ ability.to_projectile(*id, position.0, target_player),
+ ProjectileColor(player_color.0),
+ ));
*imperative = Imperative::AttackTarget(AbilitySlot::A, target_player);
}
}
diff --git a/src/shared/ability.rs b/src/shared/ability.rs
index a9387f3..66d236f 100644
--- a/src/shared/ability.rs
+++ b/src/shared/ability.rs
@@ -253,7 +253,7 @@ fn dash_activation(dash: Dash) -> DirectionalAbilityActivation {
move |entity_map: Res<EntityMap>,
mut imperatives: Query<&mut Imperative>,
mut set: ParamSet<(
- Query<&mut PlayerPosition>,
+ Query<(&mut PlayerPosition, &PlayerColor)>,
Query<(Entity, &PlayerId, &PlayerPosition, &Shape)>,
)>,
mut commands: Commands| {
@@ -278,9 +278,12 @@ fn dash_activation(dash: Dash) -> DirectionalAbilityActivation {
};
let mut positions = set.p0();
- if let Ok(mut position) = positions.get_mut(*source_entity) {
- position.0 = dash_end;
- }
+ let Ok((mut position, source_player_color)) =
+ positions.get_mut(*source_entity)
+ else {
+ return;
+ };
+ position.0 = dash_end;
if let Some(DashCollision {
collision_player_id,
@@ -295,13 +298,16 @@ fn dash_activation(dash: Dash) -> DirectionalAbilityActivation {
source_player,
area_of_effect_type: AreaOfEffectType::Slow,
}));
- commands.spawn(ProjectileBundle::new(Projectile {
- type_: ProjectileType::Instant(InstantProjectile {
- target_player: collision_player_id,
- }),
- source_player,
- damage: dash.damage,
- }));
+ commands.spawn(ProjectileBundle::new(
+ Projectile {
+ type_: ProjectileType::Instant(InstantProjectile {
+ target_player: collision_player_id,
+ }),
+ source_player,
+ damage: dash.damage,
+ },
+ ProjectileColor(source_player_color.0),
+ ));
if let Ok(mut imperative) = imperatives.get_mut(*source_entity) {
*imperative =
Imperative::AttackTarget(AbilitySlot::A, collision_player_id);
@@ -375,21 +381,12 @@ fn pull_activation(pull: Pull) -> DirectionalAbilityActivation {
move |players: Query<(Entity, &PlayerId)>,
mut imperatives: Query<&mut Imperative>,
mut set: ParamSet<(
- Query<&mut PlayerPosition>,
+ Query<(&mut PlayerPosition, &PlayerColor)>,
Query<(Entity, &PlayerId, &PlayerPosition, &Shape)>,
)>,
- mut commands: Commands| {
- let Some(source_entity) = ({
- let mut source_entity = None;
- for (entity, player_id) in players.iter() {
- if *player_id != source_player {
- continue;
- }
- source_entity = Some(entity);
- break;
- }
- source_entity
- }) else {
+ mut commands: Commands,
+ entity_map: Res<EntityMap>| {
+ let Some(source_entity) = entity_map.0.get(&source_player.0) else {
return;
};
@@ -400,7 +397,7 @@ fn pull_activation(pull: Pull) -> DirectionalAbilityActivation {
}) = ({
let pull_targets = set.p1();
pull_collision(
- source_entity,
+ *source_entity,
direction.normalize_or_zero(),
pull.max_distance,
&pull_targets,
@@ -425,18 +422,24 @@ fn pull_activation(pull: Pull) -> DirectionalAbilityActivation {
};
let mut positions = set.p0();
- if let Ok(mut position) = positions.get_mut(target_entity) {
- position.0 = pull_end;
- }
+ let Ok([(_, source_player_color), (mut position, _)]) =
+ positions.get_many_mut([*source_entity, target_entity])
+ else {
+ return;
+ };
+ position.0 = pull_end;
- commands.spawn(ProjectileBundle::new(Projectile {
- type_: ProjectileType::Instant(InstantProjectile {
- target_player: collision_player_id,
- }),
- source_player,
- damage: pull.damage,
- }));
- if let Ok(mut imperative) = imperatives.get_mut(source_entity) {
+ commands.spawn(ProjectileBundle::new(
+ Projectile {
+ type_: ProjectileType::Instant(InstantProjectile {
+ target_player: collision_player_id,
+ }),
+ source_player,
+ damage: pull.damage,
+ },
+ ProjectileColor(source_player_color.0),
+ ));
+ if let Ok(mut imperative) = imperatives.get_mut(*source_entity) {
*imperative =
Imperative::AttackTarget(AbilitySlot::A, collision_player_id);
}
@@ -571,23 +574,31 @@ fn spear_activation(spear: Spear) -> DirectionalAbilityActivation {
move |commands: &mut Commands, source_player: PlayerId, direction: Vec2| {
commands.add(move |world: &mut World| {
world.run_system_once(
- move |mut commands: Commands, players: Query<(&PlayerId, &PlayerPosition)>| {
- for (id, position) in players.iter() {
- if *id != source_player {
- continue;
- }
- commands.spawn(ProjectileBundle::new(Projectile {
+ move |mut commands: Commands,
+ players: Query<(&PlayerId, &PlayerPosition, &PlayerColor)>,
+ entity_map: Res<EntityMap>| {
+ let Some(source_entity) = entity_map.0.get(&source_player.0) else {
+ return;
+ };
+ let Ok((_source_player_id, source_player_position, source_player_color)) =
+ players.get(*source_entity)
+ else {
+ return;
+ };
+ commands.spawn(ProjectileBundle::new(
+ Projectile {
type_: ProjectileType::Free(FreeProjectile {
- position: position.0,
+ position: source_player_position.0,
direction: direction.normalize_or_zero(),
- starting_position: position.0,
+ starting_position: source_player_position.0,
max_distance: spear.max_distance,
scale_damage: Some((0.75, 2.5)),
}),
source_player,
damage: spear.damage,
- }));
- }
+ },
+ ProjectileColor(source_player_color.0),
+ ));
},
)
});
diff --git a/src/shared/projectile.rs b/src/shared/projectile.rs
index 5da0526..8fd0070 100644
--- a/src/shared/projectile.rs
+++ b/src/shared/projectile.rs
@@ -5,13 +5,15 @@ use crate::shared::*;
#[derive(Bundle)]
pub struct ProjectileBundle {
pub projectile: Projectile,
+ pub projectile_color: ProjectileColor,
pub replicate: Replicate,
}
impl ProjectileBundle {
- pub fn new(projectile: Projectile) -> Self {
+ pub fn new(projectile: Projectile, projectile_color: ProjectileColor) -> Self {
ProjectileBundle {
projectile,
+ projectile_color: projectile_color,
replicate: Replicate {
replication_group: ReplicationGroup::default().set_priority(1.),
..Default::default()
@@ -21,7 +23,6 @@ impl ProjectileBundle {
}
#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
-
pub struct Projectile {
pub type_: ProjectileType,
pub source_player: PlayerId,
@@ -29,6 +30,9 @@ pub struct Projectile {
}
#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
+pub struct ProjectileColor(pub Color);
+
+#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
pub enum ProjectileType {
Free(FreeProjectile),
Instant(InstantProjectile),