How to use the matter-js.Vector.create function in matter-js

To help you get started, we’ve selected a few matter-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cyclegtx / colyseus-iog-state-sync / Games / Example / Entities / Character.ts View on Github external
import { Player } from "./Player";
import { GameRoom } from "../../../IOGStateSync/GameRoom";



export class Character extends RectBodyEntity {
    @nosync
    entityInHand: PhysicsEntity = null;

    dirX: number = 0;

    @nosync
    dirY: number = 0;

    @nosync
    mousePosition: Vector = Vector.create(0, 1);

    @nosync
    mouseDistance: Vector = Vector.create(0, 0);

    @nosync
    mlb: boolean = false;

    @nosync
    mrb: boolean = false;

    @nosync
    speed: number = 1;

    @nosync
    owner: Player = null;
github cyclegtx / colyseus-iog-state-sync / IOGStateSync / Entities / Player.ts View on Github external
import { Vector} from "matter-js";
import { GameRoom } from "../GameRoom";
import { nosync, Client } from "colyseus";
import { Entity } from "./Entity";


export class Player extends Entity {
    @nosync
    dirX: number = 0;

    @nosync
    dirY: number = 0;

    @nosync
    mousePosition: Vector = Vector.create(0, 1);

    name: string = "";
    sessionId:string = null;

    @nosync
    client: Client = null;

    constructor(
        room:GameRoom,
        name:string,
        client:Client,
    ) {
        super(room,"Player",0,0,0,0);
        this.name = name;
        this.client = client;
        if(this.client){
github cyclegtx / colyseus-iog-state-sync / Games / Example / Entities / AIPlayer.ts View on Github external
import { Vector, Body, Query, Bounds, Vertices, Bodies } from "matter-js";
import { Player } from "./Player";
import { nosync } from "colyseus";
import { Character } from "./Character";
import { Crate } from "./Crate";
import { GameRoom } from "../GameRoom";


export class AIPlayer extends Player {
    @nosync
    AIAction:string = "init";

    @nosync
    dirction:Vector = Vector.create(0,0);

    @nosync
    timeSinceLastThink:number = 0;

    @nosync
    timeBetweenThink:number = 2000;

    @nosync
    targetPosition:Vector = null;


    constructor(
        room:GameRoom,
    ) {
        super(room, "BOT_" + Math.random(), null);
        this.timeSinceLastThink = this.timeBetweenThink*0.5;
github cyclegtx / colyseus-iog-state-sync / Games / Example / Entities / Character.ts View on Github external
public move(x: number, y: number) {
        let _dir = Vector.create(x, y);
        _dir = Vector.normalise(_dir);
        this.dirX = _dir.x;
        this.dirY = _dir.y;
    }
github cyclegtx / colyseus-iog-state-sync / IOGStateSync / GameRoom.ts View on Github external
rndInMap(_offset?: number): Vector {
        let offset = _offset === undefined ? 0 : _offset;
        return Vector.create(
            Math.random() * (this.mapWidth - offset) - this.mapWidth / 2,
            Math.random() * (this.mapHeight - offset) - this.mapHeight / 2,
        )
    }
github cyclegtx / colyseus-iog-state-sync / Games / Example / Entities / Crate.ts View on Github external
import { RectBodyEntity } from "../../../IOGStateSync/Entities/RectBodyEntity";
import { Body, Vector } from "matter-js";
import { nosync } from "colyseus";
import { PhysicsEntity } from "../../../IOGStateSync/Entities/PhysicsEntity";
import { Character } from "./Character";
import { GameRoom } from "../GameRoom";


export class Crate extends RectBodyEntity {
    
    @nosync
    owner:Character = null;

    offset:Vector = Vector.create(0,-16);

    delayOnRemove:number = 500;

    delayOnThrowRecover:number = 400;
    throwRecoverTime:number = 0;

    constructor(
        room:GameRoom,
        x: number,
        y: number
    ) {
        super(room, "Crate", x, y, 16, 16, { mass: 10, inertia: Infinity, frictionAir:0.3});
        this.action = "idle";
    }

    update(dt: number){
github cyclegtx / colyseus-iog-state-sync / IOGStateSync / GameRoom.ts View on Github external
rndPosition(): Vector {
        return Vector.create(
            Math.random() * 200 - 100,
            Math.random() * 200 - 100,
        )
    }
github cyclegtx / colyseus-iog-state-sync / Games / Example / Entities / Character.ts View on Github external
export class Character extends RectBodyEntity {
    @nosync
    entityInHand: PhysicsEntity = null;

    dirX: number = 0;

    @nosync
    dirY: number = 0;

    @nosync
    mousePosition: Vector = Vector.create(0, 1);

    @nosync
    mouseDistance: Vector = Vector.create(0, 0);

    @nosync
    mlb: boolean = false;

    @nosync
    mrb: boolean = false;

    @nosync
    speed: number = 1;

    @nosync
    owner: Player = null;

    score: number = 0;
    name: string = "";
    sessionId:string = null;