summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-01-28 22:58:16 +0100
committertroido <troido@protonmail.com>2020-01-28 22:58:16 +0100
commitb3356eabcea09f599ad99c1332450e4d9570161b (patch)
tree3cdb9c9a2092f66a3f3d9dfeade6fcb80294579c /src/main.rs
parent1175f8b436d15c47fb60866755921fc68183dc72 (diff)
refacored systems, components, resources and assemblages into their own files
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index c3a02e9..9b313be 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,11 +9,16 @@ pub mod gameserver;
pub mod room;
pub mod util;
pub mod controls;
+pub mod assemblages;
+pub mod components;
+pub mod resources;
+pub mod systems;
use self::gameserver::{GameServer, Action};
use self::server::unixserver::UnixServer;
use self::server::tcpserver::TcpServer;
use self::server::Server;
+use self::assemblages::{Player, Wall, Grass};
use serde_json;
@@ -34,11 +39,13 @@ fn main() {
let mut room = room::Room::new((32, 32));
+ gen_room(&mut room);
+
loop {
let actions = gameserver.update();
for action in actions {
match action {
- Action::Join(name) => {room.add_player(&name);}
+ Action::Join(name) => {room.add_player(&name, &Player::new(&name));}
Action::Leave(name) => {room.remove_player(&name);}
Action::Input(name, control) => {room.control(name, control);}
}
@@ -51,6 +58,24 @@ fn main() {
}
}
+fn gen_room(room: &mut room::Room){
+
+ let (width, height) = room.get_size();
+ for x in 0..width {
+ room.add_obj(&Wall, (x, 0));
+ room.add_obj(&Wall, (x, height - 1));
+ }
+ for y in 1..height-1 {
+ room.add_obj(&Wall, (0, y));
+ room.add_obj(&Wall, (width - 1, y));
+ }
+ for x in 1..width-1 {
+ for y in 1..height-1 {
+ room.add_obj(&Grass::new(), (x, y));
+ }
+ }
+}
+
fn create_update_message((width, height): (i32, i32), field: Vec<usize>, mapping: Vec<Vec<String>>) -> String {
let updatemsg= serde_json::json!([