-
Notifications
You must be signed in to change notification settings - Fork 0
/
Packer.js
106 lines (82 loc) · 4.16 KB
/
Packer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
######## ### ###### ## ## ######## ########
## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ##
######## ## ## ## ##### ###### ########
## ######### ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ##
## ## ## ###### ## ## ######## ## ##
*/
var Packer = function() {
STAGE.removeAllChildren();
var packerHeight = 350;
var packerWidth = 600;
var roundedRadius = 100;
var numSwitches = 10;
var switchWidth = 50;
var switchHeight = 50;
var switchPositionX = 0;
var switchPositionY = 105;
var switchSpacingX = (packerWidth - (numSwitches * switchWidth + switchPositionX)) / numSwitches; //will need to change packerWidth to usable eventually
var switchPositionYlower = 220;
var numJSticks = 5;
var jStickWidth = 75;
var jStickHeight = 75;
var jStickPositionX = 0;
var jStickPositionY = 210;
var jStickSpacingX = (packerWidth - (numJSticks * jStickWidth + jStickPositionX)) / numJSticks; //same note as above for changing to usable
this.switchWidth = switchWidth; //Public Variables, needed for switches
this.switchHeight = switchHeight;
this.jStickWidth = jStickWidth;
this.jStickHeight = jStickHeight;
var packerBox = new createjs.Shape();
packerBox.graphics.setStrokeStyle(2).beginStroke("black").beginFill("orange").drawRoundRect(0, 0, packerWidth, packerHeight, roundedRadius);
var packerContainer = new createjs.Container();
packerContainer.x = 0;
packerContainer.y = 0;
packerContainer.setBounds(0, 0, packerWidth, packerHeight);
packerContainer.addChild(packerBox);
var packerSwitchArrayUpper = [];
var packerSwitchArrayLower = [];
var packerJStickArray = [];
//Creates the upper switch locations, of which 10 are possible
for (var i = 0; i < numSwitches; i++) {
var switchX = (switchSpacingX / 2) + (switchSpacingX + switchWidth) * i; //Did the divide by two, because we have 2 sides that ALSO need space.
packerSwitchArrayUpper[i] = new createjs.Shape();
packerSwitchArrayUpper[i].graphics.setStrokeStyle(2).beginStroke("black").beginFill("white").drawRect(switchX + switchPositionX, switchPositionY, switchWidth, switchHeight);
packerSwitchArrayUpper[i].setBounds(switchX + switchPositionX, switchPositionY, switchWidth, switchHeight);
packerSwitchArrayUpper[i].alpha = 0;
packerContainer.addChild(packerSwitchArrayUpper[i]);
}
//Creates the lower switch locations, of which 10 are possible
for (var i = 0; i < 10; i++) {
var switchX = (switchSpacingX / 2) + (switchSpacingX + switchWidth) * i;
packerSwitchArrayLower[i] = new createjs.Shape();
packerSwitchArrayLower[i].graphics.setStrokeStyle(2).beginStroke("black").beginFill("white").drawRect(switchX + switchPositionX, switchPositionYlower, switchWidth, switchHeight);
packerSwitchArrayLower[i].setBounds(switchX + switchPositionX, switchPositionYlower, switchWidth, switchHeight);
packerSwitchArrayLower[i].alpha = 0;
packerContainer.addChild(packerSwitchArrayLower[i]);
}
//Creates the Joystick locations, of which 5 are possible.
for (var i = 0; i < 5; i++) {
var jstickX = (jStickSpacingX / 2) + (jStickSpacingX + jStickWidth) * i;
packerJStickArray[i] = new createjs.Shape();
packerJStickArray[i].graphics.setStrokeStyle(2).beginStroke("black").beginFill("white").drawRect(jstickX + jStickPositionX, jStickPositionY, jStickWidth, jStickHeight)
packerJStickArray[i].setBounds(jstickX + jStickPositionX, jStickPositionY, jStickWidth, jStickHeight);
packerJStickArray[i].alpha = 0;
packerContainer.addChild(packerJStickArray[i]);
}
//Public Methods
this.getContainer = function() {
return packerContainer;
}
this.getSwitches = function() {
return packerSwitchArrayUpper.concat(packerSwitchArrayLower);
}
this.getJSticks = function() {
return packerJStickArray;
}
STAGE.addChild(packerContainer);
STAGE.update();
return false;
}