fn on_draw(&mut self,
               mut w: &mut PistonWindow,
               e: &Event,
               tileset: &Tileset,
               level: &mut Level) {
        // Calculate Range of the camera
        let range = self.cam.get_range();

        // draw in 2D
        w.draw_2d(e, |c, gl| {
            // Clear the screen with black
            clear(BLACK, gl);

            // Render Hubs only if player is available
            if let Some(ref p) = self.players[0] {
                if p.is_alive() {
                    let center_hub_one = c.transform.trans(10.0, 10.0);
                    self.hub_one.render(gl, center_hub_one);
                }
            }
            if let Some(ref p) = self.players[1] {
                if p.is_alive() {
                    let center_hub_two = c.transform.trans(280.0, 10.0);
                    self.hub_two.render(gl, center_hub_two);
                }
            }

            // Position for Tileset in Window
            let center_lv = c.transform.trans(0.0, 0.0);

            // render all Tiles if in Camera range
            for (h, j) in (range.x_min..range.x_max).enumerate() {
                for (w, i) in (range.y_min..range.y_max).enumerate() {
                    // get tile
                    let tile = match tileset.get_texture(level.get_data()[j as usize][i as usize].get_id()) {
                    Some(x) => x,
                    None => panic!("No texture found."),
                    };
                    // render tile
                    render_tile(&tile, gl, center_lv,
                            (h as u32 * tileset.get_tile_width()) + (CAM_BORDER/4) as u32,
                            (w as u32 * tileset.get_tile_height()) + (HUB_UP/4) as u32,
                            w as u32,
                            h as u32);
                }
            }

            // Render all in-camera items
            for i in &mut self.items {
                    if i.coord.get_x() >= range.x_min &&  i.coord.get_x() < range.x_max &&
                            i.coord.get_y() >= range.y_min && i.coord.get_y() < range.y_max {
                        // position in window for current item
                        let center_b1 = c.transform.trans(coord_to_pixel_x(i.coord.get_x(), range.x_min ),
                                                          coord_to_pixel_y(i.coord.get_y(), range.y_min));
                        // render current item
                        i.render(gl, center_b1);
                }
            }

            // Render all players if not None
            for x in &mut self.players {
                if let &mut Some(ref mut p) = x {

                    // position of Player in Pixel coordinates
                    let center_p = c.transform.trans(coord_to_pixel_x(p.coord.get_x(), range.x_min),
                                                  coord_to_pixel_y(p.coord.get_y(), range.y_min));
                    if p.is_alive() {
                    // render player one
                        p.render(gl, center_p);
                    }
                    // render all effects of player
                    for e in &p.get_effect_handler().effects {
                        // Render only Effects in Camera
                        if e.coord.get_x() >= range.x_min &&  e.coord.get_x() < range.x_max &&
                                e.coord.get_y() >= range.y_min && e.coord.get_y() < range.y_max {
                            // Pixel coordinates of player
                            let center = c.transform.trans(coord_to_pixel_x(e.coord.get_x(), range.x_min) ,
                                                          coord_to_pixel_y(e.coord.get_y(), range.y_min));
                            // Render effect
                            e.render(gl, center);
                        }
                    }

                }
            }

            // Render all bots
            for x in &mut self.bots {
                if let &mut Some(ref mut b) = x {
                    // Render only Bots in Camera
                    if b.coord.get_x() >= range.x_min &&  b.coord.get_x() < range.x_max &&
                        b.coord.get_y() >= range.y_min && b.coord.get_y() < range.y_max {
                        // Pixel coordinates of bot
                        let center_b1 = c.transform.trans(coord_to_pixel_x(b.coord.get_x(), range.x_min ),
                                                          coord_to_pixel_y(b.coord.get_y(), range.y_min));
                        // only render if alive. Bot can be dead, but not None, untill all his effects have rendered
                        if b.is_alive(){
                            b.render(gl, center_b1);
                        }

                        // Render all Effects in Camera from bot
                        for e in &b.effect.effects {
                            if e.coord.get_x() >= range.x_min &&  e.coord.get_x() < range.x_max &&
                                e.coord.get_y() >= range.y_min && e.coord.get_y() < range.y_max {
                                // pixel coordinate of effect
                                let center = c.transform.trans(coord_to_pixel_x(e.coord.get_x(), range.x_min) ,
                                                          coord_to_pixel_y(e.coord.get_y(), range.y_min));
                                e.render(gl, center);
                            }
                        }
                    }
                }
            }
        });
    }
/// Handle the rendering of all Objects
Handle the rendering of all Objects
Handle the rendering of all Objects
fn on_draw(&mut self,
               mut w: &mut PistonWindow,
               e: &Event,
               tileset: &Tileset,
               level: &mut Level) {
        // Calculate Range of the camera
        let range = self.cam.get_range();
        // draw in 2D
        w.draw_2d(e, |c, gl| {
            // Clear the screen with black
            clear(BLACK, gl);
            // Render Hubs only if player is available
            if let Some(ref p) = self.players[0] {
                if p.is_alive() {
                    let center_hub_one = c.transform.trans(10.0, 10.0);
                    self.hub_one.render(gl, center_hub_one);
                }
            }
            if let Some(ref p) = self.players[1] {
                if p.is_alive() {
                    let center_hub_two = c.transform.trans(280.0, 10.0);
                    self.hub_two.render(gl, center_hub_two);
                }
            }
            // Position for Tileset in Window
            let center_lv = c.transform.trans(0.0, 0.0);
            // render all Tiles if in Camera range
            for (h, j) in (range.x_min..range.x_max).enumerate() {
                for (w, i) in (range.y_min..range.y_max).enumerate() {
                    // get tile
                    let tile = match tileset.get_texture(level.get_data()[j as usize][i as usize].get_id()) {
                    Some(x) => x,
                    None => panic!("No texture found."),
                    };
                    // render tile
                    render_tile(&tile, gl, center_lv,
                            (h as u32 * tileset.get_tile_width()) + (CAM_BORDER/4) as u32,
                            (w as u32 * tileset.get_tile_height()) + (HUB_UP/4) as u32,
                            w as u32,
                            h as u32);
                }
            }
            // Render all in-camera items
            for i in &mut self.items {
                    if i.coord.get_x() >= range.x_min &&  i.coord.get_x() < range.x_max &&
                            i.coord.get_y() >= range.y_min && i.coord.get_y() < range.y_max {
                        // position in window for current item
                        let center_b1 = c.transform.trans(coord_to_pixel_x(i.coord.get_x(), range.x_min ),
                                                          coord_to_pixel_y(i.coord.get_y(), range.y_min));
                        // render current item
                        i.render(gl, center_b1);
                }
            }
            // Render all players if not None
            for x in &mut self.players {
                if let &mut Some(ref mut p) = x {
                    // position of Player in Pixel coordinates
                    let center_p = c.transform.trans(coord_to_pixel_x(p.coord.get_x(), range.x_min),
                                                  coord_to_pixel_y(p.coord.get_y(), range.y_min));
                    if p.is_alive() {
                    // render player one
                        p.render(gl, center_p);
                    }
                    // render all effects of player
                    for e in &p.get_effect_handler().effects {
                        // Render only Effects in Camera
                        if e.coord.get_x() >= range.x_min &&  e.coord.get_x() < range.x_max &&
                                e.coord.get_y() >= range.y_min && e.coord.get_y() < range.y_max {
                            // Pixel coordinates of player
                            let center = c.transform.trans(coord_to_pixel_x(e.coord.get_x(), range.x_min) ,
                                                          coord_to_pixel_y(e.coord.get_y(), range.y_min));
                            // Render effect
                            e.render(gl, center);
                        }
                    }
                }
            }
            // Render all bots
            for x in &mut self.bots {
                if let &mut Some(ref mut b) = x {
                    // Render only Bots in Camera
                    if b.coord.get_x() >= range.x_min &&  b.coord.get_x() < range.x_max &&
                        b.coord.get_y() >= range.y_min && b.coord.get_y() < range.y_max {
                        // Pixel coordinates of bot
                        let center_b1 = c.transform.trans(coord_to_pixel_x(b.coord.get_x(), range.x_min ),
                                                          coord_to_pixel_y(b.coord.get_y(), range.y_min));
                        // only render if alive. Bot can be dead, but not None, untill all his effects have rendered
                        if b.is_alive(){
                            b.render(gl, center_b1);
                        }
                        // Render all Effects in Camera from bot
                        for e in &b.effect.effects {
                            if e.coord.get_x() >= range.x_min &&  e.coord.get_x() < range.x_max &&
                                e.coord.get_y() >= range.y_min && e.coord.get_y() < range.y_max {
                                // pixel coordinate of effect
                                let center = c.transform.trans(coord_to_pixel_x(e.coord.get_x(), range.x_min) ,
                                                          coord_to_pixel_y(e.coord.get_y(), range.y_min));
                                e.render(gl, center);
                            }
                        }
                    }
                }
            }
        });
    }
fn on_draw ( & mut self , mut w : & mut PistonWindow , e : & Event , tileset : & Tileset , level : & mut Level ) { // Calculate Range of the camera let range = self . cam . get_range ( ) ; // draw in 2D w . draw_2d ( e , | c , gl | { // Clear the screen with black clear ( BLACK , gl ) ; // Render Hubs only if player is available if let Some ( ref p ) = self . players [ 0 ] { if p . is_alive ( ) { let center_hub_one = c . transform . trans ( 10.0 , 10.0 ) ; self . hub_one . render ( gl , center_hub_one ) ; } } if let Some ( ref p ) = self . players [ 1 ] { if p . is_alive ( ) { let center_hub_two = c . transform . trans ( 280.0 , 10.0 ) ; self . hub_two . render ( gl , center_hub_two ) ; } } // Position for Tileset in Window let center_lv = c . transform . trans ( 0.0 , 0.0 ) ; // render all Tiles if in Camera range for ( h , j ) in ( range . x_min .. range . x_max ) . enumerate ( ) { for ( w , i ) in ( range . y_min .. range . y_max ) . enumerate ( ) { // get tile let tile = match tileset . get_texture ( level . get_data ( ) [ j as usize ] [ i as usize ] . get_id ( ) ) { Some ( x ) => x , None => panic ! ( " " ) , } ; // render tile render_tile ( & tile , gl , center_lv , ( h as u32 * tileset . get_tile_width ( ) ) + ( CAM_BORDER / 4 ) as u32 , ( w as u32 * tileset . get_tile_height ( ) ) + ( HUB_UP / 4 ) as u32 , w as u32 , h as u32 ) ; } } // Render all in-camera items for i in & mut self . items { if i . coord . get_x ( ) >= range . x_min && i . coord . get_x ( ) < range . x_max && i . coord . get_y ( ) >= range . y_min && i . coord . get_y ( ) < range . y_max { // position in window for current item let center_b1 = c . transform . trans ( coord_to_pixel_x ( i . coord . get_x ( ) , range . x_min ) , coord_to_pixel_y ( i . coord . get_y ( ) , range . y_min ) ) ; // render current item i . render ( gl , center_b1 ) ; } } // Render all players if not None for x in & mut self . players { if let & mut Some ( ref mut p ) = x { // position of Player in Pixel coordinates let center_p = c . transform . trans ( coord_to_pixel_x ( p . coord . get_x ( ) , range . x_min ) , coord_to_pixel_y ( p . coord . get_y ( ) , range . y_min ) ) ; if p . is_alive ( ) { // render player one p . render ( gl , center_p ) ; } // render all effects of player for e in & p . get_effect_handler ( ) . effects { // Render only Effects in Camera if e . coord . get_x ( ) >= range . x_min && e . coord . get_x ( ) < range . x_max && e . coord . get_y ( ) >= range . y_min && e . coord . get_y ( ) < range . y_max { // Pixel coordinates of player let center = c . transform . trans ( coord_to_pixel_x ( e . coord . get_x ( ) , range . x_min ) , coord_to_pixel_y ( e . coord . get_y ( ) , range . y_min ) ) ; // Render effect e . render ( gl , center ) ; } } } } // Render all bots for x in & mut self . bots { if let & mut Some ( ref mut b ) = x { // Render only Bots in Camera if b . coord . get_x ( ) >= range . x_min && b . coord . get_x ( ) < range . x_max && b . coord . get_y ( ) >= range . y_min && b . coord . get_y ( ) < range . y_max { // Pixel coordinates of bot let center_b1 = c . transform . trans ( coord_to_pixel_x ( b . coord . get_x ( ) , range . x_min ) , coord_to_pixel_y ( b . coord . get_y ( ) , range . y_min ) ) ; // only render if alive. Bot can be dead, but not None, untill all his effects have rendered if b . is_alive ( ) { b . render ( gl , center_b1 ) ; } // Render all Effects in Camera from bot for e in & b . effect . effects { if e . coord . get_x ( ) >= range . x_min && e . coord . get_x ( ) < range . x_max && e . coord . get_y ( ) >= range . y_min && e . coord . get_y ( ) < range . y_max { // pixel coordinate of effect let center = c . transform . trans ( coord_to_pixel_x ( e . coord . get_x ( ) , range . x_min ) , coord_to_pixel_y ( e . coord . get_y ( ) , range . y_min ) ) ; e . render ( gl , center ) ; } } } } } } ) ; }
Handle the rendering of all Objects
Handle the rendering of all Objects
&mut self
w
&mut PistonWindow
e
&Event
tileset
&Tileset
level
&mut Level
&mut self
w
&mut PistonWindow
e
&Event
tileset
&Tileset
level
&mut Level