Esempio n. 1
0
        private PhyObject CreateSphere(SphereState state)
        {
            var sphere = new Sphere(state.radius);
            CollidableDescription collidableDescription = new CollidableDescription(Simulation.Shapes.Add(sphere), 0.1f);
            BodyInertia           bodyInertia;

            sphere.ComputeInertia(state.mass, out bodyInertia);

            var phy = CreateVanilla(state, collidableDescription, bodyInertia);

            return(phy);
        }
Esempio n. 2
0
        private void CreateBall()
        {
            SphereState ball = new SphereState();

            ball.radius      = 3;
            ball.position    = state.position + new Vector3(0, 0, 100);
            ball.quaternion  = Quaternion.Identity;
            ball.type        = "GolfBall2";
            ball.mass        = 1;
            ball.instantiate = true;
            ball.owner       = state.owner;
            ball.mesh        = "Objects/Balls/Vanilla/Vanilla";

            golfball = (GolfBall2)simulator.Create(ball);
        }
Esempio n. 3
0
        internal void createObjects()
        {
            int width   = 10;
            int sizeObj = 60;

            for (int a = 0; a < boxToCreate; a++)
            {
                var box = new SphereState();
                box.uID  = PhyObject.createUID();
                box.uID += "" + a;
                box.mass = 10;
                box.type = "Bomb";
                // box.instantiate = false;

                int x = a % width;    // % is the "modulo operator", the remainder of i / width;
                int y = a / width;    // where "/" is an integer division
                box.position    = new Vector3(x * sizeObj, 1050 + (timesPressedCreateBoxes * sizeObj), y * sizeObj);
                box.radius      = 10;
                box.mesh        = "Board/Bomb";
                box.instantiate = true;
                box.quaternion  = Quaternion.Identity;
                var b = Create(box);

                /* int x = a % width;    // % is the "modulo operator", the remainder of i / width;
                 * int y = a / width;    // where "/" is an integer division
                 * var ringBoxShape = new Box(1, 1, 1);
                 * ringBoxShape.ComputeInertia(1, out var ringBoxInertia);
                 * var boxDescription = BodyDescription.CreateDynamic(new Vector3(), ringBoxInertia,
                 *                new CollidableDescription(Simulation.Shapes.Add(ringBoxShape), 0.1f),
                 *                new BodyActivityDescription(0.01f));
                 * new BodyActivityDescription(0.01f);
                 *
                 * boxDescription.Pose = new RigidPose(new Vector3(x,300,y), Quaternion.Identity);
                 * Simulation.Bodies.Add(boxDescription);*/
            }
            timesPressedCreateBoxes++;
            // Console.WriteLine("Statics size " + Simulation.Statics.Count);
        }
Esempio n. 4
0
        internal void ReadCommand()
        {
            //Console.WriteLine("Read command: {0}", v);

            try
            {
                foreach (var item in commandsList)
                {
                    JsonSerializerSettings setting = new JsonSerializerSettings();
                    setting.CheckAdditionalContent = false;

                    Newtonsoft.Json.Linq.JObject message = JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>((string)item, setting);
                    string type = (string)message["type"];
                    switch (type)
                    {
                    case "create":

                        // Console.WriteLine(message);

                        if (message["data"]["halfSize"] != null)
                        {
                            BoxState ob = JsonConvert.DeserializeObject <BoxState>(((object)message["data"]).ToString());
                            simulator.Create(ob);
                        }

                        if (message["data"]["radius"] != null)
                        {
                            SphereState ob = JsonConvert.DeserializeObject <SphereState>(((object)message["data"]).ToString());
                            simulator.Create(ob);
                            break;
                        }

                        break;

                    case "createBoxes":
                        //Console.WriteLine("Create boxes");
                        // simulator.boxToCreate = 10;
                        simulator.createObjects();
                        break;

                    case "gauntlet":

                        UseGauntlet(((object)message["data"]).ToString());
                        break;

                    case "move":

                        MoveMessage j = JsonConvert.DeserializeObject <MoveMessage>(((object)message["data"]).ToString());
                        //objects[]
                        Player2 onb = (Player2)simulator.users[j.client].player;
                        // Simulation.Awakener.AwakenBody(ob.bodyHandle);
                        onb.Move(j);

                        break;

                    case "rotate":
                        MoveMessage j2 = JsonConvert.DeserializeObject <MoveMessage>(((object)message["data"]).ToString());
                        //objects[]
                        Player2 onb2 = (Player2)simulator.users[j2.client].player;
                        // Simulation.Awakener.AwakenBody(ob.bodyHandle);
                        onb2.Rotate(j2);
                        break;

                    case "jump":
                        Jump(((object)message["data"]).ToString());
                        break;

                    case "shoot":
                        Shoot(((object)message["data"]).ToString());
                        break;

                    case "swipe":
                        Swipe(((object)message["data"]).ToString());
                        break;

                    case "generateMap":

                        var map = this.simulator.server.dataBase.GetMap((string)message["data"]);
                        this.simulator.map = map;

                        foreach (var obj in map.objects)
                        {
                            //obj.ToJson();
                            if (obj.Contains("halfSize"))
                            {
                                obj["halfSize"].AsBsonDocument.Remove("__refId");
                                obj.Remove("_id");
                                var stri = JsonConvert.DeserializeObject <BoxState>(obj.ToJson());
                                stri.quaternion = JsonConvert.DeserializeObject <Quaternion>(obj["quat"].ToJson());

                                this.simulator.Create(stri);
                            }
                            if (obj.Contains("radius"))
                            {
                                // obj["radius"].AsBsonDocument.Remove("__refId");
                                obj.Remove("_id");
                                var stri = JsonConvert.DeserializeObject <SphereState>(obj.ToJson());
                                stri.quaternion = JsonConvert.DeserializeObject <Quaternion>(obj["quat"].ToJson());

                                this.simulator.Create(stri);
                            }
                        }
                        break;

                    case "close":
                        //Console.WriteLine("Close");
                        simulator.Close();

                        break;

                    default:
                        QuixConsole.WriteLine("Command not registred " + type);
                        break;
                    }
                }

                commandsList.Clear();
            }
            catch (InvalidOperationException e)
            {
                QuixConsole.Log("Collection was modifieded", e);
            }
            catch (JsonReaderException e)
            {
                QuixConsole.Log("Json Problem ", e);
            }
            catch (Exception e) {
                QuixConsole.WriteLine(e);
            }
        }