diff --git a/client/index.js b/client/index.js index d7bc2ce..d934cee 100644 --- a/client/index.js +++ b/client/index.js @@ -1,7 +1,8 @@ import {create as createClient} from '@avocado/client'; import {EntityList} from '@avocado/entity'; import {ActionRegistry} from '@avocado/input'; -import {AnimationView, Color, Container, Primitives, Renderer} from '@avocado/graphics'; +import {Container, Renderer, ShapeView} from '@avocado/graphics'; +import {shapeFromJSON} from '@avocado/physics'; import {StateSynchronizer} from '@avocado/state'; import {Animation} from '@avocado/timing'; @@ -20,6 +21,11 @@ entityList.on('entityAdded', (entity) => { // Add to graphics. if ('container' in entity) { stage.addChild(entity.container); + if (entity.hasTrait('physical')) { + const shapeView = new ShapeView(entity.shape); + shapeView.zIndex = 100; + entity.container.addChild(shapeView); + } } // Set self entity. if ('string' === typeof selfEntity) { diff --git a/package.json b/package.json index 66db257..61e73e2 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@avocado/graphics": "1.x", "@avocado/input": "1.x", "@avocado/mixins": "1.x", + "@avocado/physics": "^1.0.0", "@avocado/resource": "1.x", "@avocado/server": "1.x", "@avocado/state": "1.x", diff --git a/server/game.js b/server/game.js index 8282bc9..e9bd91f 100644 --- a/server/game.js +++ b/server/game.js @@ -88,6 +88,15 @@ function createEntityForConnection(socket) { speed: 400, }, }, + physical: { + params: { + shape: { + type: 'rectangle', + position: [0, 0], + size: [32, 32], + } + } + }, positioned: { state: { x: 100, @@ -126,6 +135,15 @@ function createFlowerBarrelEntity(position) { }, existent: {}, graphical: {}, + physical: { + params: { + shape: { + type: 'rectangle', + position: [0, 0], + size: [32, 32], + } + } + }, positioned: { state: { x: position[0], diff --git a/yarn.lock b/yarn.lock index a99a53e..f101f8f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -56,6 +56,10 @@ version "1.0.0" resolved "https://npm.i12e.cha0s.io/@avocado%2fmixins/-/mixins-1.0.0.tgz#6fe5f8c9d340d502ec4797827efb004a0c833977" +"@avocado/physics@^1.0.0": + version "1.0.0" + resolved "https://npm.i12e.cha0s.io/@avocado%2fphysics/-/physics-1.0.0.tgz#d165c45d832ab07030dc841d40eb1ab4af62bff5" + "@avocado/resource@1.x": version "1.0.0" resolved "https://npm.i12e.cha0s.io/@avocado%2fresource/-/resource-1.0.0.tgz#3cb94928c59207b1d79fd491818f9d87c9a376be"