landgreen / n-gon

2-d physics rogue-lite platformer shooter
https://landgreen.github.io/n-gon/
GNU General Public License v3.0
162 stars 234 forks source link

need help with construct mode #344

Closed c-rxxp-y closed 3 weeks ago

c-rxxp-y commented 3 weeks ago

currently starting a modded fork of n-gon, and I'm trying to add testing and construct mode by default without having to "beat" the game normally. testing was easy, I just set localSettings.loreCount = 1 on game loop, but when construct mode is activated on testing-loop start it doesn't work properly. mainly, the white output box does appear, but when drawing or using different key commands nothing happens. (maybe I'm just making an easy mistake or smth, my JavaScript isnt that great yet, I'm using this as a project to get better)

const simulation = {
    loop() { }, //main game loop, gets set to normal or testing loop
    normalLoop() {
        simulation.enableConstructMode();
        localSettings.loreCount = 1;
        try {
            simulation.gravity();
            Engine.update(engine, simulation.delta);
            simulation.wipe();
            simulation.textLog();
            if (m.onGround) {
                m.groundControl()
            } else {
                m.airControl()
            }
            m.move();
            m.look();
            simulation.camera();
            level.custom();
            powerUps.do();
            mobs.draw();
            simulation.draw.cons();
            simulation.draw.body();
            if (!m.isBodiesAsle) mobs.loop();
            mobs.healthBar();
            m.draw();
            m.hold();
            level.customTopLayer();
            simulation.draw.drawMapPath();
            b.fire();
            b.bulletRemove();
            b.bulletDraw();
            if (!m.isBodiesAsleep) b.bulletDo();
            simulation.drawCircle();
            simulation.runEphemera();
            simulation.constructCycle()
            ctx.restore();
        } catch (error) {
            simulation.inGameConsole(`<strong style='color:red;'>ERROR:</strong> ${(error.stack && error.stack.replace(/\n/g, "<br>")) || (error.message + ` <u>${error.filename}:${error.lineno}</u>`)}`);
        } finally {
            simulation.enableConstructMode();
            simulation.drawCursor();
        }
    },
    testingLoop() {
        try {
            simulation.gravity();
            Engine.update(engine, simulation.delta);
            simulation.wipe();
            simulation.textLog();
            if (m.onGround) {
                m.groundControl()
            } else {
                m.airControl()
            }
            m.move();
            m.look();
            simulation.camera();
            level.custom();
            m.draw();
            m.hold();
            level.customTopLayer();
            simulation.draw.wireFrame();
            if (input.fire && m.fireCDcycle < m.cycle) {
                m.fireCDcycle = m.cycle + 15; //fire cooldown       
                for (let i = 0, len = mob.length; i < len; i++) {
                    if (Vector.magnitudeSquared(Vector.sub(mob[i].position, simulation.mouseInGame)) < mob[i].radius * mob[i].radius) {
                        console.log(mob[i])
                    }
                }
            }
            simulation.draw.cons();
            simulation.draw.testing();
            simulation.drawCircle();
            simulation.runEphemera();
            simulation.constructCycle()
        } catch (error) {
            simulation.inGameConsole(`<strong style='color:red;'>ERROR:</strong> ${(error.stack && error.stack.replace(/\n/g, "<br>")) || (error.message + ` <u>${error.filename}:${error.lineno}</u>`)}`);
        } finally {
            ctx.restore();
            simulation.enableConstructMode();
            simulation.testingOutput();
            simulation.drawCursor();
        }
    },
3xionDev commented 3 weeks ago

it might be because you're always enabling construct mode and never letting it be used? personally, I would change the <body> tag to <body onload="simulation.enableConstructMode()">

c-rxxp-y commented 3 weeks ago

okay I'll try that, thank you (also ur mod is fun btw :D

3xionDev commented 3 weeks ago

thank

c-rxxp-y commented 3 weeks ago

yup it worked, also moved loreCount to as well. fixed some lag lol

3xionDev commented 3 weeks ago

yup it worked, also moved loreCount to as well. fixed some lag lol

I think you can just do

<body onload="lore.unlockTesting()" onload="simulation.enableConstructMode()">

to make it even more efficient, as loreCount tends to reset with browser storage. you don't have to, though

c-rxxp-y commented 3 weeks ago

if it fixes the browser reset then I will