aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/projectile.rs
blob: 74dc260b092373f9bd64f9d39b6591cd3e964bc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use crate::protocol::*;
use crate::shared::damage::*;
use crate::shared::player::*;
use bevy::prelude::*;
use lightyear::prelude::*;
use serde::*;

#[derive(Bundle)]
pub struct ProjectileBundle {
    pub projectile: Projectile,
    pub projectile_color: ProjectileColor,
    pub replicate: Replicate,
}

impl ProjectileBundle {
    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()
            },
        }
    }
}

#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct Projectile {
    pub type_: ProjectileType,
    pub source_player: PlayerId,
    pub damage: Damage,
}

#[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),
    Targeted(TargetedProjectile),
}

#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct FreeProjectile {
    pub position: Vec2,
    pub direction: Vec2,
    pub starting_position: Vec2,
    pub max_distance: f32,
    pub scale_damage: Option<(f32, f32)>,
}

#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct InstantProjectile {
    pub target_player: PlayerId,
}

#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct TargetedProjectile {
    pub target_player: PlayerId,
    pub position: Vec2,
}