--- /dev/null
+use sdl2::EventPump;
+use sdl2::pixels::Color;
+use sdl2::render::BlendMode;
+use sdl2::render::Canvas;
+use sdl2::video::Window;
+
+use {SCREEN_HEIGHT, SCREEN_WIDTH};
+use sprites::SpriteManager;
+
+pub struct App {
+ pub canvas: Canvas<Window>,
+ pub event_pump: EventPump,
+ pub sprites: SpriteManager,
+}
+
+impl App {
+ pub fn new() -> App {
+ let context = sdl2::init().unwrap();
+ sdl2::image::init(sdl2::image::InitFlag::PNG).unwrap();
+ let window = context.video().unwrap().window("SDL test", SCREEN_WIDTH, SCREEN_HEIGHT)
+ .position_centered()
+ .opengl()
+ .build()
+ .unwrap();
+ context.mouse().show_cursor(false);
+ let mut canvas = window.into_canvas().build().unwrap();
+ canvas.set_blend_mode(BlendMode::Add);
+ canvas.set_draw_color(Color::RGB(0, 0, 0));
+ canvas.clear();
+ canvas.present();
+ let event_pump = context.event_pump().unwrap();
+ let sprites = SpriteManager::new(canvas.texture_creator());
+ App {
+ canvas,
+ event_pump,
+ sprites,
+ }
+ }
+
+ pub fn load_sprites(&mut self, sprites: &[(&'static str, &str)]) {
+ for (name, file) in sprites {
+ self.sprites.load(name, file);
+ }
+ }
+}
use rand::Rng;
use sdl2::event::Event;
use sdl2::event::WindowEvent;
-use sdl2::EventPump;
use sdl2::gfx::primitives::DrawRenderer;
use sdl2::keyboard::Keycode;
use sdl2::pixels::Color;
use sdl2::rect::Rect;
-use sdl2::render::BlendMode;
-use sdl2::render::Canvas;
use sdl2::video::FullscreenType;
-use sdl2::video::Window;
use time::PreciseTime;
+use app::*;
use boll::{Boll, CircleBoll, SquareBoll};
use common::Point2D;
-use sprites::SpriteManager;
+mod app;
#[macro_use] mod common;
mod boll;
mod sprites;
type Bollar = Vec<Box<dyn Boll>>;
-struct App {
- canvas: Canvas<Window>,
- event_pump: EventPump,
- sprites: SpriteManager,
-}
-
-impl App {
- fn new() -> App {
- let context = sdl2::init().unwrap();
- sdl2::image::init(sdl2::image::InitFlag::PNG).unwrap();
- let window = context.video().unwrap().window("SDL test", SCREEN_WIDTH, SCREEN_HEIGHT)
- .position_centered()
- .opengl()
- .build()
- .unwrap();
- context.mouse().show_cursor(false);
- let mut canvas = window.into_canvas().build().unwrap();
- canvas.set_blend_mode(BlendMode::Add);
- canvas.set_draw_color(Color::RGB(0, 0, 0));
- canvas.clear();
- canvas.present();
- let event_pump = context.event_pump().unwrap();
- let sprites = SpriteManager::new(canvas.texture_creator());
- App {
- canvas,
- event_pump,
- sprites,
- }
- }
-
- fn load_sprites(&mut self, sprites: &[(&'static str, &str)]) {
- for (name, file) in sprites {
- self.sprites.load(name, file);
- }
- }
-}
-
fn main() {
println!("starting...");
let mut app = App::new();