use sprites::SpriteManager;
use std::f32::consts::PI;
use time::PreciseTime;
-use {SCREEN_HEIGHT, SCREEN_WIDTH};
pub type Nanoseconds = u64;
let event_pump = context.event_pump()?;
let sprites = SpriteManager::new(canvas.texture_creator());
+ let screen = canvas.output_size().unwrap();
Ok(App {
canvas,
event_pump,
sprites,
- state: self.state.unwrap_or_else(|| Box::new(ActiveState::new())),
+ state: self.state.unwrap_or_else(|| Box::new(ActiveState::new(screen))),
})
}
let mut frame_count: u64 = 0;
let mut fps_time = PreciseTime::now();
let mut last_time = PreciseTime::now();
+ let screen = self.canvas.output_size().unwrap();
+ let screen = Rect::from((screen.0 as i32, screen.1 as i32));
let mut mario_angle = 0.0;
let blocks = 20;
let size = 32;
let offset = point!(
- (SCREEN_WIDTH as i32 - (blocks + 1) * size) / 2,
- (SCREEN_HEIGHT as i32 - (blocks + 1) * size) / 2
+ (screen.width - (blocks + 1) * size) / 2,
+ (screen.height - (blocks + 1) * size) / 2
);
let block = self.sprites.get("block");
for i in 0..blocks {
{
let size = 64;
let offset = point!(
- (SCREEN_WIDTH as i32 - size) / 2,
- (SCREEN_HEIGHT as i32 - size) / 2
+ (screen.width - size) / 2,
+ (screen.height - size) / 2
);
let radius = 110.0 + size as f32 * 0.5;
let angle = (mario_angle as f32 - 90.0) * PI / 180.0;
}
}
{
- let p = point!((SCREEN_WIDTH / 2) as i16, (SCREEN_HEIGHT / 2) as i16);
+ let p = point!((screen.width / 2) as i16, (screen.height / 2) as i16);
self.canvas
.circle(p.x, p.y, 100, Color::RGB(255, 255, 255))
.unwrap();
type Bollar = Vec<Box<dyn Boll>>;
pub struct ActiveState {
+ screen: Rect<u32>,
bolls: Bollar,
boll_size: u32,
}
impl ActiveState {
- pub fn new() -> ActiveState {
+ pub fn new(screen: (u32, u32)) -> ActiveState {
ActiveState {
bolls: Bollar::new(),
boll_size: 1,
+ screen: Rect::from(screen),
}
}
let mut rng = rand::thread_rng();
self.bolls.push(Box::new(SquareBoll {
pos: point!(
- rng.gen_range(0, SCREEN_WIDTH) as f64,
- rng.gen_range(0, SCREEN_HEIGHT) as f64
+ rng.gen_range(0, self.screen.width) as f64,
+ rng.gen_range(0, self.screen.height) as f64
),
vel: point!(rng.gen_range(-2.0, 2.0), rng.gen_range(-2.0, 2.0)),
}));
mod boll;
mod sprites;
-const SCREEN_WIDTH: u32 = 1280;
-const SCREEN_HEIGHT: u32 = (SCREEN_WIDTH as f64 * (1440.0 / 2560.0)) as u32;
+const SCREEN_WIDTH: u16 = 1280;
+const SCREEN_HEIGHT: u16 = (SCREEN_WIDTH as f64 * (1440.0 / 2560.0)) as u16;
fn main() {
println!("starting...");
let mut app = App::new()
- .with_resolution(SCREEN_WIDTH as u16, SCREEN_HEIGHT as u16)
- .with_state(Box::new(ActiveState::new()))
+ .with_resolution(SCREEN_WIDTH, SCREEN_HEIGHT)
+ .with_state(Box::new(ActiveState::new((SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32))))
.with_title("SDL test")
.build()
.unwrap();