Struct nze_game_sdl::Colour

source ·
pub struct Colour {
    pub r: u8,
    pub g: u8,
    pub b: u8,
    pub a: u8,
}
Expand description

An RGBA colour with values from 0 to 255 for each channel

Fields§

§r: u8§g: u8§b: u8§a: u8

Implementations§

source§

impl Colour

source

pub fn new(r: u8, g: u8, b: u8, a: u8) -> Colour

Examples found in repository?
examples/main.rs (line 47)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
pub fn main() -> Result<(), Error> {
    
    let (mut cam, drawing_area, context) = DrawingArea::new(
        "Game Template", //window name
        Rect::new(0.0, 0.0, 240.0, 160.0),
        Vec2::new(240.0 * 4.0, 160.0 * 4.0)
    )?;
    let mut render = Render::new(drawing_area, &context)?;
    let mut controls = Controls::new(&context)?;
   
    let mono_font = render.font_manager.load_font(
        Path::new("resources/textures/fonts/FiraCode-Light.ttf"))?;
    
    let map = Map::new(
        Path::new("resources/map/test.tmx"), &mut render.texture_manager,
        Path::new("resources/textures/fonts"), &mut render.font_manager)?;

    let mut audio = AudioManager::new()?;

    let music = audio.music.load(Path::new("resources/audio/test.wav"))?;
    audio.music.play(music, -1)?;

    let sfx = audio.sfx.load(Path::new("resources/audio/test.mp3"))?;
    audio.sfx.set_volume(sfx, 0.4)?;
    
    //checking resource loading/unloading
    let mut is_gaia = true;
    let mut ephemeral_obj = GameObject::new_from_tex(
        render.texture_manager.load(
            Path::new("resources/textures/gaia.png"))?);

    let mut text = render
        .font_manager
        .load_text_obj(
            &mono_font,
            "The Planet Earth",
            Colour::new(100, 200, 70, 255),
            Vec2::new(0.0, 0.0), 10.0,
            Vec2::new(0.0, 0.0)
        )?;

    while !controls.should_close {
        cam_controls(&mut render, &mut controls, &mut cam)?;
        controls.update(&cam);
        
        // load/unload resources
        if controls.kb.press(Key::L) ||
            controls.c.press(0, controller::Button::A)
        {
            render.texture_manager.unload_from_gameobject(ephemeral_obj);
            render.font_manager.unload_text_obj(text);
            if is_gaia {
                ephemeral_obj = GameObject::new_from_tex(
                    render.texture_manager.load(
                        Path::new("resources/textures/error.png"))?);
                text = render.font_manager.load_text_obj(
                    &mono_font,
                    "Error Text",
                    Colour::new(200, 100, 70, 255),
                    Vec2::new(100.0, 0.0),
                    10.0,
                    Vec2::new(0.0, 0.0))?;
                text.parallax = Vec2::new(1.0, 1.0);
            } else {
                ephemeral_obj = GameObject::new_from_tex(
                    render.texture_manager.load(
                        Path::new("resources/textures/gaia.png"))?);
                text = render.font_manager.load_text_obj(
                    &mono_font,
                    "The Planet Earth",
                    Colour::new(100, 200, 70, 255),
                    Vec2::new(0.0, 0.0),
                    10.0,
                    Vec2::new(0.0, 0.0))?;
            }
            is_gaia = !is_gaia;
        }
        
        ephemeral_obj.rotate += controls.frame_elapsed * 30.0;
        
        if controls.kb.press(Key::F) {
            ephemeral_obj.flip_horizontal = !ephemeral_obj.flip_horizontal;
        }

        if controls.kb.press(Key::P) {
            audio.sfx.play(sfx)?;
        }
        
        if controls.c.press(0, controller::Button::DPadUp) {
            controls.c.rumble(0, 10000, 20000, 1000);
        }
        
        render.start_draw();
        
        map.draw(&mut cam);
        cam.draw(&ephemeral_obj);
        cam.draw_text(&text);
        cam.draw_disposable_text(
            &mono_font,
            format!("Wheel: {}", controls.m.wheel()),
            40,
            controls.m.pos(),
            Colour::white(),
            Vec2::new(1.0, 1.0));
        render.end_draw(&mut cam)?;
    }

    Ok(())
}
source

pub fn new_from_floats(r: f64, g: f64, b: f64, a: f64) -> Colour

source

pub fn white() -> Colour

Examples found in repository?
examples/main.rs (line 113)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
pub fn main() -> Result<(), Error> {
    
    let (mut cam, drawing_area, context) = DrawingArea::new(
        "Game Template", //window name
        Rect::new(0.0, 0.0, 240.0, 160.0),
        Vec2::new(240.0 * 4.0, 160.0 * 4.0)
    )?;
    let mut render = Render::new(drawing_area, &context)?;
    let mut controls = Controls::new(&context)?;
   
    let mono_font = render.font_manager.load_font(
        Path::new("resources/textures/fonts/FiraCode-Light.ttf"))?;
    
    let map = Map::new(
        Path::new("resources/map/test.tmx"), &mut render.texture_manager,
        Path::new("resources/textures/fonts"), &mut render.font_manager)?;

    let mut audio = AudioManager::new()?;

    let music = audio.music.load(Path::new("resources/audio/test.wav"))?;
    audio.music.play(music, -1)?;

    let sfx = audio.sfx.load(Path::new("resources/audio/test.mp3"))?;
    audio.sfx.set_volume(sfx, 0.4)?;
    
    //checking resource loading/unloading
    let mut is_gaia = true;
    let mut ephemeral_obj = GameObject::new_from_tex(
        render.texture_manager.load(
            Path::new("resources/textures/gaia.png"))?);

    let mut text = render
        .font_manager
        .load_text_obj(
            &mono_font,
            "The Planet Earth",
            Colour::new(100, 200, 70, 255),
            Vec2::new(0.0, 0.0), 10.0,
            Vec2::new(0.0, 0.0)
        )?;

    while !controls.should_close {
        cam_controls(&mut render, &mut controls, &mut cam)?;
        controls.update(&cam);
        
        // load/unload resources
        if controls.kb.press(Key::L) ||
            controls.c.press(0, controller::Button::A)
        {
            render.texture_manager.unload_from_gameobject(ephemeral_obj);
            render.font_manager.unload_text_obj(text);
            if is_gaia {
                ephemeral_obj = GameObject::new_from_tex(
                    render.texture_manager.load(
                        Path::new("resources/textures/error.png"))?);
                text = render.font_manager.load_text_obj(
                    &mono_font,
                    "Error Text",
                    Colour::new(200, 100, 70, 255),
                    Vec2::new(100.0, 0.0),
                    10.0,
                    Vec2::new(0.0, 0.0))?;
                text.parallax = Vec2::new(1.0, 1.0);
            } else {
                ephemeral_obj = GameObject::new_from_tex(
                    render.texture_manager.load(
                        Path::new("resources/textures/gaia.png"))?);
                text = render.font_manager.load_text_obj(
                    &mono_font,
                    "The Planet Earth",
                    Colour::new(100, 200, 70, 255),
                    Vec2::new(0.0, 0.0),
                    10.0,
                    Vec2::new(0.0, 0.0))?;
            }
            is_gaia = !is_gaia;
        }
        
        ephemeral_obj.rotate += controls.frame_elapsed * 30.0;
        
        if controls.kb.press(Key::F) {
            ephemeral_obj.flip_horizontal = !ephemeral_obj.flip_horizontal;
        }

        if controls.kb.press(Key::P) {
            audio.sfx.play(sfx)?;
        }
        
        if controls.c.press(0, controller::Button::DPadUp) {
            controls.c.rumble(0, 10000, 20000, 1000);
        }
        
        render.start_draw();
        
        map.draw(&mut cam);
        cam.draw(&ephemeral_obj);
        cam.draw_text(&text);
        cam.draw_disposable_text(
            &mono_font,
            format!("Wheel: {}", controls.m.wheel()),
            40,
            controls.m.pos(),
            Colour::white(),
            Vec2::new(1.0, 1.0));
        render.end_draw(&mut cam)?;
    }

    Ok(())
}

Trait Implementations§

source§

impl Clone for Colour

source§

fn clone(&self) -> Colour

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Copy for Colour

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.