Skip to content

Commit 9783dc5

Browse files
author
Roger Russel
committed
game loop yoh who
1 parent d443315 commit 9783dc5

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ Cargo.lock
88

99
# These are backup files generated by rustfmt
1010
**/*.rs.bk
11+
12+
13+
#Added by cargo
14+
15+
/target

Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "rust-petridish"
3+
version = "0.1.0"
4+
authors = ["Roger Russel <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
sdl2 = "0.33"

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
# rust-petridish
2-
A simple Rust game with proposity of learn Rust.
2+
3+
A simple Rust game with the purpose of learning Rust.
4+
5+
## Dependencies
6+
7+
* [Rust SDL2](https://github.com/Rust-SDL2/rust-sdl2)

src/main.rs

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
extern crate sdl2;
3+
4+
use sdl2::pixels::Color;
5+
use sdl2::rect::Rect;
6+
use std::time::Duration;
7+
8+
#[derive(Debug)]
9+
struct Player {
10+
x: i32,
11+
y: i32,
12+
radius: i8,
13+
}
14+
15+
fn main() {
16+
17+
println!("");
18+
19+
game_loop();
20+
21+
}
22+
23+
fn game_loop(){
24+
25+
let mut player = Player{
26+
x: 100,
27+
y: 100,
28+
radius: 20,
29+
};
30+
31+
32+
let sdl_context = sdl2::init().unwrap();
33+
let video_subsystem = sdl_context.video().unwrap();
34+
let window = video_subsystem.window(
35+
"Petridish",
36+
800,
37+
600,
38+
).position_centered().build().unwrap();
39+
40+
let mut canvas = window.into_canvas().build().unwrap();
41+
42+
loop {
43+
44+
canvas.set_draw_color(Color::RGB(0,0,0));
45+
// canvas.clear(); // Clear Screen
46+
47+
canvas.set_draw_color(Color::RGB(255,210,0));
48+
canvas.fill_rect(Rect::new(player.x, player.y, 10, 10)).unwrap();
49+
canvas.present();
50+
51+
::std::thread::sleep(Duration::new(0,1_000_000_000u32/60,));
52+
53+
player.x += 1;
54+
player.y += 1;
55+
}
56+
57+
}

0 commit comments

Comments
 (0)