Beispiel #1
0
        /// <summary>
        /// returns true if it hits a body and outs the first body that it hits
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="hit"></param>
        /// <returns></returns>
        public bool WhatDidRaycastHit(QVector2 a, QVector2 b, out List <QBody> hit)
        {
            var aSim = a.ToSim();
            var bSim = b.ToSim();
            var fl   = PhysicsWorld.RayCast(aSim, aSim + bSim);

            hit = null;
            if (fl.Count > 0)
            {
                //List<QRigiBody> qbodies = new List<QRigiBody>();
                while (_hitListNogc.Count > 0)
                {
                    //hitListNOGC.RemoveFirst();
                    _hitListNogc.Clear();
                }
                for (int i = 0; i < fl.Count; i++)
                {
                    QBehavior script = fl[i].Body.UserData as QBehavior;
                    var       qbod   = script?.World.Physics.Bodies.Find(bod => script.Id == bod.Id);
                    if (qbod != null)
                    {
                        _hitListNogc.Add(qbod);
                    }
                }
                hit = _hitListNogc;
                return(true);
            }
            return(false);
        }
Beispiel #2
0
 /// <summary>
 /// Destroys script
 /// </summary>
 /// <param name="script"></param>
 public void Destroy(QBehavior script)
 {
     script.IsDestroyed = true;
     if (!DestroyQueue.Contains(script))
     {
         DestroyQueue.Enqueue(script);
     }
 }
Beispiel #3
0
 public void Instantiate(QBehavior script, QVector2 pos = default(QVector2), float rotation = 0)
 {
     script.Parent        = QEntity.GetEntity();
     script.Parent.World  = this;
     script.Parent.Script = script;
     script.IsDestroyed   = false;
     script.Transform.Reset();
     script.SetName();
     CreatorQueue.Enqueue(script.Parent);
     CreatorFlag = true;
 }
Beispiel #4
0
        /// <summary>
        /// Creates an edge, line collision from point a to b
        /// </summary>
        /// <param name="script"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public QBody CreateEdge(QBehavior script, QVector2 start, QVector2 end)
        {
            //if the body already exists we just return that one
            QBody body = FindBody(script);

            if (body != null)
            {
                return(body);
            }
            body = new QBody(script, BodyFactory.CreateEdge(PhysicsWorld, start.ToSim(), end.ToSim(), script));
            return(AddBody(body));
        }
 public void Remove(QBehavior script)
 {
     Objects.Remove(script.Parent);
     if (script is IQLoad l)
     {
         LoadObjects.Remove(l);
     }
     if (script is IQStart s)
     {
         StartObjects.Remove(s);
     }
     if (script is IQFixedUpdate u)
     {
         FixedUpdateObjects.Remove(u);
     }
     if (script is IQUpdate up)
     {
         UpdateObjects.Remove(up);
     }
     if (script is IQLateUpdate late)
     {
         LateUpdateObjects.Remove(late);
     }
     if (script is IQSprite ds)
     {
         SpriteObjects.Remove(ds);
     }
     if (script is IQGui dg)
     {
         GuiObjects.Remove(dg);
     }
     if (script is IQDestroy des)
     {
         des.OnDestroy();
         DestroyObjects.Remove(des);
     }
     if (script is IQUnload un)
     {
         UnloadObjects.Remove(un);
     }
     //invokes event even if does not inherit OnDestroy
     script.DestroyEvent();
 }
Beispiel #6
0
//		public QRigiBody CreateRoundedRect(QBehavior script, float w = 10, float h = 10, float density = 1, QBodyTypes bodyType = QBodyTypes.Dynamic)
//		{
//			var d = 4f;
//			var body = new QRigiBody(script, BodyFactory.CreateRoundedRectangle(world, w.ToSim(), h.ToSim(), w.ToSim() / d, h.ToSim() / d, 10, density, script.Transform.Position.ToSim(), script.Transform.Rotation, (BodyType)bodyType, script));
//			script.Transform.Body = body;
//			Bodies.Add(body);
//			return body;
//		}

        /// <summary>
        /// Creates a Circle, turns this script into a physics object,
        /// you then need to do all updates in fixedUpdate
        /// </summary>
        /// <param name="script"></param>
        /// <param name="radius"></param>
        /// <param name="density"></param>
        /// <param name="bodyType"></param>
        /// <returns></returns>
        public QBody CreateCircle(QBehavior script, float radius = 10, float density = 1,
                                  QBodyTypes bodyType            = QBodyTypes.Dynamic)
        {
            //if the body already exists we just return that one
            QBody body = FindBody(script);

            if (body != null)
            {
                return(body);
            }
            body = new QBody(
                script,
                BodyFactory.CreateCircle(PhysicsWorld,
                                         radius.ToSim(),
                                         density,
                                         script.Transform.Position.ToSim(),
                                         (BodyType)bodyType,
                                         script));
            return(AddBody(body));
        }
Beispiel #7
0
        /// <summary>
        /// Creates a rectangle, turns this script into a physics object,
        /// you then need to do all updates in fixedUpdate
        /// </summary>
        /// <param name="script"></param>
        /// <param name="w"></param>
        /// <param name="h"></param>
        /// <param name="density"></param>
        /// <param name="bodyType"></param>
        /// <returns></returns>
        public QBody CreateRectangle(QBehavior script, float w = 10, float h = 10, float density = 1,
                                     QBodyTypes bodyType       = QBodyTypes.Dynamic)
        {
            QBody body = FindBody(script);

            if (body != null)
            {
                return(body);
            }
            body = new QBody(script,
                             BodyFactory.CreateRectangle(PhysicsWorld,
                                                         w.ToSim(),
                                                         h.ToSim(),
                                                         density,
                                                         script.Transform.Position.ToSim(),
                                                         script.Transform.Rotation,
                                                         (BodyType)bodyType,
                                                         script));
            return(AddBody(body));
        }
 public void Add(QBehavior script)
 {
     Objects.Add(script.Parent);
     if (script is IQLoad l)
     {
         LoadObjects.Add(l);
     }
     if (script is IQStart s)
     {
         StartObjects.Add(s);
     }
     if (script is IQFixedUpdate u)
     {
         FixedUpdateObjects.Add(u);
     }
     if (script is IQUpdate up)
     {
         UpdateObjects.Add(up);
     }
     if (script is IQLateUpdate late)
     {
         LateUpdateObjects.Add(late);
     }
     if (script is IQSprite ds)
     {
         SpriteObjects.Add(ds);
     }
     if (script is IQGui dg)
     {
         GuiObjects.Add(dg);
     }
     if (script is IQDestroy des)
     {
         DestroyObjects.Add(des);
     }
     if (script is IQUnload un)
     {
         UnloadObjects.Add(un);
     }
 }
Beispiel #9
0
        /*Private Methods*/

        /// <summary>
        /// frees up qobject and removes it from all arrays, sounds cool
        /// </summary>
        /// <param name="script"></param>
        void Obliterate(QBehavior script)
        {
            Entities.Remove(script);
            script.Transform.Reset();
            QEntity.FreeEntity(script.Parent);
        }
Beispiel #10
0
 QBody FindBody(QBehavior script)
 {
     return(Bodies.Find(bd => script.Id == bd.Id));
 }