diff --git a/pong/src/game_field.rs b/pong/src/game_field.rs index a292cb8..6bc9103 100644 --- a/pong/src/game_field.rs +++ b/pong/src/game_field.rs @@ -106,19 +106,22 @@ impl Field { let mut objs: Vec<&Box> = vec![]; objs.extend( self.players - .iter() + .clone() + .into_iter() .map(|p| &p.obj) .collect::>>(), ); - // objs.extend( - // self.balls - // .iter() - // .map(|b| &b.obj) - // .collect::>>(), - // ); + objs.extend( + self.balls + .clone() + .into_iter() + .map(|b| &b.obj) + .collect::>>(), + ); objs.extend( self.bounds.objs - .iter() + .clone() + .into_iter() .collect::>>() ); let collision_detector = CollisionDetector::new(); @@ -137,7 +140,6 @@ impl Field { collision => objs.iter().find(|o| o.id() == collision.0).unwrap(), }; - self.logger.log("### BEFORE COLLISION ###"); self.logger.log(&*format!("{:?}", ball.obj)); self.logger.log(&*format!("{:?}", other)); diff --git a/pong/src/game_object.rs b/pong/src/game_object.rs index 16e4878..219c895 100644 --- a/pong/src/game_object.rs +++ b/pong/src/game_object.rs @@ -4,7 +4,7 @@ pub mod game_object { use crate::geom::geom::{BoundingBox, Vector}; use crate::geom::shape::{Shape, ShapeType}; - pub trait GameObject : Debug { + pub trait GameObject : Debug + Clone { fn id(&self) -> u16; fn shape(&self) -> &ShapeType; fn pos(&self) -> &Vector; @@ -18,7 +18,7 @@ pub mod game_object { } // #[derive(Clone, Debug, PartialEq)] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct DefaultGameObject { pub id: u16, geom: Box, diff --git a/src/lib.rs b/src/lib.rs index dd2e99e..b0f51ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,8 +6,9 @@ use std::cmp::{max, min}; use wasm_bindgen::prelude::*; use pong::collision::collision::{Collision, CollisionDetector}; use pong::game_field::{Field, Input, InputType}; -use pong::game_object::game_object::{GameObject, ShapeType}; +use pong::game_object::game_object::{GameObject}; use pong::geom::geom::Vector; +use pong::geom::shape::ShapeType; use pong::utils::utils::Logger; extern crate serde_json; @@ -45,13 +46,13 @@ impl GameObjectDTO { id: obj.id(), x: pos.x as u16, y: pos.y as u16, - shape_param_1: match shape.shape_type() { - ShapeType::Rect => shape., - ShapeType::Circle => + shape_param_1: match shape { + ShapeType::Rect(_, width, _) => *width as u16, + ShapeType::Circle(_, radius) => *radius as u16 }, - shape_param_2: match obj.shape_params[..] { - [_, p2] => p2, - _ => 0, + shape_param_2: match shape { + ShapeType::Rect(_, _, height) => *height as u16, + ShapeType::Circle(_, _) => 0 }, }; } @@ -115,7 +116,7 @@ impl FieldWrapper { let input_dtos: Vec = inputs_js.into_serde().unwrap(); let inputs = input_dtos.into_iter().map(|i| i.to_input()).collect::>(); self.field.tick(inputs); - // log!("{:?}", self.field.collisions); + log!("{:?}", self.field.collisions); } pub fn objects(&self) -> *const GameObjectDTO {