#[macro_use] extern crate specs_derive; use ggez::{ event::{self, EventHandler}, Context, ContextBuilder, GameResult, }; mod nc { pub use ncollide2d::bounding_volume::*; pub use ncollide2d::broad_phase::*; pub use ncollide2d::narrow_phase::*; } use specs::world::WorldExt; pub mod com; pub mod consts; pub mod game; pub mod res; pub mod sys; pub mod types; use game::MyGame; impl EventHandler for MyGame { fn update(&mut self, _ctx: &mut Context) -> GameResult<()> { sys::input::systems(self); sys::physics::systems(self); Ok(()) } fn draw(&mut self, ctx: &mut Context) -> GameResult<()> { sys::drawing::systems(self, ctx) } fn key_down_event( &mut self, ctx: &mut Context, keycode: winit::VirtualKeyCode, _keymod: ggez::event::KeyMods, _repeat: bool, ) { if keycode == winit::VirtualKeyCode::Escape { ggez::event::quit(ctx); } self.world.write_resource::().insert(keycode); } fn key_up_event( &mut self, _ctx: &mut Context, keycode: winit::VirtualKeyCode, _keymod: ggez::event::KeyMods, ) { self.world.write_resource::().remove(&keycode); } } fn main() -> Result<(), ggez::error::GameError> { let mut world = specs::World::new(); com::register(&mut world); world.insert(ncollide2d::world::CollisionWorld::>::new(0.1)); res::world_from_file(&mut world, "assets/main.tmx"); // Make a Context and an EventLoop. let (mut ctx, mut evloop) = ContextBuilder::new("game", "me") .add_resource_path({ let base = std::env::var("CARGO_MANIFEST_DIR").unwrap(); let mut path = std::path::PathBuf::from(base); path.push("assets"); path }) .window_mode(ggez::conf::WindowMode { width: consts::WINDOW_WIDTH, height: consts::WINDOW_HEIGHT, ..Default::default() }) .build()?; let image = ggez::graphics::Image::new(&mut ctx, "/spritesheet.png")?; let mut sprites = ggez::graphics::spritebatch::SpriteBatch::new(image); sprites.set_filter(ggez::graphics::FilterMode::Nearest); world.insert(sprites); world.insert(res::KeySet::new()); let mut my_game = MyGame { world }; event::run(&mut ctx, &mut evloop, &mut my_game) }