spawn projectiles at player location
This commit is contained in:
@@ -17,7 +17,11 @@ pub const PROTOCOL_ID: u64 = 7;
|
||||
#[derive(Debug, Component)]
|
||||
pub struct Player {
|
||||
pub id: u64,
|
||||
pub transform: Transform,
|
||||
}
|
||||
|
||||
#[derive(Debug, Component)]
|
||||
pub struct PlayerId {
|
||||
pub id: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, Component)]
|
||||
@@ -36,7 +40,7 @@ pub struct Jumper {
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Component)]
|
||||
pub enum PlayerCommand {
|
||||
BasicAttack { origin: Vec2, direction: Vec2 },
|
||||
BasicAttack { direction: Vec2 },
|
||||
}
|
||||
|
||||
pub enum ClientChannel {
|
||||
@@ -144,12 +148,15 @@ pub fn setup_level(mut _commands: Commands) {
|
||||
pub fn spawn_projectile(commands: &mut Commands, origin: Vec2, direction: Vec2) -> Entity {
|
||||
commands
|
||||
.spawn()
|
||||
.insert(Transform {
|
||||
translation: Vec3::new(origin.x, origin.y, 0.),
|
||||
..Default::default()
|
||||
})
|
||||
.insert(Collider::ball(0.1))
|
||||
.insert(Velocity::linear(direction * 10.))
|
||||
.insert(ActiveEvents::COLLISION_EVENTS)
|
||||
.insert(Projectile {
|
||||
duration: Timer::from_seconds(1.5, false),
|
||||
origin,
|
||||
duration: Timer::from_seconds(3.5, false),
|
||||
direction,
|
||||
})
|
||||
.id()
|
||||
@@ -158,6 +165,5 @@ pub fn spawn_projectile(commands: &mut Commands, origin: Vec2, direction: Vec2)
|
||||
#[derive(Debug, Component)]
|
||||
pub struct Projectile {
|
||||
pub duration: Timer,
|
||||
pub origin: Vec2,
|
||||
pub direction: Vec2,
|
||||
}
|
||||
|
Reference in New Issue
Block a user