|
@@ -1,13 +1,6 @@
|
|
|
#[macro_use]
|
|
|
extern crate specs_derive;
|
|
|
|
|
|
-use ggez::{
|
|
|
- event::{self, EventHandler},
|
|
|
- Context, ContextBuilder, GameResult,
|
|
|
-};
|
|
|
-
|
|
|
-use specs::world::WorldExt;
|
|
|
-
|
|
|
pub mod components;
|
|
|
pub mod consts;
|
|
|
pub mod game;
|
|
@@ -15,51 +8,10 @@ pub mod resources;
|
|
|
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::<resources::KeySet>().insert(keycode);
|
|
|
- }
|
|
|
-
|
|
|
- fn key_up_event(
|
|
|
- &mut self,
|
|
|
- _ctx: &mut Context,
|
|
|
- keycode: winit::VirtualKeyCode,
|
|
|
- _keymod: ggez::event::KeyMods,
|
|
|
- ) {
|
|
|
- self.world.write_resource::<resources::KeySet>().remove(&keycode);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
fn main() -> Result<(), ggez::error::GameError> {
|
|
|
- let mut world = specs::World::new();
|
|
|
- components::register(&mut world);
|
|
|
-
|
|
|
- world.insert(ncollide2d::world::CollisionWorld::<f32, specs::Entity>::new(0.1));
|
|
|
- resources::world_from_file(&mut world, "assets/main.tmx");
|
|
|
|
|
|
// Make a Context and an EventLoop.
|
|
|
- let (mut ctx, mut evloop) = ContextBuilder::new("game", "me")
|
|
|
+ let (mut ctx, mut evloop) = ggez::ContextBuilder::new("game", "me")
|
|
|
.add_resource_path({
|
|
|
let base = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
|
|
let mut path = std::path::PathBuf::from(base);
|
|
@@ -73,13 +25,6 @@ fn main() -> Result<(), ggez::error::GameError> {
|
|
|
})
|
|
|
.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(resources::KeySet::new());
|
|
|
-
|
|
|
- let mut my_game = MyGame { world };
|
|
|
-
|
|
|
- event::run(&mut ctx, &mut evloop, &mut my_game)
|
|
|
+ let mut my_game = game::MyGame::setup(&mut ctx)?;
|
|
|
+ ggez::event::run(&mut ctx, &mut evloop, &mut my_game)
|
|
|
}
|