OgarProject / Ogar

An open source Agar.io server implementation, written with Node.js.
Other
718 stars 821 forks source link

Spawn Protection #409

Open ghost opened 8 years ago

ghost commented 8 years ago

Add Spawn protection in the player, others. Like, do don't generate viruses, food, player, bot... in the player and others. For player be not generated dead, per player and spiked per virus generated in player. (Bad English!)

ghost commented 8 years ago

do you mean you do not want other entities like viruses, other players, bots spawning inside of other players or bots?

BaumanDev commented 8 years ago

Yes I assume that is what is his query about, he wants everything to spawn away from each other and not inside of each other. I kind of experience this too when my bots are big, I would spawn inside them. Also viruses spawn a little too close to you, I kind of need this too.

Andrews54757 commented 8 years ago

For viruses I assume you edit this in Gameserver.js. But how?

GameServer.prototype.virusCheck = function() {
    // Checks if there are enough viruses on the map
    if (this.nodesVirus.length < this.config.virusMinAmount) {
        // Spawns a virus
        var pos = this.getRandomPosition();
        var virusSquareSize = (this.config.virusStartMass * 100) >> 0;

        // Check for players
        for (var i = 0; i < this.nodesPlayer.length; i++) {
            var check = this.nodesPlayer[i];

            if (check.mass < this.config.virusStartMass) {
                continue;
            }

            var squareR = check.getSquareSize(); // squared Radius of checking player cell

            var dx = check.position.x - pos.x;
            var dy = check.position.y - pos.y;

            if (dx * dx + dy * dy + virusSquareSize <= squareR)
                return; // Collided
        }

        // Spawn if no cells are colliding
        var v = new Entity.Virus(this.getNextNodeId(), null, pos, this.config.virusStartMass);
        this.addNode(v);
    }
};
Luka967 commented 8 years ago

It's better to not go return;, as you still need to spawn a virus. Better call the function (use recursion) until it spawns a virus.