forked from R74nCom/sandboxels
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcpt_alt.js
241 lines (232 loc) · 7.19 KB
/
cpt_alt.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
var modName = "mods/cpt_alt.js";
var explodeAtPlusMod = "mods/explodeAtPlus.js";
var libraryMod = "mods/code_library.js";
if(enabledMods.includes(explodeAtPlusMod) && enabledMods.includes(libraryMod)) {
actExcludedElements = ["wall","alt_controllable_pixel"];
function actTryMove(pixel,x,y) {
if(!tryMove(pixel,x,y)) {
if(outOfBounds(x,y)) {
return false;
};
if(!isEmpty(x,y,true)) {
var newPixel = pixelMap[x][y];
var newElement = newPixel.element;
if(actExcludedElements.includes(newElement)) {
return false;
};
if(newElement == pixel.element) { //Copy-paste of "break" code
swapPixels(pixel,newPixel);
return true;
} else {
breakCircle(newPixel.x,newPixel.y,pixel.breakAroundRadius,false,false,false); //does nothing to elements without breakIntos if defaultBreakIntoDust is false
swapPixels(pixel,newPixel);
return true;
};
} else {
return false;
};
} else {
return true;
};
};
function cptaEapFunction(pixel,x,y,radius,fire,smoke,power,damage) {
var coords = circleCoords(pixel.x,pixel.y,radius);
for (var i = 0; i < coords.length; i++) {
var x = coords[i].x;
var y = coords[i].y;
if(isEmpty(x,y)) { //if there's space for fire
if (Array.isArray(fire)) { //this should remain "fire"
var newfire = fire[Math.floor(Math.random() * fire.length)];
} else {
var newfire = fire;
};
createPixel(newfire,x,y); //add fire
var firePixel = pixelMap[x][y];
firePixel.temp = Math.max(elements[newfire].temp,firePixel.temp);
firePixel.burning = true;
};
if(!isEmpty(x,y,true)) {
pixel.temp += (400 * ((1 + (5 * damage)) ** 2) * ((power ** 1.5) * 1.5));
pixelTempCheck(pixel);
};
if(enabledMods.includes("mods/velocity.js")) {
if (!elements[pixel.element].excludeVelocity) {
var angle = Math.atan2(pixel.y-y,pixel.x-x);
pixel.vx = Math.round((pixel.vx|0) + Math.cos(angle) * (radius * power/10));
pixel.vy = Math.round((pixel.vy|0) + Math.sin(angle) * (radius * power/10));
}
};
};
};
alt_sussyKey = null;
isShift = false;
isAlt = false;
document.addEventListener("keydown", function(modifierDownListener) {
// User presses shift
if (modifierDownListener.keyCode == 16) {
isShift = true;
}
// User presses alt
if (modifierDownListener.keyCode == 18) {
isAlt = true;
}
});
document.addEventListener("keyup", function(modifierUpListener) {
// User releases shift
if (modifierUpListener.keyCode == 16) {
isShift = false;
}
// User releases alt
if (modifierUpListener.keyCode == 18) {
isAlt = false;
}
});
document.addEventListener("keyup", function(alt_sussyListener) {
switch (alt_sussyListener.keyCode) {
case 87:
alt_sussyKey = "W";
break;
case 65:
alt_sussyKey = "A";
break;
case 83:
alt_sussyKey = "S";
break;
case 68:
alt_sussyKey = "D";
break;
case 81:
alt_sussyKey = "Q";
break;
case 88:
alt_sussyKey = "X";
break;
case 90:
alt_sussyKey = "Z";
break;
case 72:
alt_sussyKey = "H";
break;
case 76:
alt_sussyKey = "L";
break;
};
});
function controllablePixelTryCreatePixelNullCheck(element,x,y) {
if(!elements[element]) { //catch the null
return false;
};
if(isEmpty(x,y)) {
tryCreatePixel(element,x,y);
return true;
} else {
return false;
}
}
elements.alt_controllable_pixel = {
color: "#7F7F7F",
colorOn: "#FFFF00",
behavior: behaviors.WALL,
state: "solid",
density: 2000,
maxSize: 1,
conduct: 1,
hardness: 1,
movable: true,
desc: "it breaks things more<br/>Use the console or enable prop.js to set speed / explosionRadius / circleRadius / breakAroundRadius (though it has an Illogical™ random resetting bug)",
breakInto: "alt_controllable_pixel",
properties: {
speed: 1,
explosionRadius: 8,
circleRadius: 8,
breakAroundRadius: 4,
},
excludeVelocity: true,
tick: function(pixel) {
userElement = currentElement;
if(userElement === pixel.element) {
userElement = null;
};
if(isShift && !isAlt) {
alt_sussyKey === "Z" ? pixel.color = "rgb(255,191,127)" : pixel.color = "rgb(255,127,127)";
}
if(isAlt && !isShift) {
alt_sussyKey === "Z" ? pixel.color = "rgb(191,255,127)" : pixel.color = "rgb(127,255,127)";
}
if(isAlt && isShift) {
alt_sussyKey === "Z" ? pixel.color = "rgb(255,255,0)" : pixel.color = "rgb(255,255,127)";
}
if(!isAlt && !isShift) {
alt_sussyKey === "Z" ? pixel.color = "rgb(255,255,191)" : pixel.color = "rgb(255,255,255)";
}
if(alt_sussyKey !== null) {
switch (alt_sussyKey) {
case "W":
if(isAlt) { controllablePixelTryCreatePixelNullCheck(userElement,pixel.x,pixel.y-1) } else { for(move = 0; move < pixel.speed; move++) { actTryMove(pixel,pixel.x,pixel.y-1) } };
if(!isShift) {
alt_sussyKey = null;
}
break;
case "A":
if(isAlt) { controllablePixelTryCreatePixelNullCheck(userElement,pixel.x-1,pixel.y) } else { for(move = 0; move < pixel.speed; move++) { actTryMove(pixel,pixel.x-1,pixel.y) } };
if(!isShift) {
alt_sussyKey = null;
}
break;
case "S":
if(isAlt) { controllablePixelTryCreatePixelNullCheck(userElement,pixel.x,pixel.y+1) } else { for(move = 0; move < pixel.speed; move++) { actTryMove(pixel,pixel.x,pixel.y+1) } };
if(!isShift) {
alt_sussyKey = null;
}
break;
case "D":
for(move = 0; move < pixel.speed; move++) { actTryMove(pixel,pixel.x+1,pixel.y) };
if(!isShift) {
alt_sussyKey = null;
}
break;
case "H": //Alt+D is something else in some browsers.
if(isAlt) {
controllablePixelTryCreatePixelNullCheck(userElement,pixel.x+1,pixel.y);
};
if(!isShift) {
alt_sussyKey = null;
}
break;
case "X":
explodeAtPlus(pixel.x,pixel.y,pixel.explosionRadius,"plasma,fire,fire","fire,smoke,smoke",null,cptaEapFunction)
if(!isShift) {
alt_sussyKey = null;
}
break;
case "Z":
if (!pixel.charge && !pixel.chargeCD && !isEmpty(pixel.x,pixel.y,true)) {
pixel.charge = 1;
}
if(!isShift === 0) {
alt_sussyKey = null;
}
break;
case "L":
if(userElement !== null) {
fillCircle(currentElement,pixel.x,pixel.y,pixel.circleRadius,false);
if(!isShift === 0) {
alt_sussyKey = null;
}
};
break;
case "Q": //Use if a key gets stuck
alt_sussyKey = null;
isShift = null;
isAlt = null;
break;
}
}
},
}
} else {
if(!enabledMods.includes(explodeAtPlusMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,explodeAtPlusMod) };
if(!enabledMods.includes(libraryMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,libraryMod) };
alert(`The "${libraryMod}" and "${explodeAtPlusMod}" mods are required; any missing mods in this list have been automatically inserted (reload for this to take effect).`)
localStorage.setItem("enabledMods", JSON.stringify(enabledMods));
};