X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fmain.rs;h=217918c3b85ff2bcab1d972f722bfc1874588c0c;hb=fea68d56aa10f9e91f922323676ef7ff468340f6;hp=4c399c62a56f1ded337ac3de533a9bebdab6bafb;hpb=95e3e10de390930a0f26317dae544f4a2c1bda2e;p=kaka%2Frust-sdl-test.git diff --git a/src/main.rs b/src/main.rs index 4c399c6..217918c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,10 +13,10 @@ use sdl2::rect::Rect; use sdl2::video::FullscreenType; use time::PreciseTime; -use app::*; +use game::app::*; use common::Point2D; -mod app; +mod game; #[macro_use] mod common; mod boll; mod sprites; @@ -28,7 +28,12 @@ const NS_PER_FRAME: u32 = 1_000_000_000 / FPS; fn main() { println!("starting..."); - let mut app = App::new(); + let mut app = App::new() + .with_resolution(SCREEN_WIDTH as u16, SCREEN_HEIGHT as u16) + .with_state(Box::new(ActiveState::new())) + .with_title("SDL test") + .build() + .unwrap(); app.load_sprites(&[ ("block", "res/block.bmp"), ("mario", "res/mario-trans.png"), @@ -49,9 +54,9 @@ fn main() { let offset = point!((SCREEN_WIDTH as i32 - (blocks + 1) * size) / 2, (SCREEN_HEIGHT as i32 - (blocks + 1) * size) / 2); let block = app.sprites.get("block"); for i in 0..blocks { - app.canvas.copy(block, None, Rect::new((i) * size + offset.x, (0) * size + offset.y, size as u32, size as u32)).unwrap(); + app.canvas.copy(block, None, Rect::new((i) * size + offset.x, offset.y, size as u32, size as u32)).unwrap(); app.canvas.copy(block, None, Rect::new((blocks - i) * size + offset.x, (blocks) * size + offset.y, size as u32, size as u32)).unwrap(); - app.canvas.copy(block, None, Rect::new((0) * size + offset.x, (blocks - i) * size + offset.y, size as u32, size as u32)).unwrap(); + app.canvas.copy(block, None, Rect::new(offset.x, (blocks - i) * size + offset.y, size as u32, size as u32)).unwrap(); app.canvas.copy(block, None, Rect::new((blocks) * size + offset.x, (i) * size + offset.y, size as u32, size as u32)).unwrap(); } } @@ -61,7 +66,12 @@ fn main() { let radius = 110.0 + size as f32 * 0.5; let angle = (mario_angle as f32 - 90.0) * PI / 180.0; let offset2 = point!((angle.cos() * radius) as i32, (angle.sin() * radius) as i32); - app.canvas.copy_ex(app.sprites.get("mario"), None, Rect::new(offset.x + offset2.x, offset.y + offset2.y, size as u32, size as u32), mario_angle, sdl2::rect::Point::new(size / 2, size / 2), false, false).unwrap(); + app.canvas.copy_ex( + app.sprites.get("mario"), + None, Rect::new(offset.x + offset2.x, offset.y + offset2.y, size as u32, size as u32), + mario_angle, + sdl2::rect::Point::new(size / 2, size / 2), + false, false).unwrap(); mario_angle += 1.0; if mario_angle >= 360.0 { mario_angle -= 360.0 } }