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;
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_fps(60)
+ .with_state(Box::new(ActiveState::new()))
+ .with_title("SDL test")
+ .start();
app.load_sprites(&[
("block", "res/block.bmp"),
("mario", "res/mario-trans.png"),
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();
}
}
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 }
}