Skip to content

Commit 58dfa94

Browse files
authored
Add placing capability
Read description **Uses keyboard; not likely to work on mobile** ##Notes This *will* move if you are typing in a menu, but not in an alert. Non-shifted presses will behave *unpredictably* if there are multiple pixels. Shift-hold presses will behave more predictably. Using multiple pixels is not supported. The pixel has a state of "solid" and a density of 2. It might be able to move through liquids and gases according to this density. ##Controls## WASD to move Z to shock X to explode Hold shift to repeat action Hold alt with movement keys to place the current element * It cannot place itself * You can also use Alt+H to place on the right Q to reset keys (current action, shift status, alt status) if they get stuck
1 parent dbac388 commit 58dfa94

File tree

1 file changed

+93
-15
lines changed

1 file changed

+93
-15
lines changed

mods/controllable_pixel_test.js

Lines changed: 93 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
1-
sussyKey = null,
1+
sussyKey = null;
2+
isShift = false;
3+
isAlt = false;
4+
5+
document.addEventListener("keydown", function(modifierDownListener) {
6+
// User presses shift
7+
if (modifierDownListener.keyCode == 16) {
8+
isShift = true;
9+
}
10+
// User presses alt
11+
if (modifierDownListener.keyCode == 18) {
12+
isAlt = true;
13+
}
14+
});
15+
16+
document.addEventListener("keyup", function(modifierUpListener) {
17+
// User releases shift
18+
if (modifierUpListener.keyCode == 16) {
19+
isShift = false;
20+
}
21+
// User releases alt
22+
if (modifierUpListener.keyCode == 18) {
23+
isAlt = false;
24+
}
25+
});
226

327
document.addEventListener("keyup", function(sussyListener) {
428
switch (sussyListener.keyCode) {
@@ -23,62 +47,116 @@ document.addEventListener("keyup", function(sussyListener) {
2347
case 90:
2448
sussyKey = "Z";
2549
break;
50+
case 72:
51+
sussyKey = "H";
52+
break;
2653
};
2754
});
2855

56+
function tryCreatePixel(_element,_x,_y) {
57+
if(!elements[_element]) {
58+
throw new Error("Element " + _element + " doesn't exist!");
59+
};
60+
if(isEmpty(_x,_y)) {
61+
createPixel(_element,_x,_y);
62+
return true;
63+
} else {
64+
return false;
65+
}
66+
}
67+
68+
function controllablePixelTryCreatePixelNullCheck(_element,_x,_y) {
69+
if(!elements[_element]) { //catch the null
70+
return false;
71+
};
72+
if(isEmpty(_x,_y)) {
73+
tryCreatePixel(_element,_x,_y);
74+
return true;
75+
} else {
76+
return false;
77+
}
78+
}
79+
2980
elements.controllable_pixel = {
3081
color: "#FFFFFF",
3182
colorOn: "#FFFF00",
3283
behavior: behaviors.WALL,
3384
state: "solid",
3485
density: 2000,
86+
maxSize: 1,
3587
conduct: 1,
3688
hardness: 1,
3789
tick: function(pixel) {
38-
var xx = pixel.x
39-
var yy = pixel.y
90+
var xx = pixel.x;
91+
var yy = pixel.y;
92+
userElement = currentElement;
93+
if(userElement === pixel.element) {
94+
userElement = null;
95+
};
96+
if(isShift && !isAlt) {
97+
sussyKey === "Z" ? pixel.color = "rgb(255,191,127)" : pixel.color = "rgb(255,127,127)";
98+
}
99+
if(isAlt && !isShift) {
100+
sussyKey === "Z" ? pixel.color = "rgb(191,255,127)" : pixel.color = "rgb(127,255,127)";
101+
}
102+
if(isAlt && isShift) {
103+
sussyKey === "Z" ? pixel.color = "rgb(255,255,0)" : pixel.color = "rgb(255,255,127)";
104+
}
105+
if(!isAlt && !isShift) {
106+
sussyKey === "Z" ? pixel.color = "rgb(255,255,191)" : pixel.color = "rgb(255,255,255)";
107+
}
40108
if(sussyKey !== null) {
41109
switch (sussyKey) {
42110
case "W":
43-
tryMove(pixel,xx,yy-1)
44-
if(shiftDown === 0) {
111+
isAlt ? controllablePixelTryCreatePixelNullCheck(userElement,xx,yy-1) : tryMove(pixel,xx,yy-1);
112+
if(!isShift) {
45113
sussyKey = null;
46114
}
47115
break;
48116
case "A":
49-
tryMove(pixel,xx-1,yy)
50-
if(shiftDown === 0) {
117+
isAlt ? controllablePixelTryCreatePixelNullCheck(userElement,xx-1,yy) : tryMove(pixel,xx-1,yy);
118+
if(!isShift) {
51119
sussyKey = null;
52120
}
53121
break;
54122
case "S":
55-
tryMove(pixel,xx,yy+1)
56-
if(shiftDown === 0) {
123+
isAlt ? controllablePixelTryCreatePixelNullCheck(userElement,xx,yy+1) : tryMove(pixel,xx,yy+1);
124+
if(!isShift) {
57125
sussyKey = null;
58126
}
59127
break;
60128
case "D":
61-
tryMove(pixel,xx+1,yy)
62-
if(shiftDown === 0) {
129+
tryMove(pixel,xx+1,yy);
130+
if(!isShift) {
131+
sussyKey = null;
132+
}
133+
break;
134+
case "H": //Alt+D is something else in some browsers.
135+
if(isAlt) {
136+
controllablePixelTryCreatePixelNullCheck(userElement,xx+1,yy);
137+
};
138+
if(!isShift) {
63139
sussyKey = null;
64140
}
65141
break;
66142
case "X":
67-
explodeAt(xx,yy,4)
68-
if(shiftDown === 0) {
143+
explodeAt(xx,yy,5)
144+
if(!isShift) {
69145
sussyKey = null;
70146
}
71147
break;
72148
case "Z":
73149
if (!pixel.charge && !pixel.chargeCD && !isEmpty(pixel.x,pixel.y,true)) {
74150
pixel.charge = 1;
75151
}
76-
if(shiftDown === 0) {
152+
if(!isShift === 0) {
77153
sussyKey = null;
78154
}
79155
break;
80-
case "Q":
156+
case "Q": //Use if a key gets stuck
81157
sussyKey = null;
158+
isShift = null;
159+
isAlt = null;
82160
break;
83161
}
84162
}

0 commit comments

Comments
 (0)