pub fn draw(
        &self,
        ctx: &CanvasRenderingContext2d,
        sprites: &HashMap<String, HtmlImageElement>,
    ) -> Result<(), JsValue> {
        // draw tower base
        let base_size = self.rect.w() * 1.25;
        ctx.draw_image_with_html_image_element_and_dw_and_dh(
            sprites.get(&self.base_img).unwrap(),
            self.rect.center_x() - base_size * 0.5,
            self.rect.center_y() - base_size / 2.5,
            base_size,
            base_size,
        )?;

        // draw top sprite with potential blast sprite
        ctx.translate(self.rect.center_x(), self.rect.center_y())?;
        ctx.rotate(self.rotation)?;
        if Date::now() - self.last_dmg_time < 100.0 {
            ctx.draw_image_with_html_image_element_and_dw_and_dh(
                sprites.get(&self.blast_img).unwrap(),
                -self.rect.w() * 0.5,
                -self.rect.h() * 1.4,
                self.rect.w().floor(),
                self.rect.h().floor(),
            )?;
        }
        ctx.draw_image_with_html_image_element_and_dw_and_dh(
            sprites.get(&self.top_img).unwrap(),
            (-self.rect.w() * 0.5).floor(),
            (-self.rect.h() * 0.5).floor(),
            self.rect.w().floor(),
            self.rect.h().floor(),
        )?;
        ctx.set_transform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)?;

        if self.mouse_over {
            self.draw_range(ctx)?;

            self.draw_selection(ctx)?;
        }

        if let TowerStatus::Selected = self.status {
            self.draw_selection(ctx)?;

            self.upgrade_button.draw(ctx, sprites)?;
            self.delete_button.draw(ctx, sprites)?;
        }

        Ok(())
    }
/// Draws the Tower on the referenced Context
Draws the Tower on the referenced Context
Draws the Tower on the referenced Context
pub fn draw(
        &self,
        ctx: &CanvasRenderingContext2d,
        sprites: &HashMap<String, HtmlImageElement>,
    ) -> Result<(), JsValue> {
        // draw tower base
        let base_size = self.rect.w() * 1.25;
        ctx.draw_image_with_html_image_element_and_dw_and_dh(
            sprites.get(&self.base_img).unwrap(),
            self.rect.center_x() - base_size * 0.5,
            self.rect.center_y() - base_size / 2.5,
            base_size,
            base_size,
        )?;
        // draw top sprite with potential blast sprite
        ctx.translate(self.rect.center_x(), self.rect.center_y())?;
        ctx.rotate(self.rotation)?;
        if Date::now() - self.last_dmg_time < 100.0 {
            ctx.draw_image_with_html_image_element_and_dw_and_dh(
                sprites.get(&self.blast_img).unwrap(),
                -self.rect.w() * 0.5,
                -self.rect.h() * 1.4,
                self.rect.w().floor(),
                self.rect.h().floor(),
            )?;
        }
        ctx.draw_image_with_html_image_element_and_dw_and_dh(
            sprites.get(&self.top_img).unwrap(),
            (-self.rect.w() * 0.5).floor(),
            (-self.rect.h() * 0.5).floor(),
            self.rect.w().floor(),
            self.rect.h().floor(),
        )?;
        ctx.set_transform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)?;
        if self.mouse_over {
            self.draw_range(ctx)?;
            self.draw_selection(ctx)?;
        }
        if let TowerStatus::Selected = self.status {
            self.draw_selection(ctx)?;
            self.upgrade_button.draw(ctx, sprites)?;
            self.delete_button.draw(ctx, sprites)?;
        }
        Ok(())
    }
pub fn draw ( & self , ctx : & CanvasRenderingContext2d , sprites : & HashMap < String , HtmlImageElement > , ) -> Result < ( ) , JsValue > { // draw tower base let base_size = self . rect . w ( ) * 1.25 ; ctx . draw_image_with_html_image_element_and_dw_and_dh ( sprites . get ( & self . base_img ) . unwrap ( ) , self . rect . center_x ( ) - base_size * 0.5 , self . rect . center_y ( ) - base_size / 2.5 , base_size , base_size , ) ? ; // draw top sprite with potential blast sprite ctx . translate ( self . rect . center_x ( ) , self . rect . center_y ( ) ) ? ; ctx . rotate ( self . rotation ) ? ; if Date :: now ( ) - self . last_dmg_time < 100.0 { ctx . draw_image_with_html_image_element_and_dw_and_dh ( sprites . get ( & self . blast_img ) . unwrap ( ) , - self . rect . w ( ) * 0.5 , - self . rect . h ( ) * 1.4 , self . rect . w ( ) . floor ( ) , self . rect . h ( ) . floor ( ) , ) ? ; } ctx . draw_image_with_html_image_element_and_dw_and_dh ( sprites . get ( & self . top_img ) . unwrap ( ) , ( - self . rect . w ( ) * 0.5 ) . floor ( ) , ( - self . rect . h ( ) * 0.5 ) . floor ( ) , self . rect . w ( ) . floor ( ) , self . rect . h ( ) . floor ( ) , ) ? ; ctx . set_transform ( 1.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 ) ? ; if self . mouse_over { self . draw_range ( ctx ) ? ; self . draw_selection ( ctx ) ? ; } if let TowerStatus :: Selected = self . status { self . draw_selection ( ctx ) ? ; self . upgrade_button . draw ( ctx , sprites ) ? ; self . delete_button . draw ( ctx , sprites ) ? ; } Ok ( ( ) ) }
Draws the Tower on the referenced Context
Draws the Tower on the referenced Context
&self
ctx
&CanvasRenderingContext2d
sprites
&HashMap<String, HtmlImageElement>
&self
ctx
&CanvasRenderingContext2d
sprites
&HashMap<String, HtmlImageElement>