|
@@ -59,35 +59,29 @@ impl EventHandler for State {
|
|
|
}
|
|
|
|
|
|
fn update(&mut self, _ctx: &mut Context) -> Result<(), GameError> {
|
|
|
- Draw.run_now(&mut self.world);
|
|
|
- Leftward.run_now(&mut self.world);
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
fn main() -> Result<(), GameError> {
|
|
|
- let (mut ctx, mut evloop) = ggez::ContextBuilder::new("game", "me")
|
|
|
- .add_resource_path({
|
|
|
+ let mut game = carpet::GameBuilder::new()
|
|
|
+ .name("game")
|
|
|
+ .author("me")
|
|
|
+ .resource_path({
|
|
|
let base = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
|
|
let mut path = std::path::PathBuf::from(base);
|
|
|
path.push("resources");
|
|
|
path
|
|
|
})
|
|
|
- .window_mode(ggez::conf::WindowMode {
|
|
|
- width: 80.0 * 8.0,
|
|
|
- height: 50.0 * 8.0,
|
|
|
- ..ggez::conf::WindowMode::default()
|
|
|
- })
|
|
|
+ .tileset("/terminal8x8.jpg", [8, 8])
|
|
|
+ .map_size(80, 50)
|
|
|
.build()?;
|
|
|
- let mut world = World::new();
|
|
|
- world.register::<Pos>();
|
|
|
- world.register::<Renderable>();
|
|
|
- world.register::<MoveLeft>();
|
|
|
- let tileset = carpet::Tileset::from_file(&mut ctx, [8, 8], "/terminal8x8.jpg")?;
|
|
|
- let mut board = carpet::Board::new([80, 50], tileset);
|
|
|
- board.print([1, 1], "Hello, world!");
|
|
|
+ game.register::<Pos>();
|
|
|
+ game.register::<Renderable>();
|
|
|
+ game.register::<MoveLeft>();
|
|
|
+ game.world.print([1, 1], "Hello, world!");
|
|
|
|
|
|
- world
|
|
|
+ game.world.world
|
|
|
.create_entity()
|
|
|
.with(Pos { x: 40, y: 25 })
|
|
|
.with(Renderable {
|
|
@@ -97,7 +91,7 @@ fn main() -> Result<(), GameError> {
|
|
|
.build();
|
|
|
|
|
|
for i in 0..10 {
|
|
|
- world
|
|
|
+ game.world.world
|
|
|
.create_entity()
|
|
|
.with(Pos { x: i * 7, y: 20 })
|
|
|
.with(Renderable {
|
|
@@ -107,13 +101,11 @@ fn main() -> Result<(), GameError> {
|
|
|
.with(MoveLeft)
|
|
|
.build();
|
|
|
}
|
|
|
-
|
|
|
- world.insert(board);
|
|
|
-
|
|
|
- let mut state = State { world };
|
|
|
- ggez::event::run(&mut ctx, &mut evloop, &mut state)
|
|
|
+ game.run_with_systems(|world| {
|
|
|
+ Draw.run_now(&world);
|
|
|
+ Leftward.run_now(&world);
|
|
|
+ })
|
|
|
}
|
|
|
-
|
|
|
// Local Variables:
|
|
|
// cargo-process--command-build: "build --release"
|
|
|
// cargo-process--command-run: "run --release --bin ch2"
|