]> git.r.bdr.sh - rbdr/sumo/blobdiff - lib/factories/sumo.js
Add Grab System (#9)
[rbdr/sumo] / lib / factories / sumo.js
index e8417f9532667416b556077ca8bb9164a906997c..7b50f8ae50493ce087d8d8f570e23a12c08f7a9a 100644 (file)
@@ -10,6 +10,9 @@ import CoupledEntitiesComponent from '../components/coupled_entities';
 import DashComponent from '../components/dash';
 import ElasticComponent from '../components/elastic';
 import ForceComponent from '../components/force';
 import DashComponent from '../components/dash';
 import ElasticComponent from '../components/elastic';
 import ForceComponent from '../components/force';
+import GrabAreaComponent from '../components/grab_area';
+import GrabbableComponent from '../components/grabbable';
+import GrabComponent from '../components/grab';
 import MaxVelocityComponent from '../components/max_velocity';
 import PositionComponent from '@serpentity/components.position';
 import PixiContainerComponent from '../components/pixi_container';
 import MaxVelocityComponent from '../components/max_velocity';
 import PositionComponent from '@serpentity/components.position';
 import PixiContainerComponent from '../components/pixi_container';
@@ -96,6 +99,18 @@ export default {
     });
     entity.addComponent(new BodyComponent({ body }));
 
     });
     entity.addComponent(new BodyComponent({ body }));
 
+    // GRAB
+
+    const areaSizeFactor = 2; // Multiplier vs the radius
+    const area = Bodies.circle(position.x / Config.meterSize, position.y / Config.meterSize, (radius * areaSizeFactor) / Config.meterSize, {
+      label: 'Sumo Grab Area',
+      isSensor: true
+    });
+
+    entity.addComponent(new GrabAreaComponent({ area }));
+    entity.addComponent(new GrabComponent({ body }));
+    entity.addComponent(new GrabbableComponent({ body }));
+
     if (engine) {
       engine.addEntity(entity);
     }
     if (engine) {
       engine.addEntity(entity);
     }
@@ -235,6 +250,16 @@ export default {
             component: DashComponent,
             property: 'dashing'
           }
             component: DashComponent,
             property: 'dashing'
           }
+        },
+        {
+          source: {
+            type: 'keyboard',
+            index: 88 // X
+          },
+          target: {
+            component: GrabComponent,
+            property: 'grabbing'
+          }
         }
       ]
     }));
         }
       ]
     }));