mirror of
https://github.com/thilo-behnke/wasm-pong.git
synced 2026-07-11 02:29:25 +00:00
trait matching does not exist
This commit is contained in:
@@ -2,10 +2,11 @@ pub mod game_object {
|
||||
use std::fmt::Debug;
|
||||
use crate::game_object::components::{GeomComp, PhysicsComp};
|
||||
use crate::geom::geom::{BoundingBox, Vector};
|
||||
use crate::geom::shape::ShapeType;
|
||||
use crate::geom::shape::{Shape, ShapeType};
|
||||
|
||||
pub trait GameObject : Debug {
|
||||
fn id(&self) -> u16;
|
||||
fn shape(&self) -> &Box<dyn Shape>;
|
||||
fn pos(&self) -> &Vector;
|
||||
fn pos_mut(&mut self) -> &mut Vector;
|
||||
fn orientation(&self) -> &Vector;
|
||||
@@ -35,6 +36,10 @@ pub mod game_object {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn shape(&self) -> &Box<dyn Shape> {
|
||||
self.geom.shape()
|
||||
}
|
||||
|
||||
fn pos(&self) -> &Vector {
|
||||
self.geom.center()
|
||||
}
|
||||
@@ -86,6 +91,7 @@ pub mod components {
|
||||
use crate::geom::shape::Shape;
|
||||
|
||||
pub trait GeomComp : Debug {
|
||||
fn shape(&self) -> &Box<dyn Shape>;
|
||||
fn orientation(&self) -> &Vector;
|
||||
fn orientation_mut(&mut self) -> &mut Vector;
|
||||
fn center(&self) -> &Vector;
|
||||
@@ -105,6 +111,10 @@ pub mod components {
|
||||
}
|
||||
|
||||
impl GeomComp for DefaultGeomComp {
|
||||
fn shape(&self) -> &Box<dyn Shape> {
|
||||
&self.shape
|
||||
}
|
||||
|
||||
fn orientation(&self) -> &Vector {
|
||||
&self.shape.orientation()
|
||||
}
|
||||
|
||||
17
src/lib.rs
17
src/lib.rs
@@ -38,15 +38,16 @@ pub struct GameObjectDTO {
|
||||
}
|
||||
|
||||
impl GameObjectDTO {
|
||||
pub fn from(obj: &GameObject) -> GameObjectDTO {
|
||||
pub fn from(obj: &Box<dyn GameObject>) -> GameObjectDTO {
|
||||
let pos = obj.pos();
|
||||
let shape = obj.shape();
|
||||
return GameObjectDTO {
|
||||
id: obj.id,
|
||||
x: obj.pos.x as u16,
|
||||
y: obj.pos.y as u16,
|
||||
shape_param_1: match obj.shape_params[..] {
|
||||
[p1, _] => p1,
|
||||
[p1] => p1,
|
||||
_ => 0,
|
||||
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_2: match obj.shape_params[..] {
|
||||
[_, p2] => p2,
|
||||
|
||||
Reference in New Issue
Block a user