From ba4dd5c4703d6a0b50acb5a560fbfb3fec60bc44 Mon Sep 17 00:00:00 2001 From: schmelczerandras Date: Tue, 13 Oct 2020 12:47:25 +0200 Subject: [PATCH] Fix bugs and add improvements --- backend/src/map/create-dungeon.ts | 6 +++--- backend/src/players/player.ts | 1 - frontend/src/scripts/game.ts | 5 +++-- frontend/src/scripts/objects/projectile-view.ts | 2 +- frontend/src/scripts/objects/stone-view.ts | 8 +++++--- frontend/src/scripts/shapes/polygon.ts | 4 ++-- shared/src/helper/{unique.ts => id.ts} | 0 shared/src/main.ts | 2 +- shared/src/settings.ts | 6 +++--- shared/src/transport/serialization/deserialize.ts | 13 ++++++++----- 10 files changed, 26 insertions(+), 21 deletions(-) rename shared/src/helper/{unique.ts => id.ts} (100%) diff --git a/backend/src/map/create-dungeon.ts b/backend/src/map/create-dungeon.ts index 46222b4..989771f 100644 --- a/backend/src/map/create-dungeon.ts +++ b/backend/src/map/create-dungeon.ts @@ -29,15 +29,15 @@ export const createDungeon = (objectContainer: PhysicalContainer) => { Random.getRandomInRange(0, height), ); } while ( - calculateDistanceField(position) < 600 || + calculateDistanceField(position) < 800 || calculateDistanceField(position) > 2000 ); objects.push( createBlob( position, - Random.getRandomInRange(200, 2000), - Random.getRandomInRange(100, 500), + Random.getRandomInRange(300, 800), + Random.getRandomInRange(300, 800), Random.getRandomInRange(10, 40), ), ); diff --git a/backend/src/players/player.ts b/backend/src/players/player.ts index 0023969..4fdcd7f 100644 --- a/backend/src/players/player.ts +++ b/backend/src/players/player.ts @@ -160,6 +160,5 @@ export class Player extends CommandReceiver { this.isActive = false; freeColor(this.character.colorIndex); this.character.destroy(); - this.objects.removeObject(this.character); } } diff --git a/frontend/src/scripts/game.ts b/frontend/src/scripts/game.ts index 218393a..3e26d16 100644 --- a/frontend/src/scripts/game.ts +++ b/frontend/src/scripts/game.ts @@ -74,7 +74,7 @@ export class Game { } private async setupRenderer(): Promise { - const noiseTexture = await renderNoise([64, 1], 20, 1 / 10); + const noiseTexture = await renderNoise([256, 256], 2, 1 / 10); this.renderer = await compile( this.canvas, @@ -123,6 +123,7 @@ export class Game { overrides: { maxFilter: FilteringOptions.LINEAR, wrapS: WrapOptions.MIRRORED_REPEAT, + wrapT: WrapOptions.MIRRORED_REPEAT, }, }, }, @@ -135,7 +136,7 @@ export class Game { } public displayToWorldCoordinates(p: vec2): vec2 { - return this.renderer.displayToWorldCoordinates(p); + return this.renderer?.displayToWorldCoordinates(p); } public aspectRatioChanged(aspectRatio: number) { diff --git a/frontend/src/scripts/objects/projectile-view.ts b/frontend/src/scripts/objects/projectile-view.ts index bb1b2d1..02aa249 100644 --- a/frontend/src/scripts/objects/projectile-view.ts +++ b/frontend/src/scripts/objects/projectile-view.ts @@ -10,7 +10,7 @@ export class ProjectileView extends ProjectileBase implements ViewObject { constructor(id: Id, center: vec2, radius: number) { super(id, center, radius); this.circle = new Circle(center, radius / 2); - this.light = new CircleLight(center, rgb(1, 0.5, 0), 0.35); + this.light = new CircleLight(center, rgb(1, 0.5, 0), 0.15); } public step(deltaTimeInMilliseconds: number): void {} diff --git a/frontend/src/scripts/objects/stone-view.ts b/frontend/src/scripts/objects/stone-view.ts index 7595e0b..56d1b32 100644 --- a/frontend/src/scripts/objects/stone-view.ts +++ b/frontend/src/scripts/objects/stone-view.ts @@ -1,6 +1,6 @@ import { vec2 } from 'gl-matrix'; import { Drawable, Renderer } from 'sdf-2d'; -import { CommandExecutors, Id, StoneBase } from 'shared'; +import { CommandExecutors, Id, Random, StoneBase } from 'shared'; import { RenderCommand } from '../commands/types/render'; import { Polygon } from '../shapes/polygon'; import { ViewObject } from './view-object'; @@ -14,10 +14,12 @@ export class StoneView extends StoneBase implements ViewObject { constructor(id: Id, vertices: Array) { super(id, vertices); - this.shape = new Polygon(vertices); + this.shape = new Polygon(vertices, Random.getRandom()); } - public step(deltaTimeInMilliseconds: number): void {} + public step(deltaTimeInMilliseconds: number): void { + this.shape.randomOffset += deltaTimeInMilliseconds / 5000; + } public draw(renderer: Renderer): void { renderer.addDrawable(this.shape); diff --git a/frontend/src/scripts/shapes/polygon.ts b/frontend/src/scripts/shapes/polygon.ts index 5ab0052..df62695 100644 --- a/frontend/src/scripts/shapes/polygon.ts +++ b/frontend/src/scripts/shapes/polygon.ts @@ -1,4 +1,4 @@ -import { PolygonFactory } from 'sdf-2d'; +import { NoisyPolygonFactory } from 'sdf-2d'; import { settings } from 'shared'; -export const Polygon = PolygonFactory(settings.polygonEdgeCount); +export const Polygon = NoisyPolygonFactory(settings.polygonEdgeCount, 1); diff --git a/shared/src/helper/unique.ts b/shared/src/helper/id.ts similarity index 100% rename from shared/src/helper/unique.ts rename to shared/src/helper/id.ts diff --git a/shared/src/main.ts b/shared/src/main.ts index f21f2c7..dcdfc00 100644 --- a/shared/src/main.ts +++ b/shared/src/main.ts @@ -24,7 +24,7 @@ export * from './helper/circle'; export * from './helper/rectangle'; export * from './helper/mix'; export * from './helper/random'; -export * from './helper/unique'; +export * from './helper/id'; export * from './helper/rotate-90-deg'; export * from './objects/game-object'; export * from './transport/serialization/deserialize'; diff --git a/shared/src/settings.ts b/shared/src/settings.ts index 5c15dc6..c933924 100644 --- a/shared/src/settings.ts +++ b/shared/src/settings.ts @@ -5,7 +5,7 @@ export const settings = { lightCutoffDistance: 600, physicsMaxStep: 5, gravitationalForce: vec2.fromValues(0, -3000), - maxVelocityX: 4800, + maxVelocityX: 2000, maxVelocityY: 3650, polygonEdgeCount: 8, projectileSpeed: 2000, @@ -46,11 +46,11 @@ export const settings = { rgb255(114, 73, 30), rgb255(75, 75, 75), ], - maxAccelerationX: 200000, + maxAccelerationX: 2000000, maxAccelerationY: 20500, targetPhysicsDeltaTimeInMilliseconds: 20, minPhysicsSleepTime: 4, - velocityAttenuation: 0.33, + velocityAttenuation: 0.1, inViewAreaSize: 1920 * 1080 * 3, defaultJumpEnergy: 0.25, }; diff --git a/shared/src/transport/serialization/deserialize.ts b/shared/src/transport/serialization/deserialize.ts index 3d9dcfb..382aad8 100644 --- a/shared/src/transport/serialization/deserialize.ts +++ b/shared/src/transport/serialization/deserialize.ts @@ -2,11 +2,14 @@ import { serializableMapping } from './serializable-mapping'; export const deserialize = (json: string): any => { return JSON.parse(json, (k, v) => { - const possibleType = v[0]; - const overridableConstructor = serializableMapping.get(possibleType); - if (overridableConstructor) { - v.shift(); - return new overridableConstructor.constructor(...v); + if (v !== null && Object.prototype.hasOwnProperty.call(v, '0')) { + const possibleType = v[0]; + const overridableConstructor = serializableMapping.get(possibleType); + if (overridableConstructor) { + v.shift(); + return new overridableConstructor.constructor(...v); + } + return v; } return v; });