fn on_update(&mut self, level: &mut Level, state: usize, mut sounds: &mut SoundHandler) {
        // Update range
        let range = self.cam.get_range_update();
        // Update Players
        for x in &mut self.players.iter_mut() {
            if let &mut Some(ref mut p) = x {
                let id = if let InteractableType::Player(x) = p.get_interactable_type() {
                    x
                } else {
                    0
                };
                // Update Player
                p.on_update(range, level, InteractableType::Player(id), &mut sounds);
                // Update hubs
                if id == 1 {
                    self.hub_one.on_update(&p);
                } else if id == 2 {
                    self.hub_two.on_update(&p);
                }
                if p.is_alive() {
                    // check if on item and update item
                    for i in &mut self.items {
                        i.collect(p);
                    }

                    // update all effects of player
                    for e in &mut p.effect.effects {
                        if !e.get_played() {
                            sounds.play(e.get_sound_str());
                            e.played();
                        }
                    }
                } else {
                    // on player death handle death effect
                    if !p.dead {
                        p.effect.handle(p.coord, EffectOption::PlayerDeath, LastKey::Wait);
                        p.dead = true;
                    }
                    match level.get_data()[p.coord.get_x() as usize][p.coord.get_y() as usize].get_fieldstatus() {
                        Some(InteractableType::Player(i)) => {
                            match p.get_interactable_type() {
                                InteractableType::Player(a) => {
                                    if i == a {
                                        // free the field, on which the player stood
                                        level.get_data()[p.coord.get_x() as usize][p.coord.get_y() as usize].free_fieldstatus();
                                    }
                                },
                                _ => (),
                            }
                        },
                        _ => (),
                    }
                }
            }
        }
        // Set player to None, when death effect ends
        for i in 0..self.players.len() {
            let mut delete = false;
            if let Some(ref p) = self.players[i] {
                if p.dead {
                    delete = p.effect.effects.len() == 0;
                }
            }
            if delete {
                self.players[i] = None;
            }
        }
        // Vec with dead bots
        let mut dead = Vec::new();
        for x in &mut self.bots {
            if let &mut Some(ref mut b) = x {
                // if bot dead
                if !b.is_alive() {
                    // and not set dead yet (two bools, because last effect have to render)
                    if !b.dead {
                        // create last effect
                        b.effect.handle(b.coord, EffectOption::Dead, LastKey::Wait);
                        b.dead = true;
                    }
                    // Field not longer occupied
                    level.get_data()[b.coord.get_x() as usize][b.coord.get_y() as usize]
                        .free_fieldstatus();
                    // If Bot, add to dead bots
                    if let InteractableType::Bot(i) = b.get_interactable_type() {
                        dead.push(i);
                    }
                }
                // update bot (In Bot no update if already dead. Only updates of effects)
                b.on_update(level, state, &mut sounds, &mut self.players);
            }
        }
        // Delete all dead Bots (Set to None)
        for d in dead {
            let mut delete = false;
            if let Some(ref b) = self.bots[d as usize] {
                delete = b.effect.effects.len() == 0;
            }
            if delete {
                self.bots[d as usize] = None;
            }
        }

        // Update Camera
        let (coord1, coord2) = match (&self.players[0], &self.players[1]) {
            (&None, &None) => (Coordinate::new(0, 0), Coordinate::new(0, 0)),
            (&None, &Some(ref y)) => (y.coord.clone(), y.coord.clone()),
            (&Some(ref x), &None) => (x.coord.clone(), x.coord.clone()),
            (&Some(ref x), &Some(ref y)) => (x.coord.clone(), y.coord.clone()),
        };
        self.cam.calc_coordinates(coord1, coord2, level);
        self.items.retain(|ref i| !i.get_gone());

    }
/// Updates all Players, Bots, effects, items and camera
Updates all Players, Bots, effects, items and camera
Updates all Players Bots effects items and camera
fn on_update(&mut self, level: &mut Level, state: usize, mut sounds: &mut SoundHandler) {
        // Update range
        let range = self.cam.get_range_update();
        // Update Players
        for x in &mut self.players.iter_mut() {
            if let &mut Some(ref mut p) = x {
                let id = if let InteractableType::Player(x) = p.get_interactable_type() {
                    x
                } else {
                    0
                };
                // Update Player
                p.on_update(range, level, InteractableType::Player(id), &mut sounds);
                // Update hubs
                if id == 1 {
                    self.hub_one.on_update(&p);
                } else if id == 2 {
                    self.hub_two.on_update(&p);
                }
                if p.is_alive() {
                    // check if on item and update item
                    for i in &mut self.items {
                        i.collect(p);
                    }
                    // update all effects of player
                    for e in &mut p.effect.effects {
                        if !e.get_played() {
                            sounds.play(e.get_sound_str());
                            e.played();
                        }
                    }
                } else {
                    // on player death handle death effect
                    if !p.dead {
                        p.effect.handle(p.coord, EffectOption::PlayerDeath, LastKey::Wait);
                        p.dead = true;
                    }
                    match level.get_data()[p.coord.get_x() as usize][p.coord.get_y() as usize].get_fieldstatus() {
                        Some(InteractableType::Player(i)) => {
                            match p.get_interactable_type() {
                                InteractableType::Player(a) => {
                                    if i == a {
                                        // free the field, on which the player stood
                                        level.get_data()[p.coord.get_x() as usize][p.coord.get_y() as usize].free_fieldstatus();
                                    }
                                },
                                _ => (),
                            }
                        },
                        _ => (),
                    }
                }
            }
        }
        // Set player to None, when death effect ends
        for i in 0..self.players.len() {
            let mut delete = false;
            if let Some(ref p) = self.players[i] {
                if p.dead {
                    delete = p.effect.effects.len() == 0;
                }
            }
            if delete {
                self.players[i] = None;
            }
        }
        // Vec with dead bots
        let mut dead = Vec::new();
        for x in &mut self.bots {
            if let &mut Some(ref mut b) = x {
                // if bot dead
                if !b.is_alive() {
                    // and not set dead yet (two bools, because last effect have to render)
                    if !b.dead {
                        // create last effect
                        b.effect.handle(b.coord, EffectOption::Dead, LastKey::Wait);
                        b.dead = true;
                    }
                    // Field not longer occupied
                    level.get_data()[b.coord.get_x() as usize][b.coord.get_y() as usize]
                        .free_fieldstatus();
                    // If Bot, add to dead bots
                    if let InteractableType::Bot(i) = b.get_interactable_type() {
                        dead.push(i);
                    }
                }
                // update bot (In Bot no update if already dead. Only updates of effects)
                b.on_update(level, state, &mut sounds, &mut self.players);
            }
        }
        // Delete all dead Bots (Set to None)
        for d in dead {
            let mut delete = false;
            if let Some(ref b) = self.bots[d as usize] {
                delete = b.effect.effects.len() == 0;
            }
            if delete {
                self.bots[d as usize] = None;
            }
        }
        // Update Camera
        let (coord1, coord2) = match (&self.players[0], &self.players[1]) {
            (&None, &None) => (Coordinate::new(0, 0), Coordinate::new(0, 0)),
            (&None, &Some(ref y)) => (y.coord.clone(), y.coord.clone()),
            (&Some(ref x), &None) => (x.coord.clone(), x.coord.clone()),
            (&Some(ref x), &Some(ref y)) => (x.coord.clone(), y.coord.clone()),
        };
        self.cam.calc_coordinates(coord1, coord2, level);
        self.items.retain(|ref i| !i.get_gone());
    }
fn on_update ( & mut self , level : & mut Level , state : usize , mut sounds : & mut SoundHandler ) { // Update range let range = self . cam . get_range_update ( ) ; // Update Players for x in & mut self . players . iter_mut ( ) { if let & mut Some ( ref mut p ) = x { let id = if let InteractableType :: Player ( x ) = p . get_interactable_type ( ) { x } else { 0 } ; // Update Player p . on_update ( range , level , InteractableType :: Player ( id ) , & mut sounds ) ; // Update hubs if id == 1 { self . hub_one . on_update ( & p ) ; } else if id == 2 { self . hub_two . on_update ( & p ) ; } if p . is_alive ( ) { // check if on item and update item for i in & mut self . items { i . collect ( p ) ; } // update all effects of player for e in & mut p . effect . effects { if ! e . get_played ( ) { sounds . play ( e . get_sound_str ( ) ) ; e . played ( ) ; } } } else { // on player death handle death effect if ! p . dead { p . effect . handle ( p . coord , EffectOption :: PlayerDeath , LastKey :: Wait ) ; p . dead = true ; } match level . get_data ( ) [ p . coord . get_x ( ) as usize ] [ p . coord . get_y ( ) as usize ] . get_fieldstatus ( ) { Some ( InteractableType :: Player ( i ) ) => { match p . get_interactable_type ( ) { InteractableType :: Player ( a ) => { if i == a { // free the field, on which the player stood level . get_data ( ) [ p . coord . get_x ( ) as usize ] [ p . coord . get_y ( ) as usize ] . free_fieldstatus ( ) ; } } , _ => ( ) , } } , _ => ( ) , } } } } // Set player to None, when death effect ends for i in 0 .. self . players . len ( ) { let mut delete = false ; if let Some ( ref p ) = self . players [ i ] { if p . dead { delete = p . effect . effects . len ( ) == 0 ; } } if delete { self . players [ i ] = None ; } } // Vec with dead bots let mut dead = Vec :: new ( ) ; for x in & mut self . bots { if let & mut Some ( ref mut b ) = x { // if bot dead if ! b . is_alive ( ) { // and not set dead yet (two bools, because last effect have to render) if ! b . dead { // create last effect b . effect . handle ( b . coord , EffectOption :: Dead , LastKey :: Wait ) ; b . dead = true ; } // Field not longer occupied level . get_data ( ) [ b . coord . get_x ( ) as usize ] [ b . coord . get_y ( ) as usize ] . free_fieldstatus ( ) ; // If Bot, add to dead bots if let InteractableType :: Bot ( i ) = b . get_interactable_type ( ) { dead . push ( i ) ; } } // update bot (In Bot no update if already dead. Only updates of effects) b . on_update ( level , state , & mut sounds , & mut self . players ) ; } } // Delete all dead Bots (Set to None) for d in dead { let mut delete = false ; if let Some ( ref b ) = self . bots [ d as usize ] { delete = b . effect . effects . len ( ) == 0 ; } if delete { self . bots [ d as usize ] = None ; } } // Update Camera let ( coord1 , coord2 ) = match ( & self . players [ 0 ] , & self . players [ 1 ] ) { ( & None , & None ) => ( Coordinate :: new ( 0 , 0 ) , Coordinate :: new ( 0 , 0 ) ) , ( & None , & Some ( ref y ) ) => ( y . coord . clone ( ) , y . coord . clone ( ) ) , ( & Some ( ref x ) , & None ) => ( x . coord . clone ( ) , x . coord . clone ( ) ) , ( & Some ( ref x ) , & Some ( ref y ) ) => ( x . coord . clone ( ) , y . coord . clone ( ) ) , } ; self . cam . calc_coordinates ( coord1 , coord2 , level ) ; self . items . retain ( | ref i | ! i . get_gone ( ) ) ; }
Updates all Players, Bots, effects, items and camera
Updates all Players Bots effects items and camera
&mut self
level
&mut Level
state
usize
sounds
&mut SoundHandler
&mut self
level
&mut Level
state
usize
sounds
&mut SoundHandler