use crate::vertex_2d::ColoredVertex2D;

#[derive(Debug, Clone)]
pub struct Sprite {
    vertices: [ColoredVertex2D; 6],
    color: [f32; 4],
}

impl Sprite {

    pub fn new(position: (f32, f32), size: (u32, u32)) -> Sprite {
        Sprite::new_with_color(position, size, (0.,0.,0.,0.))
    }

    pub fn new_with_color(position: (f32, f32), size: (u32, u32), color: (f32, f32, f32, f32)) -> Sprite {

        let size = (size.0 as f32, size.1 as f32);

        let color = [color.0, color.1, color.2, color.3];

        Sprite {
            vertices: [
                ColoredVertex2D { position: [ position.0, position.1 ], color },                   // top left
                ColoredVertex2D { position: [ position.0, position.1 + size.1], color },          // bottom left
                ColoredVertex2D { position: [ position.0 + size.0, position.1 + size.1 ], color }, // bottom right

                ColoredVertex2D { position: [ position.0, position.1 ], color },                   // top left
                ColoredVertex2D { position: [ position.0 + size.0, position.1 + size.1 ], color }, // bottom right
                ColoredVertex2D { position: [ position.0 + size.0, position.1 ], color },          // top right
            ],
            color: color,
        }
    }
}