]>
git.r.bdr.sh - rbdr/sumo/blob - lib/factories/pixi.js
077c5b4c41187f36af8d0794d1de29df44f00d1b
1 import { Graphics
} from 'pixi.js';
4 * Factory object that contains many methods to create prefab pixi
13 * Creates a sumo container
15 * @function createSumo
16 * @memberof PixiFactory
17 * @return {external:CreateJs.Container} the created container
21 const radius
= config
.radius
;
22 const sumoColor
= config
.color
|| 0x87c5ea;
25 const body
= new Graphics();
26 body
.beginFill(sumoColor
)
27 .drawCircle(0, 0, radius
)
31 const smile
= new Graphics();
33 smile
.lineStyle(10, 0xff0080, 1)
41 const frown
= new Graphics();
43 frown
.visible
= false;
44 frown
.lineStyle(10, 0xff0080, 1)
53 const leftEye
= new Graphics();
54 leftEye
.beginFill(0xffffff)
55 .drawCircle(-radius
/ 3 - radius
/ 8, -radius
/ 4, radius
/ 5)
58 const rightEye
= new Graphics();
59 rightEye
.beginFill(0xffffff)
60 .drawCircle(radius
/ 3 + radius
/ 8, -radius
/ 4, radius
/ 5);
62 const leftPupil
= new Graphics();
63 leftPupil
.beginFill(0x11)
64 .drawCircle(-radius
/ 3 - radius
/ 8, -radius
/ 4, radius
/ 10);
66 const rightPupil
= new Graphics();
67 leftPupil
.beginFill(0x11)
68 .drawCircle(radius
/ 3 + radius
/ 8, -radius
/ 4, radius
/ 10);
70 body
.addChild(this.createBlush({ radius
}));
72 body
.addChild(this.createEffortMark({ radius
}));
73 body
.addChild(this.createShadow({ radius
}));
78 body
.addChild(leftEye
);
79 body
.addChild(rightEye
);
80 body
.addChild(leftPupil
);
81 body
.addChild(rightPupil
);
87 * Creates an empty graphic
89 * @function createEmptyGraphic
90 * @memberof PixiFactory
91 * @return {external:CreateJs.Container} the created container
93 createEmptyGraphic(config
) {
95 return new Graphics();
99 * Creates a harness graphic
101 * @function createHarness
102 * @memberof PixiFactory
103 * @return {external:CreateJs.Container} the created container
105 createHarness(config
) {
107 const radius
= config
.radius
;
109 const lineThickness
= 10;
112 const body
= new Graphics();
113 body
.lineStyle(lineThickness
, 0xe1e1e1, 1)
114 .drawCircle(0, 0, radius
);
116 const center
= new Graphics();
117 center
.beginFill(0xf1f1f1)
118 .drawCircle(0, 0, radius
- lineThickness
/ 2)
121 body
.addChild(center
);
127 * Creates an arena graphic
129 * @function createArena
130 * @memberof PixiFactory
131 * @return {external:CreateJs.Container} the created container
133 createArena(config
) {
135 const radius
= config
.radius
;
137 const lineThickness
= 20;
140 const arena
= new Graphics();
141 arena
.lineStyle(lineThickness
, 0xdfd4b2, 1)
142 .drawCircle(0, 0, radius
);
144 const leftLine
= new Graphics();
145 leftLine
.lineStyle(20, 0xbdb08b, 1)
146 .moveTo(-radius
/ 4, -radius
/ 8)
147 .lineTo(-radius
/ 4, radius
/ 8);
149 const rightLine
= new Graphics();
150 rightLine
.lineStyle(20, 0xbdb08b, 1)
151 .moveTo(radius
/ 4, -radius
/ 8)
152 .lineTo(radius
/ 4, radius
/ 8);
154 arena
.addChild(leftLine
);
155 arena
.addChild(rightLine
);
161 * Creates a blush for the face
163 * @function createBlush
164 * @memberof PixiFactory
165 * @return {external:CreateJs.Container} the created container
167 createBlush(config
) {
169 const radius
= config
.radius
;
171 const blush
= new Graphics();
173 blush
.name
= 'blush';
174 blush
.visible
= false;
176 const leftEyebrow
= new Graphics();
177 leftEyebrow
.lineStyle(4, 0x11, 1)
179 -radius
/ 3 - radius
/ 4, -radius
/ 2 - radius
/ 4,
185 const leftBlush
= new Graphics();
186 leftBlush
.lineStyle(4, 0xe7bfe6, 1)
187 .moveTo(-radius
/ 3 - radius
/ 4, radius
/ 10)
188 .lineTo(-radius
/ 3, 0);
190 const rightEyebrow
= new Graphics();
191 rightEyebrow
.lineStyle(4, 0x11, 1)
193 radius
/ 3 + radius
/ 4, -radius
/ 2 - radius
/ 4,
199 const rightBlush
= new Graphics();
200 rightBlush
.lineStyle(4, 0xe7bfe6, 1)
201 .moveTo(radius
/ 3 + radius
/ 4, radius
/ 10)
202 .lineTo(radius
/ 3, 0);
204 blush
.addChild(leftEyebrow
);
205 blush
.addChild(leftBlush
);
206 blush
.addChild(rightEyebrow
);
207 blush
.addChild(rightBlush
);
213 * Creates an effort mark
215 * @function createEffortMark
216 * @memberof PixiFactory
217 * @return {external:CreateJs.Container} the created container
219 createEffortMark(config
) {
221 const radius
= config
.radius
;
223 const effortMark
= new Graphics();
225 const centerX
= -3 * radius
/ 4;
226 const centerY
= -3 * radius
/ 4;
228 effortMark
.name
= 'effort';
229 effortMark
.visible
= false;
231 const color
= 0xff00ff;
234 const topRightArch
= new Graphics();
235 topRightArch
.lineStyle(lineWidth
, color
, 1)
237 centerX
+ 2 * radius
/ 7, centerY
- 2 * radius
/ 7,
243 const topLeftArch
= new Graphics();
244 topLeftArch
.lineStyle(lineWidth
, color
, 1)
246 centerX
- 2 * radius
/ 7, centerY
- radius
/ 4,
252 const bottomRightArch
= new Graphics();
253 bottomRightArch
.lineStyle(lineWidth
, color
, 1)
255 centerX
+ 2 * radius
/ 7, centerY
+ radius
/ 4,
261 const bottomLeftArch
= new Graphics();
262 bottomLeftArch
.lineStyle(lineWidth
, color
, 1)
264 centerX
- 2 * radius
/ 7, centerY
+ 2 * radius
/ 7,
270 effortMark
.addChild(topRightArch
);
271 effortMark
.addChild(topLeftArch
);
272 effortMark
.addChild(bottomRightArch
);
273 effortMark
.addChild(bottomLeftArch
);
279 * Creates a shadow for the eye
281 * @function createShadow
282 * @memberof PixiFactory
283 * @return {external:CreateJs.Container} the created container
285 createShadow(config
) {
287 const radius
= config
.radius
;
289 const shadow
= new Graphics();
291 const centerX
= radius
/ 2;
292 const centerY
= -3 * radius
/ 4;
294 shadow
.name
= 'shadow';
295 shadow
.visible
= false;
297 const color
= 0x9900ff;
300 shadow
.lineStyle(lineWidth
, color
, 1)
301 .moveTo(centerX
- radius
/ 4, centerY
- radius
/ 3)
302 .lineTo(centerX
- radius
/ 4, centerY
+ radius
/ 5)
303 .moveTo(centerX
- radius
/ 8, centerY
- radius
/ 4)
304 .lineTo(centerX
- radius
/ 8, centerY
+ radius
/ 5)
305 .moveTo(centerX
, centerY
- radius
/ 5)
306 .lineTo(centerX
, centerY
+ radius
/ 5)
307 .moveTo(centerX
+ radius
/ 8, centerY
- radius
/ 6)
308 .lineTo(centerX
+ radius
/ 8, centerY
+ radius
/ 6)
309 .moveTo(centerX
+ radius
/ 4, centerY
- radius
/ 5)
310 .lineTo(centerX
+ radius
/ 4, centerY
+ radius
/ 5);