Improve world creation

This commit is contained in:
schmelczerandras 2020-10-22 21:48:13 +02:00
parent dee72440bb
commit dd21c20b3a
5 changed files with 57 additions and 65 deletions

View file

@ -5,4 +5,5 @@ export const defaultOptions: Options = {
name: 'Localhost',
playerLimit: 16,
seed: 51,
worldSize: 10000,
};

View file

@ -26,7 +26,7 @@ export class GameServer {
this.serverName = options.name;
this.playerLimit = options.playerLimit;
createWorld(this.objects);
createWorld(this.objects, options.worldSize);
this.objects.initialize();
io.on('connection', (socket: SocketIO.Socket) => {

View file

@ -1,73 +1,65 @@
import { vec2, vec3 } from 'gl-matrix';
import { Random, settings, PlanetBase, hsl } from 'shared';
import { vec2 } from 'gl-matrix';
import { Random, PlanetBase, hsl, settings } from 'shared';
import { LampPhysical } from '../objects/lamp-physical';
import { PlanetPhysical } from '../objects/planet-physical';
import { PhysicalContainer } from '../physics/containers/physical-container';
import { evaluateSdf } from '../physics/functions/evaluate-sdf';
import { Physical } from '../physics/physicals/physical';
export const createWorld = (objectContainer: PhysicalContainer) => {
export const createWorld = (objectContainer: PhysicalContainer, worldRadius: number) => {
const objects: Array<Physical> = [];
const lights: Array<Physical> = [];
const worldSize = vec2.length(
vec2.fromValues(
settings.worldTopEdge - settings.worldBottomEdge,
settings.worldRightEdge - settings.worldLeftEdge,
),
for (let r = 0; r < worldRadius; r += settings.radiusSteps) {
const circumference = 2 * Math.PI * r;
const stepCount = circumference * settings.objectsOnCircleLength;
for (let rad = 0; rad < 2 * Math.PI; rad += (2 * Math.PI) / stepCount) {
const position = vec2.rotate(
vec2.create(),
vec2.fromValues(r, 0),
vec2.create(),
rad,
);
for (let i = 0; i < 15; i++) {
console.log('planet', i);
let position: vec2;
do {
position = vec2.fromValues(
Random.getRandomInRange(settings.worldLeftEdge, settings.worldRightEdge),
Random.getRandomInRange(settings.worldBottomEdge, settings.worldTopEdge),
);
} while (
evaluateSdf(position, objects) < 800 ||
evaluateSdf(position, objects) > 2500
);
objects.push(
new PlanetPhysical(
PlanetBase.createPlanetVertices(
position,
Random.getRandomInRange(300, 800),
Random.getRandomInRange(300, 800),
Random.getRandomInRange(20, 40),
),
),
);
}
for (let i = 0; i < 15; i++) {
console.log('light', i);
let position: vec2;
do {
position = vec2.fromValues(
Random.getRandomInRange(settings.worldLeftEdge, settings.worldRightEdge),
Random.getRandomInRange(settings.worldBottomEdge, settings.worldTopEdge),
);
} while (
evaluateSdf(position, objects) < 200 ||
lights.find((l) => l.distance(position) < 1500)
);
if (Random.getRandom() > 0.5) {
if (
evaluateSdf(position, objects) > 200 &&
!lights.find((l) => l.distance(position) < 2500)
) {
lights.push(
new LampPhysical(
position,
hsl(
Random.getRandomInRange(0, 360),
(rad / (2 * Math.PI)) * 360,
Random.getRandomInRange(50, 100),
Random.getRandomInRange(25, 50),
Random.getRandomInRange(40, 50),
),
Random.getRandomInRange(0.5, 2),
Random.getRandomInRange(0.35, 1),
),
);
}
} else {
if (
evaluateSdf(position, objects) > 1400 &&
!lights.find((l) => l.distance(position) < 1700)
) {
objects.push(
new PlanetPhysical(
PlanetBase.createPlanetVertices(
position,
Random.getRandomInRange(300, 1600),
Random.getRandomInRange(300, 1600),
Random.getRandomInRange(20, 100),
),
),
);
}
}
}
}
console.log('Generated planet count', objects.length);
console.log('Generated light count', lights.length);
[...objects, ...lights].forEach((o) => objectContainer.addObject(o));
};

View file

@ -3,4 +3,5 @@ export interface Options {
name: string;
playerLimit: number;
seed: number;
worldSize: number;
}

View file

@ -11,8 +11,10 @@ export const settings = {
physicsMaxStep: 2,
maxVelocityX: 1000,
maxVelocityY: 1000,
radiusSteps: 500,
objectsOnCircleLength: 0.002,
planetEdgeCount: 7,
takeControlTimeInSeconds: 10,
takeControlTimeInSeconds: 4,
maxGravityDistance: 700,
maxGravityQ: 180,
planetControlThreshold: 0.2,
@ -27,13 +29,9 @@ export const settings = {
projectileMaxBounceCount: 1,
projectileTimeout: 3,
projectileFadeSpeed: 20,
projectileStartOffset: 150,
projectileCreationInterval: 0.1,
playerColorIndexOffset: 3,
worldTopEdge: 3000,
worldRightEdge: 3000,
worldLeftEdge: -3000,
worldBottomEdge: -3000,
worldRadius: 10000,
backgroundGradient: [rgb255(90, 38, 43), rgb255(43, 39, 73)],
declaColor,
declaPlanetColor,