- File Changes
- .gitignore
- Cargo.toml
- assets/bardo.png
- assets/darkdimension.png
- assets/reaper.png
- src/main.rs
- assets
-
src
- main.rs
- .gitignore
- Cargo.toml
+16
-9
src/main.rs
1 | 1 |
|
2 | 2 |
|
3 | 3 |
|
4 |
|
|
4 | 5 |
|
5 | 6 |
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
6 | 13 |
|
7 | 14 |
|
8 | 15 |
|
9 | 16 |
|
10 |
|
|
17 |
|
|
11 | 18 |
|
12 | 19 |
|
13 | 20 |
|
14 | 21 |
|
15 | 22 |
|
16 | 23 |
|
17 | 24 |
|
18 |
|
|
19 |
|
|
20 |
|
|
21 | 25 |
|
22 | 26 |
|
23 | 27 |
|
24 |
|
|
25 |
|
|
26 |
|
|
28 |
|
|
27 | 29 |
|
28 | 30 |
|
29 | 31 |
|
30 | 32 |
|
31 | 33 |
|
32 | 34 |
|
33 | 35 |
|
34 | 36 |
|
35 | 37 |
|
36 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
37 | 44 |
|
38 |
|
|
45 |
|
|
39 | 46 |
|
40 | 47 |
|
41 | 48 |
|
42 | 49 |
|
43 | 50 |
|
+16
-9
src/main.rs
1 |
|
1 |
|
2 |
|
2 |
|
3 |
|
3 |
|
4 |
|
||
4 |
|
5 |
|
5 |
|
6 |
|
7 |
|
||
8 |
|
||
9 |
|
||
10 |
|
||
11 |
|
||
12 |
|
||
6 |
|
13 |
|
7 |
|
14 |
|
8 |
|
15 |
|
9 |
|
16 |
|
10 |
|
17 |
|
11 |
|
18 |
|
12 |
|
19 |
|
13 |
|
20 |
|
14 |
|
21 |
|
15 |
|
22 |
|
16 |
|
23 |
|
17 |
|
24 |
|
18 |
|
||
19 |
|
||
20 |
|
||
21 |
|
25 |
|
22 |
|
26 |
|
23 |
|
27 |
|
24 |
|
28 |
|
25 |
|
||
26 |
|
||
27 |
|
29 |
|
28 |
|
30 |
|
29 |
|
31 |
|
30 |
|
32 |
|
31 |
|
33 |
|
32 |
|
34 |
|
33 |
|
35 |
|
34 |
|
36 |
|
35 |
|
37 |
|
36 |
|
38 |
|
39 |
|
||
40 |
|
||
41 |
|
||
42 |
|
||
43 |
|
||
37 |
|
44 |
|
38 |
|
45 |
|
39 |
|
46 |
|
40 |
|
47 |
|
41 |
|
48 |
|
42 |
|
49 |
|
43 |
|
50 |
|
/target
**/*.rs.bk
[package]
name = "game-tutorial"
version = "0.1.0"
authors = ["Sunjay Varma <[email protected]>"]
edition = "2018"
[dependencies]
sdl2 = "0.32.1"
use sdl2::pixels::Color;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use sdl2::render::WindowCanvas;
use std::time::Duration;
fn render(canvas: &mut WindowCanvas, color: Color) {
canvas.set_draw_color(color);
canvas.clear();
canvas.present();
}
fn main() -> Result<(), String> {
let sdl_context = sdl2::init()?;
let video_subsystem = sdl_context.video()?;
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 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));
// Time management!
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60));
}
Ok(())
}