- File Changes
- .gitignore
- assets/reaper.png
- assets/bardo.png
- assets/darkdimension.png
- Cargo.toml
- src/main.rs
- assets
-
src
- main.rs
- .gitignore
- Cargo.toml
+5
-1
Cargo.toml
1 | 1 |
|
2 | 2 |
|
3 | 3 |
|
4 | 4 |
|
5 | 5 |
|
6 | 6 |
|
7 | 7 |
|
8 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
+17
-3
src/main.rs
1 | 1 |
|
2 | 2 |
|
3 | 3 |
|
4 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
5 | 7 |
|
6 | 8 |
|
7 |
|
|
9 |
|
|
8 | 10 |
|
9 | 11 |
|
12 |
|
|
13 |
|
|
14 |
|
|
10 | 15 |
|
16 |
|
|
17 |
|
|
11 | 18 |
|
12 | 19 |
|
13 | 20 |
|
14 | 21 |
|
15 | 22 |
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
16 | 27 |
|
17 | 28 |
|
18 | 29 |
|
19 | 30 |
|
20 | 31 |
|
21 | 32 |
|
22 | 33 |
|
23 | 34 |
|
24 | 35 |
|
36 |
|
|
37 |
|
|
38 |
|
|
25 | 39 |
|
26 | 40 |
|
27 | 41 |
|
28 | 42 |
|
29 | 43 |
|
30 | 44 |
|
31 | 45 |
|
32 | 46 |
|
33 | 47 |
|
34 | 48 |
|
35 | 49 |
|
36 | 50 |
|
37 | 51 |
|
38 | 52 |
|
39 | 53 |
|
40 | 54 |
|
41 | 55 |
|
42 | 56 |
|
43 |
|
|
57 |
|
|
44 | 58 |
|
45 | 59 |
|
46 | 60 |
|
47 | 61 |
|
48 | 62 |
|
49 | 63 |
|
50 | 64 |
|
+5
-1
Cargo.toml
1 |
|
1 |
|
2 |
|
2 |
|
3 |
|
3 |
|
4 |
|
4 |
|
5 |
|
5 |
|
6 |
|
6 |
|
7 |
|
7 |
|
8 |
|
8 |
|
9 |
|
||
10 |
|
||
11 |
|
||
12 |
|
+17
-3
src/main.rs
1 |
|
1 |
|
2 |
|
2 |
|
3 |
|
3 |
|
4 |
|
4 |
|
5 |
|
||
6 |
|
||
5 |
|
7 |
|
6 |
|
8 |
|
7 |
|
9 |
|
8 |
|
10 |
|
9 |
|
11 |
|
12 |
|
||
13 |
|
||
14 |
|
||
10 |
|
15 |
|
16 |
|
||
17 |
|
||
11 |
|
18 |
|
12 |
|
19 |
|
13 |
|
20 |
|
14 |
|
21 |
|
15 |
|
22 |
|
23 |
|
||
24 |
|
||
25 |
|
||
26 |
|
||
16 |
|
27 |
|
17 |
|
28 |
|
18 |
|
29 |
|
19 |
|
30 |
|
20 |
|
31 |
|
21 |
|
32 |
|
22 |
|
33 |
|
23 |
|
34 |
|
24 |
|
35 |
|
36 |
|
||
37 |
|
||
38 |
|
||
25 |
|
39 |
|
26 |
|
40 |
|
27 |
|
41 |
|
28 |
|
42 |
|
29 |
|
43 |
|
30 |
|
44 |
|
31 |
|
45 |
|
32 |
|
46 |
|
33 |
|
47 |
|
34 |
|
48 |
|
35 |
|
49 |
|
36 |
|
50 |
|
37 |
|
51 |
|
38 |
|
52 |
|
39 |
|
53 |
|
40 |
|
54 |
|
41 |
|
55 |
|
42 |
|
56 |
|
43 |
|
57 |
|
44 |
|
58 |
|
45 |
|
59 |
|
46 |
|
60 |
|
47 |
|
61 |
|
48 |
|
62 |
|
49 |
|
63 |
|
50 |
|
64 |
|
/target
**/*.rs.bk
[package]
name = "game-tutorial"
version = "0.1.0"
authors = ["Sunjay Varma <[email protected]>"]
edition = "2018"
[dependencies]
[dependencies.sdl2]
version = "0.32.1"
default-features = false
features = ["image"]
use sdl2::pixels::Color;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use sdl2::render::{WindowCanvas, Texture};
// "self" imports the "image" module itself as well as everything else we listed
use sdl2::image::{self, LoadTexture, InitFlag};
use std::time::Duration;
fn render(canvas: &mut WindowCanvas, color: Color, texture: &Texture) -> Result<(), String> {
canvas.set_draw_color(color);
canvas.clear();
canvas.copy(texture, None, None)?;
canvas.present();
Ok(())
}
fn main() -> Result<(), String> {
let sdl_context = sdl2::init()?;
let video_subsystem = sdl_context.video()?;
// Leading "_" tells Rust that this is an unused variable that we don't care about. It has to
// stay unused because if we don't have any variable at all then Rust will treat it as a
// temporary value and drop it right away!
let _image_context = image::init(InitFlag::PNG | InitFlag::JPG)?;
let window = video_subsystem.window("game tutorial", 800, 600)
.position_centered()
.build()
.expect("could not initialize video subsystem");
let mut canvas = window.into_canvas().build()
.expect("could not make a canvas");
let texture_creator = canvas.texture_creator();
let texture = texture_creator.load_texture("assets/bardo.png")?;
let mut event_pump = sdl_context.event_pump()?;
let mut i = 0;
'running: loop {
// Handle events
for event in event_pump.poll_iter() {
match event {
Event::Quit {..} |
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
break 'running;
},
_ => {}
}
}
// Update
i = (i + 1) % 255;
// Render
render(&mut canvas, Color::RGB(i, 64, 255 - i), &texture)?;
// Time management!
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60));
}
Ok(())
}