]> git.r.bdr.sh - rbdr/sumo/blame - lib/factories/pixi.js
Add control via keyboard (#6)
[rbdr/sumo] / lib / factories / pixi.js
CommitLineData
0616b3f0
RBR
1import { Graphics } from 'pixi.js';
2
3/**
4 * Factory object that contains many methods to create prefab pixi
5 * objects
6 *
7 * @type object
8 * @name PixiFactory
9 */
10export default {
11
12 /**
13 * Creates a sumo container
14 *
15 * @function createSumo
16 * @memberof PixiFactory
17 * @return {external:CreateJs.Container} the created container
18 */
493ec31c 19 createSumo(config) {
0616b3f0 20
493ec31c 21 const radius = config.radius;
0616b3f0
RBR
22
23 // The body
24 const body = new Graphics();
25 body.beginFill(0x87c5ea)
26 .drawCircle(0, 0, radius)
27 .endFill();
28
29 // The mouth
30 const mouth = new Graphics();
31 mouth.lineStyle(10, 0xff0080, 1)
32 .arc(
33 0, 0, // center
34 radius * 0.6,
35 Math.PI / 6,
36 5 * Math.PI / 6
37 );
38
39 const leftEye = new Graphics();
40 leftEye.beginFill(0xffffff)
41 .drawCircle(-radius / 3 - radius / 8, -radius / 4, radius / 5)
42 .endFill();
43
44 const rightEye = new Graphics();
45 rightEye.beginFill(0xffffff)
46 .drawCircle(radius / 3 + radius / 8, -radius / 4, radius / 5);
47
48 const leftPupil = new Graphics();
49 leftPupil.beginFill(0x11)
50 .drawCircle(-radius / 3 - radius / 8, -radius / 4, radius / 10);
51
52 const rightPupil = new Graphics();
53 leftPupil.beginFill(0x11)
54 .drawCircle(radius / 3 + radius / 8, -radius / 4, radius / 10);
55
56 // The group
57 body.addChild(mouth);
58 body.addChild(leftEye);
59 body.addChild(rightEye);
60 body.addChild(leftPupil);
61 body.addChild(rightPupil);
62
63 return body;
493ec31c
RBR
64 },
65
66 /**
67 * Creates an empty graphic
68 *
69 * @function createEmptyGraphic
70 * @memberof PixiFactory
71 * @return {external:CreateJs.Container} the created container
72 */
73 createEmptyGraphic(config) {
74
75 return new Graphics();
7ade6f8d
RBR
76 },
77
78 /**
79 * Creates a harness graphic
80 *
81 * @function createHarness
82 * @memberof PixiFactory
83 * @return {external:CreateJs.Container} the created container
84 */
85 createHarness(config) {
86
87 const radius = config.radius;
88
89 const lineThickness = 10;
90
91 // The body
92 const body = new Graphics();
93 body.lineStyle(lineThickness, 0xe1e1e1, 1)
94 .drawCircle(0, 0, radius);
95
96 const center = new Graphics();
97 center.beginFill(0xf1f1f1)
98 .drawCircle(0, 0, radius - lineThickness / 2)
99 .endFill();
100
101 body.addChild(center);
102
103 return body;
0616b3f0
RBR
104 }
105};
106