r/coolmathgames • u/NetherWarlock1 • 20d ago
Console Cheat Panel for Big Tower Tiny Square (CMG version)
I wanted to share this because I thought some of you might be interested in it, essentially it's a console command which creates a panel that gives you cheats (noclip, extra speed, etc). I wanted it to be just one long console command to make it easy to use. Hope you guys enjoy and feel free to tinker around with it and make something cool and new from it.
(function () {
var proto = cr.behaviors.Platform.prototype.Instance.prototype;
var rt = cr_getC2Runtime();
var setCollisions = cr.plugins_.Sprite.prototype.acts.SetCollisions;
// if i run this twice, clean up the first copy
var oldPanel = document.getElementById("mm_panel");
if (oldPanel) oldPanel.remove();
if (proto._origPosttick) proto.posttick = proto._origPosttick;
else proto._origPosttick = proto.posttick;
var realPosttick = proto._origPosttick;
var on = { jump: false, noclip: false };
var over = { speed: null, acc: null, dec: null }; // null = leave the game's value alone
var keys = { up: false, down: false };
var playerOnly = false;
// every object that has the platform behavior
function getPlatformers() {
var list = [];
rt.types_by_index.forEach(function (type) {
(type.instances || []).forEach(function (inst) {
(inst.behavior_insts || []).forEach(function (beh) {
if (typeof beh.maxspeed === "number" && beh.jumpStrength !== undefined) {
list.push({ inst: inst, beh: beh });
}
});
});
});
return list;
}
// the player is whatever uses default controls, if nothing does just grab them all
function updatePlayerOnly() {
playerOnly = getPlatformers().some(function (p) { return p.beh.defaultControls; });
}
function isPlayer(beh) {
return !playerOnly || beh.defaultControls;
}
updatePlayerOnly();
var firstOne = getPlatformers().filter(function (p) { return isPlayer(p.beh); })[0];
var defaults = {
speed: firstOne ? firstOne.beh.maxspeed : 425,
acc: firstOne ? firstOne.beh.acc : 1500,
dec: firstOne ? firstOne.beh.dec : 1500
};
// wrap the behavior's per-frame update
proto.posttick = function () {
if (!isPlayer(this)) return realPosttick.apply(this, arguments);
if (over.speed !== null) this.maxspeed = over.speed;
if (over.acc !== null) this.acc = over.acc;
if (over.dec !== null) this.dec = over.dec;
if (on.jump) {
this.enableDoubleJump = true;
// only refill the double jump once the key is let go, otherwise you just fly
if (!this.jumpkey && !this.simjump) this.doubleJumped = false;
}
if (on.noclip) {
if (this.inst.collisionsEnabled) setCollisions.call(this.inst, 0);
var savedGravity = this.g;
this.g = 0;
this.dy = 0;
this.jumpkey = false;
this.simjump = false;
var dir = (keys.up ? -1 : 0) + (keys.down ? 1 : 0);
if (dir !== 0) {
var dt = this.runtime.getDt(this.inst);
this.inst.y += dir * this.maxspeed * dt;
this.inst.set_bbox_changed();
}
var result = realPosttick.apply(this, arguments);
this.g = savedGravity;
this.dy = 0;
return result;
}
return realPosttick.apply(this, arguments);
};
// up/down tracking for noclip (arrows + w/s)
function track(e, isDown) {
var code = e.keyCode;
if (code === 38 || code === 87) keys.up = isDown;
if (code === 40 || code === 83) keys.down = isDown;
}
window.addEventListener("keydown", function (e) { track(e, true); }, true);
window.addEventListener("keyup", function (e) { track(e, false); }, true);
window.addEventListener("blur", function () { keys.up = keys.down = false; });
// ---- ui ----
var panel = document.createElement("div");
panel.id = "mm_panel";
panel.style.cssText =
"position:fixed;top:8px;left:8px;z-index:2147483647;background:rgba(0,0,0,.75);" +
"padding:8px;border-radius:8px;font:13px sans-serif;color:#fff;" +
"display:flex;flex-direction:column;gap:6px;user-select:none";
function makeButton(text, onClick) {
var el = document.createElement("button");
el.textContent = text;
el.tabIndex = -1;
el.style.cssText = "padding:5px 10px;border:0;border-radius:5px;cursor:pointer;background:#444;color:#fff";
// stops the button stealing focus from the game
el.addEventListener("mousedown", function (e) { e.preventDefault(); });
el.addEventListener("click", function () { onClick(el); el.blur(); });
return el;
}
function setToggleLook(el, name, state) {
el.textContent = name + ": " + (state ? "ON" : "OFF");
el.style.background = state ? "#2a8a3a" : "#444";
}
// one row with - / label / + / reset
function makeRow(key, prop, name, step) {
var label = document.createElement("div");
label.style.cssText = "min-width:92px;text-align:center";
function current() {
if (over[key] !== null) return over[key];
var p = getPlatformers().filter(function (q) { return isPlayer(q.beh); })[0];
return p ? p.beh[prop] : defaults[key];
}
function refresh() {
label.textContent = name + ": " + Math.round(current());
}
function change(val) {
over[key] = Math.max(0, val);
updatePlayerOnly();
refresh();
}
var row = document.createElement("div");
row.style.cssText = "display:flex;gap:4px;align-items:center";
row.appendChild(makeButton("-", function () { change(current() - step); }));
row.appendChild(label);
row.appendChild(makeButton("+", function () { change(current() + step); }));
row.appendChild(makeButton("Reset", function () { change(defaults[key]); }));
refresh();
return row;
}
panel.appendChild(makeRow("speed", "maxspeed", "Speed", 50));
panel.appendChild(makeRow("acc", "acc", "Accel", 250));
panel.appendChild(makeRow("dec", "dec", "Decel", 250));
var jumpBtn = makeButton("", function (el) {
on.jump = !on.jump;
updatePlayerOnly();
setToggleLook(el, "Infinite jump", on.jump);
});
setToggleLook(jumpBtn, "Infinite jump", false);
panel.appendChild(jumpBtn);
var noclipBtn = makeButton("", function (el) {
on.noclip = !on.noclip;
updatePlayerOnly();
if (!on.noclip) {
// turn collisions back on so you don't fall forever
getPlatformers().forEach(function (p) {
if (isPlayer(p.beh) && !p.inst.collisionsEnabled) setCollisions.call(p.inst, 1);
});
}
setToggleLook(el, "Noclip", on.noclip);
});
setToggleLook(noclipBtn, "Noclip", false);
panel.appendChild(noclipBtn);
document.body.appendChild(panel);
})();
"loaded";
1
u/D_sYT 20d ago
we love construct