From dbd6091accdd4ed7aa408400be605aa327cf9028 Mon Sep 17 00:00:00 2001 From: cha0s Date: Mon, 19 Apr 2021 06:54:38 -0500 Subject: [PATCH] feat: seeds --- packages/farm/src/traits/seeds.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 packages/farm/src/traits/seeds.js diff --git a/packages/farm/src/traits/seeds.js b/packages/farm/src/traits/seeds.js new file mode 100644 index 0000000..2e5a2c6 --- /dev/null +++ b/packages/farm/src/traits/seeds.js @@ -0,0 +1,24 @@ +import {Rectangle, Vector} from '@avocado/math'; +import {Trait} from '@avocado/traits'; + +export default () => class Seeds extends Trait { + + // eslint-disable-next-line class-methods-use-this + methods() { + return { + + isPlantAt: (position, list) => { + const entities = list.visibleEntities(Rectangle.centerOn(position, [1, 1])); + for (let i = 0; i < entities.length; ++i) { + const entity = entities[i]; + if (Vector.equals(entity.position, position) && entity.is('Plant')) { + return true; + } + } + return false; + }, + + }; + } + +};