|
@@ -8,6 +8,7 @@ use specs::prelude::*;
|
|
|
use specs::world::WorldExt;
|
|
|
|
|
|
mod input;
|
|
|
+pub mod messages;
|
|
|
pub mod util;
|
|
|
|
|
|
const WIDTH: f32 = 600.0;
|
|
@@ -18,13 +19,14 @@ struct Game {
|
|
|
}
|
|
|
|
|
|
impl Game {
|
|
|
- fn setup() -> Game {
|
|
|
+ fn setup(conn: messages::Connection) -> Game {
|
|
|
let mut world = specs::World::new();
|
|
|
world.register::<Pos>();
|
|
|
world.register::<Vel>();
|
|
|
world.register::<Solid>();
|
|
|
world.register::<Controlled>();
|
|
|
world.insert(input::Input::new());
|
|
|
+ world.insert(conn);
|
|
|
world
|
|
|
.create_entity()
|
|
|
.with(Pos { x: 200.0, y: 200.0 })
|
|
@@ -55,6 +57,12 @@ pub struct Controlled;
|
|
|
#[derive(Component)]
|
|
|
pub struct Solid;
|
|
|
|
|
|
+system! {
|
|
|
+ Transmit(resource conn: messages::Connection, _c: Controlled, p: Pos) {
|
|
|
+ conn.update(p.x, p.y);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
system! {
|
|
|
Control(resource inp: input::Input, _c: Controlled, mut v: Vel) {
|
|
|
const ACCEL: f32 = 0.5;
|
|
@@ -147,6 +155,7 @@ impl ggez::event::EventHandler for Game {
|
|
|
Physics.run_now(&self.world);
|
|
|
Slowdown.run_now(&self.world);
|
|
|
Move.run_now(&self.world);
|
|
|
+ Transmit.run_now(&self.world);
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
@@ -159,6 +168,7 @@ impl ggez::event::EventHandler for Game {
|
|
|
_repeat: bool,
|
|
|
) {
|
|
|
if keycode == winit::VirtualKeyCode::Escape {
|
|
|
+ self.world.read_resource::<messages::Connection>().goodbye();
|
|
|
ggez::event::quit(ctx);
|
|
|
}
|
|
|
input::Input::handle_down(&mut self.world.write_resource(), keycode);
|
|
@@ -175,6 +185,7 @@ impl ggez::event::EventHandler for Game {
|
|
|
}
|
|
|
|
|
|
fn main() -> ggez::GameResult<()> {
|
|
|
+ let connection = messages::Connection::new("foo", "192.168.0.3", 9991);
|
|
|
let (mut ctx, mut evloop) = ggez::ContextBuilder::new("game", "me")
|
|
|
.window_mode(ggez::conf::WindowMode {
|
|
|
width: WIDTH,
|
|
@@ -182,6 +193,7 @@ fn main() -> ggez::GameResult<()> {
|
|
|
..ggez::conf::WindowMode::default()
|
|
|
})
|
|
|
.build()?;
|
|
|
- let mut game = Game::setup();
|
|
|
- ggez::event::run(&mut ctx, &mut evloop, &mut game)
|
|
|
+ let mut game = Game::setup(connection);
|
|
|
+ let res = ggez::event::run(&mut ctx, &mut evloop, &mut game);
|
|
|
+ res
|
|
|
}
|