landgreen / n-gon

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

Update level: tlinat #56

Closed Whyisthisnotavalable closed 1 year ago

Whyisthisnotavalable commented 1 year ago
tlinat() { // _Destined_ formerly Richard0820#2652
    simulation.fallHeight = 1 / 0, level.setPosToSpawn(0, -1e3), level.exit.x = 5100, level.exit.y = 3770, spawn.mapRect(level.enter.x, level.enter.y + 20, 100, 20), spawn.mapRect(level.exit.x, level.exit.y + 20, 100, 20), level.defaultZoom = 3000, simulation.zoomTransition(level.defaultZoom), document.body.style.backgroundColor = "#d8dadf";
    let e = 0,
        t = 0;
    const boidsFlocking = function (mob, otherMobs) {
        const cohesionFactor = 0.01;
        const separationFactor = 0.0001;
        const alignmentFactor = 0.04;
        let averagePosition = { x: 0, y: 0 };
        let averageVelocity = { x: 0, y: 0 };
        let nearbyMobsCount = 0;
        for (const otherMob of otherMobs) {
            if (otherMob !== mob) {
                const distanceSquared = Vector.magnitudeSquared(Vector.sub(mob.position, otherMob.position));
                const boidRangeSquared = 300 * 300; // Adjust boid range as needed
                if (distanceSquared < boidRangeSquared) {
                    averagePosition = Vector.add(averagePosition, otherMob.position);
                    averageVelocity = Vector.add(averageVelocity, otherMob.velocity);
                    nearbyMobsCount++;
                }
            }
        }
        if (nearbyMobsCount > 0) {
            averagePosition = Vector.div(averagePosition, nearbyMobsCount);
            averageVelocity = Vector.div(averageVelocity, nearbyMobsCount);
            const cohesionForce = Vector.mult(Vector.sub(averagePosition, mob.position), cohesionFactor);
            mob.force = Vector.add(mob.force, cohesionForce);
            const separationForce = Vector.mult(Vector.sub(mob.position, averagePosition), separationFactor);
            mob.force = Vector.add(mob.force, separationForce);
            const alignmentForce = Vector.mult(Vector.sub(averageVelocity, mob.velocity), alignmentFactor);
            mob.force = Vector.add(mob.force, alignmentForce);
        }
    };            
    function ghoster(x, y, radius = 50 + Math.ceil(Math.random() * 90)) {
        mobs.spawn(x, y, 7, radius, "transparent");
        let me = mob[mob.length - 1];
        me.seeAtDistance2 = 300000;
        me.accelMag = 0.00004 + 0.00015 * simulation.accelScale;
        if (map.length) me.searchTarget = map[Math.floor(Math.random() * (map.length - 1))].position; //required for search
        // Matter.Body.setDensity(me, 0.0015); //normal is 0.001
        me.damageReduction = 0.5
        me.stroke = "transparent"; //used for drawGhost
        me.alpha = 1; //used in drawGhost
        me.isNotCloaked = false; //used in drawGhost
        me.isBadTarget = true;
        // me.leaveBody = false;
        me.collisionFilter.mask = cat.bullet //| cat.body
        me.showHealthBar = false;
        me.memory = 600;
        me.do = function () {
            boidsFlocking(me, mob);//Stack, increase power.
            if (this.speed > 7) {
                Matter.Body.setVelocity(this, {
                    x: this.velocity.x * 0.8,
                    y: this.velocity.y * 0.8
                });
            }
            this.seePlayerCheckByDistance();
            this.checkStatus();
            this.attraction();
            this.search();
            //draw
            if (this.distanceToPlayer2() < this.seeAtDistance2) {
                if (this.alpha < 1) this.alpha += 0.011 * simulation.CDScale; //near player go solid
            } else {
                if (this.alpha > 0) this.alpha -= 0.05; ///away from player, hide
            }
            if (this.alpha > 0) {
                if (this.alpha > 0.7 && this.seePlayer.recall) {
                    this.healthBar();
                    if (!this.isNotCloaked) {
                        this.isNotCloaked = true;
                        this.isBadTarget = false;
                        this.collisionFilter.mask = cat.player | cat.bullet
                    }
                }
                //draw body
                ctx.beginPath();
                const vertices = this.vertices;
                ctx.moveTo(vertices[0].x, vertices[0].y);
                for (let j = 1, len = vertices.length; j < len; ++j) {
                    ctx.lineTo(vertices[j].x, vertices[j].y);
                }
                ctx.lineTo(vertices[0].x, vertices[0].y);
                // ctx.lineWidth = 1;
                ctx.fillStyle = `rgba(255,255,255,${this.alpha * this.alpha})`;
                ctx.fill();
            } else if (this.isNotCloaked) {
                this.isNotCloaked = false;
                this.isBadTarget = true;
                this.collisionFilter.mask = cat.bullet; //can't touch player or walls
            }
        };
    }        
    function o(e, t, o) {
        const l = {
                J: [" #### ", "    # ", "    # ", "    # ", " #  # ", " #  # ", "  ##  "],
                I: ["  #  ", "  #  ", "  #  ", "  #  ", "  #  ", "  #  ", "  #  "],
                N: [" #  # ", " ## # ", " ## # ", " # ## ", " # ## ", " #  # ", " #  # "],
                " ": ["      ", "      ", "      ", "      ", "      ", "      ", "      "],
                O: ["   ##   ", "  #  #  ", " #    # ", " #    # ", " #    # ", "  #  #  ", "   ##   "],
                U: [" #   # ", " #   # ", " #   # ", " #   # ", " #   # ", " #   # ", "  ###  "],
                R: [" #### ", " #   #", " #### ", " # #  ", " #  # ", " #   #", " #   #"],
                D: [" ###   ", " #  ## ", " #   # ", " #   # ", " #   # ", " #  ## ", " ###   "],
                S: ["  #### ", " #     ", " #     ", "  ###  ", "    ## ", "     # ", " ##### "],
                C: [" ##### ", " #     ", " #     ", " #     ", " #     ", " #     ", " ##### "],
                V: [" #   # ", " #   # ", " #   # ", " #   # ", " #   # ", "  # #  ", "   #   "],
                E: [" ##### ", " #     ", " #     ", " ##### ", " #     ", " #     ", " ##### "],
                ".": ["       ", "       ", "       ", "       ", "       ", "   ##  ", "   ##  "],
                "/": ["      #", "     # ", "    #  ", "   #   ", "  #    ", " #     ", "#      "],
                G: [" ###### ", " #      ", " #      ", " #  ### ", " #    # ", " #    # ", " ###### "],
                Q: ["  ######   ", " #      #  ", " #      #  ", " #      #  ", " #    # #  ", "  #    #   ", "   #### #  ", "         # "],
                8: ["  #####  ", " #     # ", " #     # ", "  #####  ", " #     # ", " #     # ", "  #####  "],
                g: ["  #####  ", " #     # ", " #     # ", "  #####  ", "       # ", "       # ", " ######  "],
                Y: [" #     # ", "  #   #  ", "   # #   ", "    #    ", "    #    ", "    #    ", "    #    "],
                4: [" #       ", " #    #  ", " #    #  ", " #    #  ", "  ###### ", "      #  ", "      #  "],
                W: [" #     # ", " #     # ", " #     # ", " #  #  # ", " # # # # ", " ##   ## ", " #     # "],
                e: ["  ######  ", " #      # ", " #      # ", " #######  ", " #        ", "  #       ", "  ######  "],
                c: [" ###### ","#       ","#       ","#       ","#       ","#       "," ###### ","        "],
                m: [" #       ", " ### ### ", " #  #  # ", " #  #  # ", " #  #  # ", " #  #  # ", " #  #  # "]
            },
            a = (e, t) => {
                ctx.fillStyle = "black", ctx.fillRect(e, t, 50, 50)
            },
            n = (e, t, o) => {
                const n = l[e];
                if (n)
                    for (let e = 0; e < n.length; e++) {
                        const l = n[e];
                        for (let n = 0; n < l.length; n++) {
                            if ("#" === l[n]) {
                                a(t + 20 * n, o + 20 * e)
                            }
                        }
                    }
            };
        for (let l = 0; l < o.length; l++) {
            n(o[l], e + 250 * l - Math.abs(1.5 * e), t)
        }
    }
    simulation.makeTextLog(`<img src="https://raw.githubusercontent.com/Whyisthisnotavalable/image-yy/main/Hotpot-removed.png" width="100" height="100" style="background-image: radial-gradient(circle, gray, black, transparent)"><br>Look up<br><em>Walk right to tp to maze</em><br><b>Exit is at the bottom left</b>`), Matter.Body.scale(player.parts[3], 2, 2), level.custom = () => {
            if (level.exit.drawAndCheck(), level.enter.draw(), player.position.y > 1e5 && Matter.Body.setPosition(player, {
                    x: 5100,
                    y: -5925
                }), player.position.x > 2500 && 0 == e) {
                Matter.Body.setPosition(player, {
                    x: 5100,
                    y: -5925
                }), e++;
                for (let e = 0; e < map.length; e++) Math.random() < .75 && ghoster(map[e].position.x, map[e].position.y);
                simulation.makeTextLog("Watch out for <b>ghosters</b><br>Peace ✌️")
            }
            player.position.x > level.exit.x && player.position.x < level.exit.x + 100 && player.position.y > level.exit.y - 150 && player.position.y < level.exit.y - 0 && player.velocity.y < .15 && 0 == t && (t++, Matter.Body.scale(player.parts[3], .5, .5))
        }, level.customTopLayer = () => {
            player.position.x > -1200 && player.position.x < 4500 && (o(2e3, -3e3, "JOIN OUR DISCORD SERVER"), o(1500, -2700, "DISCORD.GG/Q8gY4WeUcm"))
        }, spawn.mapRect(-1e3, -950, 5950, 100), spawn.mapRect(-1325, -3450, 100, 2575), spawn.mapRect(-1325, -950, 350, 100), spawn.mapRect(4850, -3400, 100, 2550), spawn.mapRect(-1325, -3450, 6275, 100),
        function(e, t, o, l, a) {
            const n = o / a,
                s = l / a,
                i = e - o / 2,
                p = t - l / 2,
                r = [];
            for (let e = 0; e < a; e++) {
                r[e] = [];
                for (let t = 0; t < a; t++) r[e][t] = 1
            }
            const c = [];
            (function e(t, o) {
                r[t][o] = 0;
                const l = [{
                    dx: 0,
                    dy: -1
                }, {
                    dx: 1,
                    dy: 0
                }, {
                    dx: 0,
                    dy: 1
                }, {
                    dx: -1,
                    dy: 0
                }];
                l.sort((() => Math.random() - .5));
                for (const n of l) {
                    const l = t + 2 * n.dx,
                        s = o + 2 * n.dy;
                    l >= 0 && l < a && s >= 0 && s < a && 1 === r[l][s] && (r[t + n.dx][o + n.dy] = 0, r[l][s] = 0, c.push({
                        x: t + n.dx,
                        y: o + n.dy
                    }), e(l, s))
                }
            })(0, 0), r[a - 1][a - 1] = 1;
            for (let e = -1; e < a + 1; e++) {
                let t = -1,
                    o = -1;
                for (let l = -1; l < a + 1; l++)
                    if (e >= 0 && e < a && l >= 0 && l < a && 1 === r[e][l]) - 1 === t && (t = l), o = l;
                    else if (-1 !== t) {
                    const l = i + e * n,
                        a = p + t * s,
                        r = n,
                        c = (o - t + 1) * s;
                    c !== s && spawn.mapRect(l, a, r, c), t = -1, o = -1
                }
            }
            for (let e = -1; e < a + 1; e++) {
                let t = -1,
                    o = -1;
                for (let l = -1; l < a + 1; l++)
                    if (l >= 0 && l < a && e >= 0 && e < a && 1 === r[l][e]) - 1 === t && (t = l), o = l;
                    else if (-1 !== t) {
                    const l = i + t * n,
                        a = p + e * s,
                        r = (o - t + 1) * n,
                        c = s;
                    r !== n && spawn.mapRect(l, a, r, c), t = -1, o = -1
                }
            }
            spawn.mapRect(i - n, p - s, n * a, s), spawn.mapRect(i - n, p - s, n, s * a), spawn.mapRect(i + (a - 1) * n, p - s, n, s * (a + 1)), spawn.mapRect(i - n, p + (a - 1) * s, n * (a + 1), s)
        }(1e4, -1e3, 1e4, 1e4, 50);    
},//Join us at: https://discord.gg/Q8gY4WeUcm
Whyisthisnotavalable commented 1 year ago

Removed QR code and replaced it with a link.

landgreen commented 1 year ago

I ran this level and got this error as I walked to the right

Uncaught TypeError: this.boidsFlocking is not a function at me.do (level.js:26104:22) at Object.loop (mob.js:9:26) at Object.normalLoop (simulation.js:23:37) at cycle (index.js:1886:20)

Whyisthisnotavalable commented 1 year ago

Apologies, it should work now.

landgreen commented 1 year ago

ok