Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { type } from '@colyseus/schema';
import { Types } from '@tosios/common';
import { Rectangle } from './Rectangle';
export class Prop extends Rectangle {
@type('string')
public type: Types.PropType;
@type('boolean')
public active: boolean;
// Init
constructor(type: Types.PropType, x: number, y: number, width: number, height: number) {
super(x, y, width, height);
this.type = type;
this.active = true;
}
}
import { type } from '@colyseus/schema';
import { Circle } from './Circle';
export class Bullet extends Circle {
@type('string')
public playerId: string;
@type('number')
public rotation: number;
@type('number')
public fromX: number;
@type('number')
public fromY: number;
@type('boolean')
public active: boolean;
@type('string')
public color: string;
@type('number')
public shotAt: number;
// Init
constructor(
import { Schema, type } from '@colyseus/schema';
import { Types } from '@tosios/common';
export class Game extends Schema {
@type('string')
public mapName: string;
@type('string')
public state: Types.GameState;
@type('number')
public lobbyEndsAt: number;
@type('number')
public gameEndsAt: number;
@type('number')
public maxPlayers: number;
private lobbyDuration: number;
private gameDuration: number;
// Init
constructor(
import { Schema, type } from '@colyseus/schema';
import { Room } from '../Room';
class RoomData extends Schema { // tslint:disable-line
@type('string') public id: string;
@type('string') public name: string;
@type('number') public clients: number;
@type('number') public maxClients: number;
@type('string') public metadata: string;
}
class LobbyState extends Schema { // tslint:disable-line
@type([RoomData]) public rooms: RoomData[];
}
export class LobbyRoom extends Room { // tslint:disable-line
public onCreate(options: any) {
this.setState(new LobbyState());
this.clock.setInterval(() => this.fetch(), Math.max(1, options.updateInterval || 5000) * 1000);
}
public fetch() {
import { type } from '@colyseus/schema';
import { Types } from '@tosios/common';
import { Rectangle } from './Rectangle';
export class Prop extends Rectangle {
@type('string')
public type: Types.PropType;
@type('boolean')
public active: boolean;
// Init
constructor(type: Types.PropType, x: number, y: number, width: number, height: number) {
super(x, y, width, height);
this.type = type;
this.active = true;
}
}
import { Room } from "../src";
import { Schema, type } from "@colyseus/schema";
class Message extends Schema {
@type("string") str;
@type("number") num;
}
class State extends Schema {
@type("string")
lastMessage: string = "";
}
export class DummyRoom extends Room {
maxClients = 4;
onCreate (options) {
console.log("CREATE ROOM WITH OPTIONS", options);
this.setMetadata({ password: true });
this.setState(new State());
}
import { ArraySchema, MapSchema, Schema, type } from '@colyseus/schema';
import { Collisions, Constants, Entities, Geometry, Maps, Maths, Tiled, Types } from '@tosios/common';
import { Bullet, Game, Message, Player, Prop } from '../entities';
export class GameState extends Schema {
@type(Game)
public game: Game;
@type({ map: Player })
public players: MapSchema = new MapSchema();
@type([Prop])
public props: ArraySchema = new ArraySchema();
@type([Bullet])
public bullets: ArraySchema = new ArraySchema();
private map: Entities.Map;
private walls: Collisions.TreeCollider;
private spawners: Geometry.RectangleBody[] = [];
private actions: Types.IAction[] = [];
private onMessage: (message: Message) => void;
Logger.error('Player not found! ID: '+id);
} else {
this.players[id].state.mov = false;
this.players[id].state.x = data.x;
this.players[id].state.y = data.y;
}
}
removePlayer(id)
{
delete this.players[id];
}
}
type('string')(State.prototype, 'sceneData');
type({ map: Player })(State.prototype, 'players');
module.exports.State = State;
import { Room, Delayed, Client } from 'colyseus';
import { type, Schema, MapSchema, ArraySchema } from '@colyseus/schema';
const TURN_TIMEOUT = 10
const BOARD_WIDTH = 3;
class State extends Schema {
@type("string") currentTurn: string;
@type({ map: "string" }) players = new MapSchema();
@type(["number"]) board: number[] = new ArraySchema(0, 0, 0, 0, 0, 0, 0, 0, 0);
@type("string") winner: string;
@type("boolean") draw: boolean;
}
export class TicTacToe extends Room {
maxClients = 2;
randomMoveTimeout: Delayed;
onCreate () {
this.setState(new State())
}
onJoin (client: Client) {
this.state.players[client.sessionId] = client.sessionId;
this.room_id = data.room_id;
this.scene = data.scene;
this.x = parseFloat(data.x);
this.y = parseFloat(data.y);
this.dir = data.dir;
this.mov = false;
}
}
type('number')(PlayerState.prototype, 'room_id');
type('string')(PlayerState.prototype, 'scene');
type('number')(PlayerState.prototype, 'x');
type('number')(PlayerState.prototype, 'y');
type('string')(PlayerState.prototype, 'dir');
type('boolean')(PlayerState.prototype, 'mov');
module.exports.PlayerState = PlayerState;