public override VoltShape PrepareShape(VoltWorld world)
 {
     this.shape = world.CreateCircleWorldSpace(
         this.transform.position.ToTSVector2(),
         this.radius,
         this.density);
     return(this.shape);
 }
Beispiel #2
0
        public void GenerateBody(VoltWorld world)
        {
            VoltPolygon polygon = world.CreatePolygonBodySpace(GetHitbox());

            CollisionBody = world.CreateDynamicBody(Position, Angle, polygon);
            CollisionBody.AngularVelocity = AngularVelocity;
            CollisionBody.LinearVelocity  = Velocity;
            CollisionBody.UserData        = this;
        }
 public override VoltShape PrepareShape(VoltWorld world)
 {
     Vector2[] vertices = new Vector2[this.points.Length];
     for (int i = 0; i < this.points.Length; i++)
     {
         vertices[i] = this.points[i].position;
     }
     this.shape = world.CreatePolygonWorldSpace(
         vertices,
         this.density);
     return(this.shape);
 }
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            this.hits.Clear();
            this.lastOrigin = this.transform.position.ToTSVector2();
            this.showDelay  = Time.time + 0.2f;

            VolatileWorld.Instance.World.PerformExplosion(
                this.lastOrigin,
                this.radius,
                this.ExplosionCallback,
                (body) => (body.IsStatic == false) && (body != this.body.Body),
                VoltWorld.FilterExcept(this.body.Body));
        }
    }
Beispiel #5
0
    void Awake()
    {
        VoltWorld world = VolatileWorld.Instance.World;
        IEnumerable <VoltShape> shapes = this.shapes.Select((s) => s.PrepareShape(world));

        Vector2 position = transform.position;
        float   radians  = Mathf.Deg2Rad * transform.eulerAngles.z;

        if (this.isStatic == true)
        {
            this.body = world.CreateStaticBody(position, radians, shapes.ToArray());
        }
        else
        {
            this.body = world.CreateDynamicBody(position, radians, shapes.ToArray());
        }

        this.lastPosition = this.nextPosition = transform.position;
        this.lastAngle    = this.nextAngle = transform.eulerAngles.z;
    }
Beispiel #6
0
        public AsteroidServer(NetDefinitions netdefs, Vector2 boundary, int port)
        {
            NetDefs = netdefs;

            Boundary           = boundary;
            Server             = new UDPServer(port);
            Server.Compression = NetworkCompression;
            MaxPlayers         = 8;

            OutgoingPool   = new OutgoingSyncPool(netdefs, 0);
            Physicals      = new List <Physical>();
            Projectiles    = new List <Projectile>();
            CollisionWorld = new VoltWorld(0, 1.0f);

            Clients = new List <RemoteClient>();

            Context = new ContextToken(this);

            int k = 4;

            for (int i = 0; i < 30 * k; i++)
            {
                AddEntity(NewAsteroid(32));
            }
            for (int i = 0; i < 40 * k; i++)
            {
                AddEntity(NewAsteroid(48));
            }
            for (int i = 0; i < 10 * k; i++)
            {
                AddEntity(NewAsteroid(56));
            }

            OutgoingPool.AddEntity(serverReport);

            LastTimestamp = 0;
            Random        = new Random((int)System.DateTime.UtcNow.ToBinary());
        }
Beispiel #7
0
        public void Start(RemoteConnectionToken server, bool render = true)
        {
            DoRender = render;
            _node    = new NetworkNode();
            _node.Start(false);
            _connected = _node.Connect(server);
            if (render)
            {
                _win = new RenderWindow(new VideoMode(1024, 720), "SimpleGame");
                _win.SetVerticalSyncEnabled(true);
                _win.Closed += RenderWindow_Closed;
            }
            EnvironmentAPI.Input = new SFMLInput()
            {
                _win = _win
            };
            EnvironmentAPI.Draw = new SFMLDrawApi()
            {
                _win = _win
            };
            EnvironmentAPI.Time = new SFMLTime();
            EnvironmentAPI.Win  = new SFMLWindowApi()
            {
                _win = _win
            };
            _charView        = new View();
            _physicsWorld    = new VoltWorld();
            _node.CustomData = _physicsWorld;
            var map = DefsHolder.Instance.LoadDef <MapDef>("/TestMapDef");

            _debugCreator = new LocationCreator(map.Locations[0].CreatorDef, 0);
            _debugCreator.Setup(map.Locations[0].RootSite, map.Locations[0].Pos, map.Locations[0].Rot);
            while (_debugCreator.Tick())
            {
                ;
            }
        }
Beispiel #8
0
        public bool Start(int port = 9051)
        {
            _node = new NetworkNode();
            var started = _node.Start(port, 128, true);

            if (!started)
            {
                return(false);
            }
            _sessionId = _node.Create <SessionEntity>();
            _node.Create <VisibilityEntity>();
            _node.NewConnectionEstablished += NewConnection;
            _physicsWorld    = new VoltWorld();
            _node.CustomData = _physicsWorld;
            var map = DefsHolder.Instance.LoadDef <MapDef>("/TestMapDef");

            _debugCreator = new LocationCreator(map.Locations[0].CreatorDef, 0);
            _debugCreator.Setup(map.Locations[0].RootSite, map.Locations[0].Pos, map.Locations[0].Rot);
            while (_debugCreator.Tick())
            {
                ;
            }
            return(true);
        }
Beispiel #9
0
 void Awake()
 {
     VolatileWorld.instance = this;
     this.World             = new VoltWorld(this.historyLength);
 }
 public abstract VoltShape PrepareShape(VoltWorld world);
Beispiel #11
0
 public VolatilePhysicsWorld(int historyLength = 0, int capacity = 1024)
 {
     this._world        = new VoltWorld(historyLength);
     this._entityToBody = new Dictionary <Entity, VoltBody>(capacity);
 }