Exemplo n.º 1
0
    //发生碰撞,赋给玩家
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Tank"))
        {
            Item item = null;
            switch (itemType)
            {
            case ItemType.Wrench:
                item = new Wrench();
                break;

            case ItemType.Timer:
                item = new Timer();
                break;

            case ItemType.Shileld:
                item = new Shileld();
                break;

            case ItemType.OilBottle:
                item = new OilBottle();
                break;

            case ItemType.Missle:
                item = new Missle();
                break;
            }

            other.gameObject.GetComponent <Tank>().item = item;
            Destroy(gameObject);
        }
    }
Exemplo n.º 2
0
        public void reset()
        {
            lock ( mutex_ )
            {
                propulsion_model_.x.Initialize();
                propulsion_model_.x_pred.Initialize();
                propulsion_model_.u.Initialize();
                propulsion_model_.y.Initialize();

                wrench_ = new Wrench();

                motor_status_           = new MotorStatus();
                motor_status_.voltage   = new float[4];
                motor_status_.frequency = new float[4];
                motor_status_.current   = new float[4];

                supply_            = new Supply();
                supply_.voltage    = new float[1];
                supply_.voltage[0] = (float)initial_voltage_;

                last_command_time_ = ROS.GetTime();

                command_queue_ = new Queue <MotorPWM> ();
            }
        }
		public Wrench limit (Wrench input)
		{
			Wrench output = new Wrench ();
			output.force = force.limit ( input.force );
			output.torque = torque.limit ( input.torque );
			return output;
		}
Exemplo n.º 4
0
        static void Main()
        {
            Worker W1 = new Worker("W1", Enums.WorkerStatus.WAITING);
            Worker W2 = new Worker("W2", Enums.WorkerStatus.WAITING);
            Worker W3 = new Worker("W3", Enums.WorkerStatus.WAITING);
            Worker W4 = new Worker("W4", Enums.WorkerStatus.WAITING);

            Screwdriver Scr1 = new Screwdriver("Scr1", Enums.ToolStatus.FREE);
            Screwdriver Scr2 = new Screwdriver("Scr2", Enums.ToolStatus.FREE);
            Wrench      Wrc1 = new Wrench("Wrc1", Enums.ToolStatus.FREE);
            Wrench      Wrc2 = new Wrench("Wrc2", Enums.ToolStatus.FREE);

            InitializeWorkers(W1, W2, W3, W4, Wrc1, Scr1, Wrc2, Scr2);

            Thread w1 = new Thread(W1.Waiting);
            Thread w2 = new Thread(W2.Waiting);
            Thread w3 = new Thread(W3.Waiting);
            Thread w4 = new Thread(W4.Waiting);

            w1.Start();
            w2.Start();
            w3.Start();
            w4.Start();

            W1.Speak();
            W2.Speak();
            W3.Speak();
            W4.Speak();
        }
Exemplo n.º 5
0
 private void OnTriggerStay(Collider other)
 {//hand layer can only interact with tool layer
     if (!b_IstoolInRange)
     {
         toolInRange     = other.GetComponent <Wrench>();
         b_IstoolInRange = true;
     }
 }
Exemplo n.º 6
0
        //  optional duration of wrench application time (seconds)
        //  if duration < 0, apply wrench continuously without end
        //  if duration = 0, do nothing
        //  if duration < step size, apply wrench
        //  for one step size

        public ApplyBodyWrenchRequest()
        {
            this.body_name       = "";
            this.reference_frame = "";
            this.reference_point = new Point();
            this.wrench          = new Wrench();
            this.start_time      = new Time();
            this.duration        = new Duration();
        }
Exemplo n.º 7
0
 public ApplyBodyWrenchRequest(string body_name, string reference_frame, Point reference_point, Wrench wrench, Time start_time, Duration duration)
 {
     this.body_name       = body_name;
     this.reference_frame = reference_frame;
     this.reference_point = reference_point;
     this.wrench          = wrench;
     this.start_time      = start_time;
     this.duration        = duration;
 }
Exemplo n.º 8
0
        public Wrench RefPoint(Vector v_base_AB)
        {
            Wrench ret = new Wrench(kdlPINVOKE.Wrench_RefPoint(swigCPtr, Vector.getCPtr(v_base_AB)), true);

            if (kdlPINVOKE.SWIGPendingException.Pending)
            {
                throw kdlPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Exemplo n.º 9
0
        public static Wrench Zero()
        {
            Wrench ret = new Wrench(kdlPINVOKE.Wrench_Zero(), true);

            if (kdlPINVOKE.SWIGPendingException.Pending)
            {
                throw kdlPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Exemplo n.º 10
0
        public Wrench Inverse(Wrench arg)
        {
            Wrench ret = new Wrench(kdlPINVOKE.Rotation_Inverse__SWIG_2(swigCPtr, Wrench.getCPtr(arg)), true);

            if (kdlPINVOKE.SWIGPendingException.Pending)
            {
                throw kdlPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Exemplo n.º 11
0
 public ContactState(string info, string collision1_name, string collision2_name, Wrench[] wrenches, Wrench total_wrench, Vector3[] contact_positions, Vector3[] contact_normals, double[] depths)
 {
     this.info              = info;
     this.collision1_name   = collision1_name;
     this.collision2_name   = collision2_name;
     this.wrenches          = wrenches;
     this.total_wrench      = total_wrench;
     this.contact_positions = contact_positions;
     this.contact_normals   = contact_normals;
     this.depths            = depths;
 }
Exemplo n.º 12
0
        //  list of penetration depths

        public ContactState()
        {
            this.info              = "";
            this.collision1_name   = "";
            this.collision2_name   = "";
            this.wrenches          = new Wrench[0];
            this.total_wrench      = new Wrench();
            this.contact_positions = new Vector3[0];
            this.contact_normals   = new Vector3[0];
            this.depths            = new double[0];
        }
        public void reset()
        {
            lock ( mutex_ )
            {
                drag_model_.u.Initialize();
                drag_model_.y.Initialize();

                twist_  = new Twist();
                wind_   = new Vector3();
                wrench_ = new Wrench();
            }
        }
Exemplo n.º 14
0
    public void SendWrench(UnityEngine.Vector3 force, UnityEngine.Vector3 torque)
    {
        if (!init)
        {
            return;
        }

        Wrench wrench = new Wrench();

        wrench.force  = new Messages.geometry_msgs.Vector3(force.ToRos());
        wrench.torque = new Messages.geometry_msgs.Vector3(torque.ToRos());

        wrenchPub.publish(wrench);
    }
Exemplo n.º 15
0
 /// <summary>
 /// Detach Attached tool
 /// </summary>
 void DetachTool()
 {
     toolInRange = attachedTool;
     attachedTool.OnScrewLock            -= LockToScrew;
     attachedTool.m_Rigidbody.isKinematic = false;
     attachedTool.transform.parent        = null;
     attachedTool.lockedWrenchHead        = null;
     attachedTool.lockedScrew             = null;
     attachedTool       = null;
     transform.rotation = Quaternion.identity;
     MouseInputHandler.instance.b_LockPointerHeight = false;
     MouseInputHandler.instance.pointerHeight       = basePlaneheight;
     animator.SetBool("Hold", false);
 }
Exemplo n.º 16
0
            public override void Randomize()
            {
                int    arraylength = -1;
                Random rand        = new Random();
                int    strlength;

                byte[] strbuf, myByte;

                //body_name
                strlength = rand.Next(100) + 1;
                strbuf    = new byte[strlength];
                rand.NextBytes(strbuf);  //fill the whole buffer with random bytes
                for (int __x__ = 0; __x__ < strlength; __x__++)
                {
                    if (strbuf[__x__] == 0) //replace null chars with non-null random ones
                    {
                        strbuf[__x__] = (byte)(rand.Next(254) + 1);
                    }
                }
                strbuf[strlength - 1] = 0; //null terminate
                body_name             = Encoding.ASCII.GetString(strbuf);
                //reference_frame
                strlength = rand.Next(100) + 1;
                strbuf    = new byte[strlength];
                rand.NextBytes(strbuf);  //fill the whole buffer with random bytes
                for (int __x__ = 0; __x__ < strlength; __x__++)
                {
                    if (strbuf[__x__] == 0) //replace null chars with non-null random ones
                    {
                        strbuf[__x__] = (byte)(rand.Next(254) + 1);
                    }
                }
                strbuf[strlength - 1] = 0; //null terminate
                reference_frame       = Encoding.ASCII.GetString(strbuf);
                //reference_point
                reference_point = new Point();
                reference_point.Randomize();
                //wrench
                wrench = new Wrench();
                wrench.Randomize();
                //start_time
                start_time = new Time(new TimeData(
                                          Convert.ToUInt32(rand.Next()),
                                          Convert.ToUInt32(rand.Next())));
                //duration
                duration = new Duration(new TimeData(
                                            Convert.ToUInt32(rand.Next()),
                                            Convert.ToUInt32(rand.Next())));
            }
Exemplo n.º 17
0
        public override byte[] Serialize(bool partofsomethingelse)
        {
            int  currentIndex = 0, length = 0;
            bool hasmetacomponents = false;

            byte[]        thischunk, scratch1, scratch2;
            List <byte[]> pieces = new List <byte[]>();
            GCHandle      h;

            //header
            if (header == null)
            {
                header = new Header();
            }
            pieces.Add(header.Serialize(true));
            //pose
            if (pose == null)
            {
                pose = new Pose();
            }
            pieces.Add(pose.Serialize(true));
            //twist
            if (twist == null)
            {
                twist = new Twist();
            }
            pieces.Add(twist.Serialize(true));
            //wrench
            if (wrench == null)
            {
                wrench = new Wrench();
            }
            pieces.Add(wrench.Serialize(true));
            //combine every array in pieces into one array and return it
            int __a_b__f = pieces.Sum((__a_b__c) => __a_b__c.Length);
            int __a_b__e = 0;

            byte[] __a_b__d = new byte[__a_b__f];
            foreach (var __p__ in pieces)
            {
                Array.Copy(__p__, 0, __a_b__d, __a_b__e, __p__.Length);
                __a_b__e += __p__.Length;
            }
            return(__a_b__d);
        }
Exemplo n.º 18
0
        public override void Deserialize(byte[] SERIALIZEDSTUFF, ref int currentIndex)
        {
            int    arraylength       = -1;
            bool   hasmetacomponents = false;
            object __thing;
            int    piecesize = 0;

            byte[] thischunk, scratch1, scratch2;
            IntPtr h;

            //header
            header = new Header(SERIALIZEDSTUFF, ref currentIndex);
            //pose
            pose = new Pose(SERIALIZEDSTUFF, ref currentIndex);
            //twist
            twist = new Twist(SERIALIZEDSTUFF, ref currentIndex);
            //wrench
            wrench = new Wrench(SERIALIZEDSTUFF, ref currentIndex);
        }
Exemplo n.º 19
0
        public override void Randomize()
        {
            int    arraylength = -1;
            Random rand        = new Random();
            int    strlength;

            byte[] strbuf, myByte;

            //header
            header = new Header();
            header.Randomize();
            //pose
            pose = new Pose();
            pose.Randomize();
            //twist
            twist = new Twist();
            twist.Randomize();
            //wrench
            wrench = new Wrench();
            wrench.Randomize();
        }
Exemplo n.º 20
0
            public override void Deserialize(byte[] SERIALIZEDSTUFF, ref int currentIndex)
            {
                int  arraylength       = -1;
                bool hasmetacomponents = false;

                byte[] thischunk, scratch1, scratch2;
                object __thing;
                int    piecesize = 0;
                IntPtr h;

                //body_name
                body_name     = "";
                piecesize     = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
                currentIndex += 4;
                body_name     = Encoding.ASCII.GetString(SERIALIZEDSTUFF, currentIndex, piecesize);
                currentIndex += piecesize;
                //reference_frame
                reference_frame = "";
                piecesize       = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
                currentIndex   += 4;
                reference_frame = Encoding.ASCII.GetString(SERIALIZEDSTUFF, currentIndex, piecesize);
                currentIndex   += piecesize;
                //reference_point
                reference_point = new Point(SERIALIZEDSTUFF, ref currentIndex);
                //wrench
                wrench = new Wrench(SERIALIZEDSTUFF, ref currentIndex);
                //start_time
                start_time = new Time(new TimeData(
                                          BitConverter.ToUInt32(SERIALIZEDSTUFF, currentIndex),
                                          BitConverter.ToUInt32(SERIALIZEDSTUFF, currentIndex + Marshal.SizeOf(typeof(System.Int32)))));
                currentIndex += 2 * Marshal.SizeOf(typeof(System.Int32));
                //duration
                duration = new Duration(new TimeData(
                                            BitConverter.ToUInt32(SERIALIZEDSTUFF, currentIndex),
                                            BitConverter.ToUInt32(SERIALIZEDSTUFF, currentIndex + Marshal.SizeOf(typeof(System.Int32)))));
                currentIndex += 2 * Marshal.SizeOf(typeof(System.Int32));
            }
Exemplo n.º 21
0
            public override byte[] Serialize(bool partofsomethingelse)
            {
                int  currentIndex = 0, length = 0;
                bool hasmetacomponents = false;

                byte[]        thischunk, scratch1, scratch2;
                List <byte[]> pieces = new List <byte[]>();
                GCHandle      h;

                //body_name
                if (body_name == null)
                {
                    body_name = "";
                }
                scratch1  = Encoding.ASCII.GetBytes((string)body_name);
                thischunk = new byte[scratch1.Length + 4];
                scratch2  = BitConverter.GetBytes(scratch1.Length);
                Array.Copy(scratch1, 0, thischunk, 4, scratch1.Length);
                Array.Copy(scratch2, thischunk, 4);
                pieces.Add(thischunk);
                //reference_frame
                if (reference_frame == null)
                {
                    reference_frame = "";
                }
                scratch1  = Encoding.ASCII.GetBytes((string)reference_frame);
                thischunk = new byte[scratch1.Length + 4];
                scratch2  = BitConverter.GetBytes(scratch1.Length);
                Array.Copy(scratch1, 0, thischunk, 4, scratch1.Length);
                Array.Copy(scratch2, thischunk, 4);
                pieces.Add(thischunk);
                //reference_point
                if (reference_point == null)
                {
                    reference_point = new Point();
                }
                pieces.Add(reference_point.Serialize(true));
                //wrench
                if (wrench == null)
                {
                    wrench = new Wrench();
                }
                pieces.Add(wrench.Serialize(true));
                //start_time
                pieces.Add(BitConverter.GetBytes(start_time.data.sec));
                pieces.Add(BitConverter.GetBytes(start_time.data.nsec));
                //duration
                pieces.Add(BitConverter.GetBytes(duration.data.sec));
                pieces.Add(BitConverter.GetBytes(duration.data.nsec));
                //combine every array in pieces into one array and return it
                int __a_b__f = pieces.Sum((__a_b__c) => __a_b__c.Length);
                int __a_b__e = 0;

                byte[] __a_b__d = new byte[__a_b__f];
                foreach (var __p__ in pieces)
                {
                    Array.Copy(__p__, 0, __a_b__d, __a_b__e, __p__.Length);
                    __a_b__e += __p__.Length;
                }
                return(__a_b__d);
            }
        public override byte[] Serialize(bool partofsomethingelse)
        {
            int  currentIndex = 0, length = 0;
            bool hasmetacomponents = false;

            byte[]        thischunk, scratch1, scratch2;
            List <byte[]> pieces = new List <byte[]>();
            GCHandle      h;

            //info
            if (info == null)
            {
                info = "";
            }
            scratch1  = Encoding.ASCII.GetBytes((string)info);
            thischunk = new byte[scratch1.Length + 4];
            scratch2  = BitConverter.GetBytes(scratch1.Length);
            Array.Copy(scratch1, 0, thischunk, 4, scratch1.Length);
            Array.Copy(scratch2, thischunk, 4);
            pieces.Add(thischunk);
            //collision1_name
            if (collision1_name == null)
            {
                collision1_name = "";
            }
            scratch1  = Encoding.ASCII.GetBytes((string)collision1_name);
            thischunk = new byte[scratch1.Length + 4];
            scratch2  = BitConverter.GetBytes(scratch1.Length);
            Array.Copy(scratch1, 0, thischunk, 4, scratch1.Length);
            Array.Copy(scratch2, thischunk, 4);
            pieces.Add(thischunk);
            //collision2_name
            if (collision2_name == null)
            {
                collision2_name = "";
            }
            scratch1  = Encoding.ASCII.GetBytes((string)collision2_name);
            thischunk = new byte[scratch1.Length + 4];
            scratch2  = BitConverter.GetBytes(scratch1.Length);
            Array.Copy(scratch1, 0, thischunk, 4, scratch1.Length);
            Array.Copy(scratch2, thischunk, 4);
            pieces.Add(thischunk);
            //wrenches
            hasmetacomponents |= true;
            if (wrenches == null)
            {
                wrenches = new Wrench[0];
            }
            pieces.Add(BitConverter.GetBytes(wrenches.Length));
            for (int i = 0; i < wrenches.Length; i++)
            {
                //wrenches[i]
                if (wrenches[i] == null)
                {
                    wrenches[i] = new Wrench();
                }
                pieces.Add(wrenches[i].Serialize(true));
            }
            //total_wrench
            if (total_wrench == null)
            {
                total_wrench = new Wrench();
            }
            pieces.Add(total_wrench.Serialize(true));
            //contact_positions
            hasmetacomponents |= true;
            if (contact_positions == null)
            {
                contact_positions = new Vector3[0];
            }
            pieces.Add(BitConverter.GetBytes(contact_positions.Length));
            for (int i = 0; i < contact_positions.Length; i++)
            {
                //contact_positions[i]
                if (contact_positions[i] == null)
                {
                    contact_positions[i] = new Vector3();
                }
                pieces.Add(contact_positions[i].Serialize(true));
            }
            //contact_normals
            hasmetacomponents |= true;
            if (contact_normals == null)
            {
                contact_normals = new Vector3[0];
            }
            pieces.Add(BitConverter.GetBytes(contact_normals.Length));
            for (int i = 0; i < contact_normals.Length; i++)
            {
                //contact_normals[i]
                if (contact_normals[i] == null)
                {
                    contact_normals[i] = new Vector3();
                }
                pieces.Add(contact_normals[i].Serialize(true));
            }
            //depths
            hasmetacomponents |= false;
            if (depths == null)
            {
                depths = new double[0];
            }
            pieces.Add(BitConverter.GetBytes(depths.Length));
            for (int i = 0; i < depths.Length; i++)
            {
                //depths[i]
                scratch1 = new byte[Marshal.SizeOf(typeof(double))];
                h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
                Marshal.StructureToPtr(depths[i], h.AddrOfPinnedObject(), false);
                h.Free();
                pieces.Add(scratch1);
            }
            //combine every array in pieces into one array and return it
            int __a_b__f = pieces.Sum((__a_b__c) => __a_b__c.Length);
            int __a_b__e = 0;

            byte[] __a_b__d = new byte[__a_b__f];
            foreach (var __p__ in pieces)
            {
                Array.Copy(__p__, 0, __a_b__d, __a_b__e, __p__.Length);
                __a_b__e += __p__.Length;
            }
            return(__a_b__d);
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            int   number      = 0;
            float floatNumber = 43.9F;
            bool  boolean     = true;

            number += 1;

            var implicitVariable = false;             // Guessed at compile time

            Console.WriteLine(implicitVariable.GetType());

            // implict conversion (when there is no loss of information)
            // floatNumber = number;

            // explicit conversion (needed when there is a loss of information)
            number = (int)floatNumber;
            Console.WriteLine(number);

            // Definite assignment
            int number2 = 100;

            Console.WriteLine(number2);
            Console.WriteLine((new Program()).number01);

            int[] numbers = new int[4];
            Console.WriteLine(numbers[0]);

            float i = (1 + 2) / 6 + 4;

            Console.WriteLine(i);

            Tools.Wrench wrench  = new Tools.Wrench();
            Wrench       wrench2 = new Wrench();
            FantasyBook  fantasy = new FantasyBook();

            Message goodMorning = new Message("Body");
            string  pieceOfText = "Good Morning ";

            goodMorning.SetMessage(ref pieceOfText);
            Console.WriteLine(pieceOfText);
            goodMorning.setMessages("Hello", "Hi", "Bye Bye");
            Console.WriteLine(goodMorning.BodyOfText);
            goodMorning.BodyOfText = "Hello";
            Console.WriteLine(goodMorning.BodyOfText);
            Console.WriteLine(goodMorning.BodyOfTextSize);
            goodMorning.BodyOfTextSize = 2;
            Console.WriteLine(goodMorning.BodyOfText);
            Console.WriteLine("-----");
            goodMorning.title = "Title";
            Console.WriteLine(goodMorning.title);
            PostIt postIt  = new PostIt();
            PostIt postIt2 = new PostIt();

            goodMorning.BodyOfText = "Rupendra Bandyopadhyay";
            Console.WriteLine(goodMorning[3]);
            goodMorning[1] = (char)((int)goodMorning[1] + 'A' - 'a');
            Console.WriteLine(goodMorning.BodyOfText);

            // Operator Overloading
            Message message  = new Message("Body 1", "Title 1");
            Message message1 = new Message("Body 2", "Title 2");

            message = message + message1;
            Console.WriteLine(message.title + ", " + message.BodyOfText);

            // Inheritance
            PostIt postIt3 = new PostIt();

            postIt3.title      = "My PostIT";
            postIt3.BodyOfText = "New message for my post it";
            Console.WriteLine(postIt3.BodyOfText);
            Message m1 = (Message)postIt3 + new Message("\nBye");

            Console.WriteLine(m1.BodyOfText);

            // Csv Reader
            CsvReader csvReader = new CsvReader(@"C:\Users\rupen\Documents\test_01.csv");

            csvReader.read();

            // Polymorphism
            Message messageP1 = new Message("");
            PostIt  postItP1  = new PostIt();

            SetMessages(messageP1);
            SetMessages(postItP1);

            messageP1.Lock();
            message1.Unlock();

            Paper paper = new Paper();

            paper.Lock();
            paper.Unlock();

            ILock[] locks = new ILock[2];
            locks[0] = messageP1;
            locks[1] = paper;
            foreach (ILock lok in locks)
            {
                lok.Lock();
                lok.Unlock();
            }

            Console.Write("Calling Lock on ITarget: ");
            ITarget target = messageP1;

            target.Lock();
            UseDelegate();
            UseMulticastDelegate();
            Console.WriteLine("Get JSON");
            Console.WriteLine(GetJSON());
            string  json    = GetJSON();
            Account account = GetAccountFromJSON(json);

            Console.WriteLine(account);
            Console.WriteLine("Begin Publish to Kafka");
            PublishToKafka("104.196.197.123:9092", "hello-kafka");
            // PublishToKafka("105.196.197.123:9092", "hello-kafka");
        }
Exemplo n.º 24
0
 private void OnTriggerExit(Collider other)
 {//hand layer can only interact with tool layer
     b_IstoolInRange = false;
     toolInRange     = null;
 }
        public override void Randomize()
        {
            int    arraylength = -1;
            Random rand        = new Random();
            int    strlength;

            byte[] strbuf, myByte;

            //info
            strlength = rand.Next(100) + 1;
            strbuf    = new byte[strlength];
            rand.NextBytes(strbuf);  //fill the whole buffer with random bytes
            for (int __x__ = 0; __x__ < strlength; __x__++)
            {
                if (strbuf[__x__] == 0) //replace null chars with non-null random ones
                {
                    strbuf[__x__] = (byte)(rand.Next(254) + 1);
                }
            }
            strbuf[strlength - 1] = 0; //null terminate
            info = Encoding.ASCII.GetString(strbuf);
            //collision1_name
            strlength = rand.Next(100) + 1;
            strbuf    = new byte[strlength];
            rand.NextBytes(strbuf);  //fill the whole buffer with random bytes
            for (int __x__ = 0; __x__ < strlength; __x__++)
            {
                if (strbuf[__x__] == 0) //replace null chars with non-null random ones
                {
                    strbuf[__x__] = (byte)(rand.Next(254) + 1);
                }
            }
            strbuf[strlength - 1] = 0; //null terminate
            collision1_name       = Encoding.ASCII.GetString(strbuf);
            //collision2_name
            strlength = rand.Next(100) + 1;
            strbuf    = new byte[strlength];
            rand.NextBytes(strbuf);  //fill the whole buffer with random bytes
            for (int __x__ = 0; __x__ < strlength; __x__++)
            {
                if (strbuf[__x__] == 0) //replace null chars with non-null random ones
                {
                    strbuf[__x__] = (byte)(rand.Next(254) + 1);
                }
            }
            strbuf[strlength - 1] = 0; //null terminate
            collision2_name       = Encoding.ASCII.GetString(strbuf);
            //wrenches
            arraylength = rand.Next(10);
            if (wrenches == null)
            {
                wrenches = new Wrench[arraylength];
            }
            else
            {
                Array.Resize(ref wrenches, arraylength);
            }
            for (int i = 0; i < wrenches.Length; i++)
            {
                //wrenches[i]
                wrenches[i] = new Wrench();
                wrenches[i].Randomize();
            }
            //total_wrench
            total_wrench = new Wrench();
            total_wrench.Randomize();
            //contact_positions
            arraylength = rand.Next(10);
            if (contact_positions == null)
            {
                contact_positions = new Vector3[arraylength];
            }
            else
            {
                Array.Resize(ref contact_positions, arraylength);
            }
            for (int i = 0; i < contact_positions.Length; i++)
            {
                //contact_positions[i]
                contact_positions[i] = new Vector3();
                contact_positions[i].Randomize();
            }
            //contact_normals
            arraylength = rand.Next(10);
            if (contact_normals == null)
            {
                contact_normals = new Vector3[arraylength];
            }
            else
            {
                Array.Resize(ref contact_normals, arraylength);
            }
            for (int i = 0; i < contact_normals.Length; i++)
            {
                //contact_normals[i]
                contact_normals[i] = new Vector3();
                contact_normals[i].Randomize();
            }
            //depths
            arraylength = rand.Next(10);
            if (depths == null)
            {
                depths = new double[arraylength];
            }
            else
            {
                Array.Resize(ref depths, arraylength);
            }
            for (int i = 0; i < depths.Length; i++)
            {
                //depths[i]
                depths[i] = (rand.Next() + rand.NextDouble());
            }
        }
Exemplo n.º 26
0
 private void OnTriggerEnter(Collider other)
 {//hand layer can only interact with tool layer
     b_IstoolInRange = true;
     toolInRange     = other.GetComponent <Wrench>();
 }
        public override void Deserialize(byte[] SERIALIZEDSTUFF, ref int currentIndex)
        {
            int    arraylength       = -1;
            bool   hasmetacomponents = false;
            object __thing;
            int    piecesize = 0;

            byte[] thischunk, scratch1, scratch2;
            IntPtr h;

            //info
            info          = "";
            piecesize     = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex += 4;
            info          = Encoding.ASCII.GetString(SERIALIZEDSTUFF, currentIndex, piecesize);
            currentIndex += piecesize;
            //collision1_name
            collision1_name = "";
            piecesize       = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex   += 4;
            collision1_name = Encoding.ASCII.GetString(SERIALIZEDSTUFF, currentIndex, piecesize);
            currentIndex   += piecesize;
            //collision2_name
            collision2_name = "";
            piecesize       = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex   += 4;
            collision2_name = Encoding.ASCII.GetString(SERIALIZEDSTUFF, currentIndex, piecesize);
            currentIndex   += piecesize;
            //wrenches
            hasmetacomponents |= true;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (wrenches == null)
            {
                wrenches = new Wrench[arraylength];
            }
            else
            {
                Array.Resize(ref wrenches, arraylength);
            }
            for (int i = 0; i < wrenches.Length; i++)
            {
                //wrenches[i]
                wrenches[i] = new Wrench(SERIALIZEDSTUFF, ref currentIndex);
            }
            //total_wrench
            total_wrench = new Wrench(SERIALIZEDSTUFF, ref currentIndex);
            //contact_positions
            hasmetacomponents |= true;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (contact_positions == null)
            {
                contact_positions = new Vector3[arraylength];
            }
            else
            {
                Array.Resize(ref contact_positions, arraylength);
            }
            for (int i = 0; i < contact_positions.Length; i++)
            {
                //contact_positions[i]
                contact_positions[i] = new Vector3(SERIALIZEDSTUFF, ref currentIndex);
            }
            //contact_normals
            hasmetacomponents |= true;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (contact_normals == null)
            {
                contact_normals = new Vector3[arraylength];
            }
            else
            {
                Array.Resize(ref contact_normals, arraylength);
            }
            for (int i = 0; i < contact_normals.Length; i++)
            {
                //contact_normals[i]
                contact_normals[i] = new Vector3(SERIALIZEDSTUFF, ref currentIndex);
            }
            //depths
            hasmetacomponents |= false;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (depths == null)
            {
                depths = new double[arraylength];
            }
            else
            {
                Array.Resize(ref depths, arraylength);
            }
            for (int i = 0; i < depths.Length; i++)
            {
                //depths[i]
                piecesize = Marshal.SizeOf(typeof(double));
                h         = IntPtr.Zero;
                if (SERIALIZEDSTUFF.Length - currentIndex != 0)
                {
                    h = Marshal.AllocHGlobal(piecesize);
                    Marshal.Copy(SERIALIZEDSTUFF, currentIndex, h, piecesize);
                }
                if (h == IntPtr.Zero)
                {
                    throw new Exception("Alloc failed");
                }
                depths[i] = (double)Marshal.PtrToStructure(h, typeof(double));
                Marshal.FreeHGlobal(h);
                currentIndex += piecesize;
            }
        }
        public override void Deserialize(byte[] SERIALIZEDSTUFF, ref int currentIndex)
        {
            int    arraylength       = -1;
            bool   hasmetacomponents = false;
            object __thing;
            int    piecesize = 0;

            byte[] thischunk, scratch1, scratch2;
            IntPtr h;

            //header
            header = new Header(SERIALIZEDSTUFF, ref currentIndex);
            //name
            hasmetacomponents |= false;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (name == null)
            {
                name = new string[arraylength];
            }
            else
            {
                Array.Resize(ref name, arraylength);
            }
            for (int i = 0; i < name.Length; i++)
            {
                //name[i]
                name[i]       = "";
                piecesize     = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
                currentIndex += 4;
                name[i]       = Encoding.ASCII.GetString(SERIALIZEDSTUFF, currentIndex, piecesize);
                currentIndex += piecesize;
            }
            //pose
            hasmetacomponents |= true;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (pose == null)
            {
                pose = new Pose[arraylength];
            }
            else
            {
                Array.Resize(ref pose, arraylength);
            }
            for (int i = 0; i < pose.Length; i++)
            {
                //pose[i]
                pose[i] = new Pose(SERIALIZEDSTUFF, ref currentIndex);
            }
            //twist
            hasmetacomponents |= true;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (twist == null)
            {
                twist = new Twist[arraylength];
            }
            else
            {
                Array.Resize(ref twist, arraylength);
            }
            for (int i = 0; i < twist.Length; i++)
            {
                //twist[i]
                twist[i] = new Twist(SERIALIZEDSTUFF, ref currentIndex);
            }
            //wrench
            hasmetacomponents |= true;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (wrench == null)
            {
                wrench = new Wrench[arraylength];
            }
            else
            {
                Array.Resize(ref wrench, arraylength);
            }
            for (int i = 0; i < wrench.Length; i++)
            {
                //wrench[i]
                wrench[i] = new Wrench(SERIALIZEDSTUFF, ref currentIndex);
            }
        }
        public override void Randomize()
        {
            int    arraylength = -1;
            Random rand        = new Random();
            int    strlength;

            byte[] strbuf, myByte;

            //header
            header = new Header();
            header.Randomize();
            //name
            arraylength = rand.Next(10);
            if (name == null)
            {
                name = new string[arraylength];
            }
            else
            {
                Array.Resize(ref name, arraylength);
            }
            for (int i = 0; i < name.Length; i++)
            {
                //name[i]
                strlength = rand.Next(100) + 1;
                strbuf    = new byte[strlength];
                rand.NextBytes(strbuf);  //fill the whole buffer with random bytes
                for (int __x__ = 0; __x__ < strlength; __x__++)
                {
                    if (strbuf[__x__] == 0) //replace null chars with non-null random ones
                    {
                        strbuf[__x__] = (byte)(rand.Next(254) + 1);
                    }
                }
                strbuf[strlength - 1] = 0; //null terminate
                name[i] = Encoding.ASCII.GetString(strbuf);
            }
            //pose
            arraylength = rand.Next(10);
            if (pose == null)
            {
                pose = new Pose[arraylength];
            }
            else
            {
                Array.Resize(ref pose, arraylength);
            }
            for (int i = 0; i < pose.Length; i++)
            {
                //pose[i]
                pose[i] = new Pose();
                pose[i].Randomize();
            }
            //twist
            arraylength = rand.Next(10);
            if (twist == null)
            {
                twist = new Twist[arraylength];
            }
            else
            {
                Array.Resize(ref twist, arraylength);
            }
            for (int i = 0; i < twist.Length; i++)
            {
                //twist[i]
                twist[i] = new Twist();
                twist[i].Randomize();
            }
            //wrench
            arraylength = rand.Next(10);
            if (wrench == null)
            {
                wrench = new Wrench[arraylength];
            }
            else
            {
                Array.Resize(ref wrench, arraylength);
            }
            for (int i = 0; i < wrench.Length; i++)
            {
                //wrench[i]
                wrench[i] = new Wrench();
                wrench[i].Randomize();
            }
        }
        public override byte[] Serialize(bool partofsomethingelse)
        {
            int  currentIndex = 0, length = 0;
            bool hasmetacomponents = false;

            byte[]        thischunk, scratch1, scratch2;
            List <byte[]> pieces = new List <byte[]>();
            GCHandle      h;

            //header
            if (header == null)
            {
                header = new Header();
            }
            pieces.Add(header.Serialize(true));
            //name
            hasmetacomponents |= false;
            if (name == null)
            {
                name = new string[0];
            }
            pieces.Add(BitConverter.GetBytes(name.Length));
            for (int i = 0; i < name.Length; i++)
            {
                //name[i]
                if (name[i] == null)
                {
                    name[i] = "";
                }
                scratch1  = Encoding.ASCII.GetBytes((string)name[i]);
                thischunk = new byte[scratch1.Length + 4];
                scratch2  = BitConverter.GetBytes(scratch1.Length);
                Array.Copy(scratch1, 0, thischunk, 4, scratch1.Length);
                Array.Copy(scratch2, thischunk, 4);
                pieces.Add(thischunk);
            }
            //pose
            hasmetacomponents |= true;
            if (pose == null)
            {
                pose = new Pose[0];
            }
            pieces.Add(BitConverter.GetBytes(pose.Length));
            for (int i = 0; i < pose.Length; i++)
            {
                //pose[i]
                if (pose[i] == null)
                {
                    pose[i] = new Pose();
                }
                pieces.Add(pose[i].Serialize(true));
            }
            //twist
            hasmetacomponents |= true;
            if (twist == null)
            {
                twist = new Twist[0];
            }
            pieces.Add(BitConverter.GetBytes(twist.Length));
            for (int i = 0; i < twist.Length; i++)
            {
                //twist[i]
                if (twist[i] == null)
                {
                    twist[i] = new Twist();
                }
                pieces.Add(twist[i].Serialize(true));
            }
            //wrench
            hasmetacomponents |= true;
            if (wrench == null)
            {
                wrench = new Wrench[0];
            }
            pieces.Add(BitConverter.GetBytes(wrench.Length));
            for (int i = 0; i < wrench.Length; i++)
            {
                //wrench[i]
                if (wrench[i] == null)
                {
                    wrench[i] = new Wrench();
                }
                pieces.Add(wrench[i].Serialize(true));
            }
            //combine every array in pieces into one array and return it
            int __a_b__f = pieces.Sum((__a_b__c) => __a_b__c.Length);
            int __a_b__e = 0;

            byte[] __a_b__d = new byte[__a_b__f];
            foreach (var __p__ in pieces)
            {
                Array.Copy(__p__, 0, __a_b__d, __a_b__e, __p__.Length);
                __a_b__e += __p__.Length;
            }
            return(__a_b__d);
        }
Exemplo n.º 31
0
Arquivo: Maps.cs Projeto: wbish/wirk
        private static ITile TransposeTile(ITile tile)
        {
            if (tile is Pit)
                return new Pit();

            var originalFloorTile = (Floor) tile;
            Floor floorTile;

            if (tile is ExpressConveyer)
                floorTile = new ExpressConveyer();
            else if (tile is Conveyer)
                floorTile = new Conveyer();
            else if (tile is WrenchHammer)
                floorTile = new WrenchHammer();
            else if (tile is Wrench)
                floorTile = new Wrench();
            else if (tile is Gear)
                floorTile = new Gear((tile as Gear).Direction);
            else
                floorTile = new Floor();

            foreach (var edge in originalFloorTile.Edges)
            {
                IEdge newEdge;

                if (edge.Item2 is WallLaserEdge)
                    newEdge = new WallLaserEdge((edge.Item2 as WallLaserEdge).Lasers);
                else if (edge.Item2 is WallPusherEdge)
                    newEdge = new WallPusherEdge((edge.Item2 as WallPusherEdge).Registers);
                else
                    newEdge = new WallEdge();

                floorTile.PutEdge(Utilities.GetOppositeOrientation(edge.Item1), newEdge);
            }

            var originalConveyer = originalFloorTile as Conveyer;
            if (originalConveyer != null)
            {
                var entrances = originalConveyer.Entrances.Select(Utilities.GetOppositeOrientation).ToList();

                var newConveyer = (Conveyer) floorTile;
                newConveyer.Entrances = entrances;
                newConveyer.Exit = Utilities.GetOppositeOrientation(originalConveyer.Exit);
            }

            return floorTile;
        }
Exemplo n.º 32
0
        ActionScene(Game game, Texture2D theTexture, Texture2D backgroundTexture, SpriteFont font)
            : base(game)
        {
            _audio = (AudioLibrary)Game.Services.GetService(typeof(AudioLibrary));
            _background = new ImageComponent(game, backgroundTexture, ImageComponent.DrawMode.Stretch);
            Components.Add(_background);

            _actionTexture = theTexture;

            _spriteBatch = (SpriteBatch) Game.Services.GetService(typeof (SpriteBatch));
            _meteors = new MeteorsManager(Game, ref _actionTexture);
            Components.Add(_meteors);

            _scoreFont = font;

            _scorePlayer1 = new Score(game, font, _player1FontColor) {Position = new Vector2(10, 10)};
            Components.Add(_scorePlayer1);

            _rumblePad = new SimpleRumblePad(game);
            Components.Add(_rumblePad);

            _powerSource = new PowerSource(game, ref _actionTexture);
            _powerSource.Initialize();
            Components.Add(_powerSource);

            _wrench = new Wrench(game, game.Content.Load<Texture2D>("wrench"));
            _wrench.Initialize();
            Components.Add(_wrench);

            #if DEBUG
            _positionDebugText=new TextComponent(game,_scoreFont,new Vector2(),Color.Red);
            Components.Add(_positionDebugText);
            #endif
        }