An online multiplay experience where you explore randomly generated worlds in search of supplies used to craft items for you and your base to help you survive the nights from waves of zombies.
npm install
cp packages/dashboard/.env.example packages/dashboard/.env
npm run dev
see Spike.ts for a good example of a server entity using ECS.
- Create an entity class and put it somewhere intelligent in the game-server/src/shared/entities directory
- Add the entity to the
EntityFactory
in theclient
package.
Extensions are a core part of our Entity Component System (ECS) that add specific behaviors to entities. Here's how to create one:
- Create an extension class in the
game-server/src/shared/extensions
directory - Add the extension to the
extensionsMap
ingame-server/src/shared/extensions/index.ts
file
Here's an example of how to create an extension that makes entities burst into flames when destroyed:
import { Extension, ExtensionNames, ExtensionSerialized } from "./types";
import { Positionable } from "./index";
import { Entity } from "../entities";
import { EntityType } from "../entity-types";
export default class Combustible implements Extension {
// Define a unique name for the extension
public static readonly Name = ExtensionNames.combustible;
// required
private self: Entity;
// only used on this example
private entityFactory: EntityFactory;
// SERIALIZED PROPERTIES
private numFires: number;
private spreadRadius: number;
// Constructor receives the entity this extension is attached to
public constructor(
self: Entity,
entityFactory: EntityFactory,
numFires = 3,
spreadRadius = 32
) {
this.self = self;
this.entityFactory = entityFactory;
this.numFires = numFires;
this.spreadRadius = spreadRadius;
}
public update() {
// if an extension has an update method, it'll be invoked each server tick
}
public deserialize(data: ExtensionSerialized): this {
// this is invoked client side; if you have properties you want to sync between clients and server, you can deserialize them here
return this;
}
public serialize(): ExtensionSerialized {
// this is invoked server side; if you have properties you want to sync between clients and server, you can serialize them here
return {
type: Combustible.type,
numFires: this.numFires,
spreadRadius: this.spreadRadius,
};
}
}
To use this extension on an entity:
// In your entity class
import Combustible from "../extensions/combustible";
class ExplodingZombie extends Entity {
constructor() {
super();
this.addExtension(new Combustible(this, entityFactory));
}
}
Final Setup
- Add the extension to
extensionsMap
ingame-server/src/shared/extensions/index.ts
- Add the extension to
ExtensionNames
ingame-server/src/shared/extensions/types.ts
Key points when creating extensions:
- Implement
serialize
anddeserialize
methods for network synchronization - Extensions can interact with other extensions through the parent entity