Improve world creation
This commit is contained in:
parent
dee72440bb
commit
dd21c20b3a
5 changed files with 57 additions and 65 deletions
|
|
@ -5,4 +5,5 @@ export const defaultOptions: Options = {
|
||||||
name: 'Localhost',
|
name: 'Localhost',
|
||||||
playerLimit: 16,
|
playerLimit: 16,
|
||||||
seed: 51,
|
seed: 51,
|
||||||
|
worldSize: 10000,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export class GameServer {
|
||||||
this.serverName = options.name;
|
this.serverName = options.name;
|
||||||
this.playerLimit = options.playerLimit;
|
this.playerLimit = options.playerLimit;
|
||||||
|
|
||||||
createWorld(this.objects);
|
createWorld(this.objects, options.worldSize);
|
||||||
this.objects.initialize();
|
this.objects.initialize();
|
||||||
|
|
||||||
io.on('connection', (socket: SocketIO.Socket) => {
|
io.on('connection', (socket: SocketIO.Socket) => {
|
||||||
|
|
|
||||||
|
|
@ -1,73 +1,65 @@
|
||||||
import { vec2, vec3 } from 'gl-matrix';
|
import { vec2 } from 'gl-matrix';
|
||||||
import { Random, settings, PlanetBase, hsl } from 'shared';
|
import { Random, PlanetBase, hsl, settings } from 'shared';
|
||||||
import { LampPhysical } from '../objects/lamp-physical';
|
import { LampPhysical } from '../objects/lamp-physical';
|
||||||
|
|
||||||
import { PlanetPhysical } from '../objects/planet-physical';
|
import { PlanetPhysical } from '../objects/planet-physical';
|
||||||
import { PhysicalContainer } from '../physics/containers/physical-container';
|
import { PhysicalContainer } from '../physics/containers/physical-container';
|
||||||
import { evaluateSdf } from '../physics/functions/evaluate-sdf';
|
import { evaluateSdf } from '../physics/functions/evaluate-sdf';
|
||||||
import { Physical } from '../physics/physicals/physical';
|
import { Physical } from '../physics/physicals/physical';
|
||||||
|
|
||||||
export const createWorld = (objectContainer: PhysicalContainer) => {
|
export const createWorld = (objectContainer: PhysicalContainer, worldRadius: number) => {
|
||||||
const objects: Array<Physical> = [];
|
const objects: Array<Physical> = [];
|
||||||
const lights: Array<Physical> = [];
|
const lights: Array<Physical> = [];
|
||||||
|
|
||||||
const worldSize = vec2.length(
|
for (let r = 0; r < worldRadius; r += settings.radiusSteps) {
|
||||||
vec2.fromValues(
|
const circumference = 2 * Math.PI * r;
|
||||||
settings.worldTopEdge - settings.worldBottomEdge,
|
const stepCount = circumference * settings.objectsOnCircleLength;
|
||||||
settings.worldRightEdge - settings.worldLeftEdge,
|
for (let rad = 0; rad < 2 * Math.PI; rad += (2 * Math.PI) / stepCount) {
|
||||||
),
|
const position = vec2.rotate(
|
||||||
);
|
vec2.create(),
|
||||||
|
vec2.fromValues(r, 0),
|
||||||
for (let i = 0; i < 15; i++) {
|
vec2.create(),
|
||||||
console.log('planet', i);
|
rad,
|
||||||
|
|
||||||
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(
|
if (Random.getRandom() > 0.5) {
|
||||||
new PlanetPhysical(
|
if (
|
||||||
PlanetBase.createPlanetVertices(
|
evaluateSdf(position, objects) > 200 &&
|
||||||
position,
|
!lights.find((l) => l.distance(position) < 2500)
|
||||||
Random.getRandomInRange(300, 800),
|
) {
|
||||||
Random.getRandomInRange(300, 800),
|
lights.push(
|
||||||
Random.getRandomInRange(20, 40),
|
new LampPhysical(
|
||||||
),
|
position,
|
||||||
),
|
hsl(
|
||||||
);
|
(rad / (2 * Math.PI)) * 360,
|
||||||
}
|
Random.getRandomInRange(50, 100),
|
||||||
|
Random.getRandomInRange(40, 50),
|
||||||
for (let i = 0; i < 15; i++) {
|
),
|
||||||
console.log('light', i);
|
Random.getRandomInRange(0.35, 1),
|
||||||
let position: vec2;
|
),
|
||||||
do {
|
);
|
||||||
position = vec2.fromValues(
|
}
|
||||||
Random.getRandomInRange(settings.worldLeftEdge, settings.worldRightEdge),
|
} else {
|
||||||
Random.getRandomInRange(settings.worldBottomEdge, settings.worldTopEdge),
|
if (
|
||||||
);
|
evaluateSdf(position, objects) > 1400 &&
|
||||||
} while (
|
!lights.find((l) => l.distance(position) < 1700)
|
||||||
evaluateSdf(position, objects) < 200 ||
|
) {
|
||||||
lights.find((l) => l.distance(position) < 1500)
|
objects.push(
|
||||||
);
|
new PlanetPhysical(
|
||||||
lights.push(
|
PlanetBase.createPlanetVertices(
|
||||||
new LampPhysical(
|
position,
|
||||||
position,
|
Random.getRandomInRange(300, 1600),
|
||||||
hsl(
|
Random.getRandomInRange(300, 1600),
|
||||||
Random.getRandomInRange(0, 360),
|
Random.getRandomInRange(20, 100),
|
||||||
Random.getRandomInRange(50, 100),
|
),
|
||||||
Random.getRandomInRange(25, 50),
|
),
|
||||||
),
|
);
|
||||||
Random.getRandomInRange(0.5, 2),
|
}
|
||||||
),
|
}
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
console.log('Generated planet count', objects.length);
|
||||||
|
console.log('Generated light count', lights.length);
|
||||||
|
|
||||||
[...objects, ...lights].forEach((o) => objectContainer.addObject(o));
|
[...objects, ...lights].forEach((o) => objectContainer.addObject(o));
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,5 @@ export interface Options {
|
||||||
name: string;
|
name: string;
|
||||||
playerLimit: number;
|
playerLimit: number;
|
||||||
seed: number;
|
seed: number;
|
||||||
|
worldSize: number;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,10 @@ export const settings = {
|
||||||
physicsMaxStep: 2,
|
physicsMaxStep: 2,
|
||||||
maxVelocityX: 1000,
|
maxVelocityX: 1000,
|
||||||
maxVelocityY: 1000,
|
maxVelocityY: 1000,
|
||||||
|
radiusSteps: 500,
|
||||||
|
objectsOnCircleLength: 0.002,
|
||||||
planetEdgeCount: 7,
|
planetEdgeCount: 7,
|
||||||
takeControlTimeInSeconds: 10,
|
takeControlTimeInSeconds: 4,
|
||||||
maxGravityDistance: 700,
|
maxGravityDistance: 700,
|
||||||
maxGravityQ: 180,
|
maxGravityQ: 180,
|
||||||
planetControlThreshold: 0.2,
|
planetControlThreshold: 0.2,
|
||||||
|
|
@ -27,13 +29,9 @@ export const settings = {
|
||||||
projectileMaxBounceCount: 1,
|
projectileMaxBounceCount: 1,
|
||||||
projectileTimeout: 3,
|
projectileTimeout: 3,
|
||||||
projectileFadeSpeed: 20,
|
projectileFadeSpeed: 20,
|
||||||
projectileStartOffset: 150,
|
|
||||||
projectileCreationInterval: 0.1,
|
projectileCreationInterval: 0.1,
|
||||||
playerColorIndexOffset: 3,
|
playerColorIndexOffset: 3,
|
||||||
worldTopEdge: 3000,
|
worldRadius: 10000,
|
||||||
worldRightEdge: 3000,
|
|
||||||
worldLeftEdge: -3000,
|
|
||||||
worldBottomEdge: -3000,
|
|
||||||
backgroundGradient: [rgb255(90, 38, 43), rgb255(43, 39, 73)],
|
backgroundGradient: [rgb255(90, 38, 43), rgb255(43, 39, 73)],
|
||||||
declaColor,
|
declaColor,
|
||||||
declaPlanetColor,
|
declaPlanetColor,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue