Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public static void SpawnObjects(QGetContent content, string nameOfTexture, QVector2 startingPos, QVector2 scale, ObjectCreator spawner)
        {
            var t      = content.Texture(nameOfTexture);
            var colors = t.GetPixels();
            var c      = ConvertArray2D(colors, t.Width, t.Height);

            ObjectSceneLoader(c, startingPos, scale, spawner);
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 4
0
        //Instantiates objects at positions of a QMapTools
        static void ObjectSceneLoader(QColor[,] colors, QVector2 startingPos, QVector2 tileSize, ObjectCreator spawner)
        {
            QVector2 pos = startingPos;

            for (int i = 0; i < colors.GetLength(0); ++i, pos.X = startingPos.X, pos.Y += tileSize.Y)
            {
                for (int j = 0; j < colors.GetLength(1); ++j, pos.X += tileSize.X)
                {
                    spawner(colors[i, j], pos);
                }
            }
        }
Ejemplo n.º 5
0
        public bool DidRaycastHit(QVector2 a, QVector2 b)
        {
            var aSim = a.ToSim();
            var bSim = b.ToSim();
            var fl   = PhysicsWorld.RayCast(aSim, aSim + bSim);

            if (fl.Count > 0)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
0
        //turns list of colors into list of rectangles and positions
        static List <QTiles> CompileLayer(QColor[,] colors, QVector2 startingPos, QVector2 scale, TileMapper layer)
        {
            var tiles = new List <QTiles>();
            var pos   = startingPos;

            for (int i = 0; i < colors.GetLength(0); i++)
            {
                for (int j = 0; j < colors.GetLength(1); j++)
                {
                    var r = layer(colors[i, j]);
                    if (r != QRectangle.Empty)
                    {
                        tiles.Add(new QTiles(pos, r));
                    }
                    pos.X += scale.X;
                }
                pos.X  = startingPos.X;
                pos.Y += scale.Y;
            }
            return(tiles);
        }
Ejemplo n.º 8
0
 public static QVector2 Clamp(QVector2 value, QVector2 min, QVector2 max) => QVector2.Clamp(value, min, max);
Ejemplo n.º 9
0
        /// <summary>
        /// Measures how many atlases are needed depending on the system
        /// </summary>
        /// <param name="manager"></param>
        /// <returns></returns>
        static List <List <QTexture> > AtlasesNeeded(QContentManager manager)
        {
            //number of atlases
            int atlasCount = 0;
            //how big the texture can get before resettting
            int textureMaxWidth = 0;
            //how big the texture can get before resettting
            int textureMaxHeight = 0;
            //the height needed for the current atlas; last one will always be the shortest
            int biggestHeight = 0;
            int totalWidth    = 0;

            //If the current system is high quality we can use bigger textures because of max limits on textures
            if (QEngine.IsHighQuality)
            {
                textureMaxWidth  = HighQualityWidth;
                textureMaxHeight = HightQualityHeight;
            }
            else
            {
                textureMaxWidth  = LowQualityWidth;
                textureMaxHeight = LowQualityHeight;
            }

            //finds the width all the textures take up side by side, and finds the biggest ones height
            foreach (var texture in manager.Textures.Values)
            {
                totalWidth += texture.Width;
                if (texture.Height > biggestHeight)
                {
                    biggestHeight = texture.Height;
                }
            }

            int rowsNeeded = (int)Math.Round((double)totalWidth / textureMaxHeight) + 1;

            int totalHeight = rowsNeeded * biggestHeight;

            //gives us the sheets needed but without remainder
            atlasCount = totalHeight / textureMaxHeight;
            //then gives use the actual remainder
            int remainder = totalHeight % textureMaxHeight;

            //if the remainder exist then we need another texture
            if (remainder > 0)
            {
                atlasCount++;
            }

            var ListOfListOfTextures = new List <List <QTexture> >();

            for (int i = 0; i < atlasCount; i++)
            {
                ListOfListOfTextures.Add(new List <QTexture>());
            }

            var textures = manager.Textures.ToList();

            QVector2 pos    = QVector2.Zero;
            int      tSheet = 0;

            for (int i = 0; i < textures.Count; i++)
            {
                var t = textures[i].Value;
                pos.X += t.Width;
                if (pos.X > textureMaxWidth)
                {
                    pos.X  = 0;
                    pos.Y += biggestHeight;
                }
                if (pos.Y > textureMaxHeight)
                {
                    tSheet++;
                }
                ListOfListOfTextures[tSheet].Add(t);
            }

            return(ListOfListOfTextures);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Moves the matrix on the 2D plane
 /// </summary>
 /// <param name="v"></param>
 /// <returns></returns>
 public static QMatrix Translate(QVector2 v) => Matrix.CreateTranslation(v.X, v.Y, 1);
Ejemplo n.º 11
0
        public static List <QTiles> CreateSpriteLayer(QGetContent content, string nameOfTexture, QVector2 startingPos, QVector2 scale, TileMapper layer)
        {
            var t      = content.Texture(nameOfTexture);
            var colors = t.GetPixels();
            var c      = ConvertArray2D(colors, t.Width, t.Height);

            return(CompileLayer(c, startingPos, scale, layer));
        }
Ejemplo n.º 12
0
 public QTiles(QVector2 pos, QRectangle source)
 {
     Position = pos;
     Source   = source;
 }
Ejemplo n.º 13
0
//		/// <summary>
//		/// Draws filled in circle
//		/// </summary>
//		/// <param name="t"></param>
//		/// <param name="radius"></param>
//		/// <param name="c"></param>
//		public void DrawCircle(QTransform t, float radius, QColor c)
//		{
//			sb.DrawCircle(t.Position, radius, 20, c, radius);
//		}
//
//		/// <summary>
//		/// Assumes that the rectangle origin is in the middle
//		/// </summary>
//		/// <param name="t"></param>
//		/// <param name="width"></param>
//		/// <param name="height"></param>
//		/// <param name="color"></param>
//		public void DrawRect(QTransform t, float width, float height, QColor color)
//		{
//			var v = t.Position;
//			//sb.DrawRectangle(v - new QVec(width, height)/2f, new QVec(width, height), color);
//			sb.FillRectangle(v - new QVec(width, height)/2f, new QVec(width, height), color);
//			//sb.FillRectangle(t.Position.X, t.Position.Y, width, height, color, t.Rotation);
//		}

        internal virtual void Draw(QTexture t, QVector2 pos, QColor c)
        {
            sb.Draw(t, pos, c);
        }
Ejemplo n.º 14
0
        /*Private Methods*/

        public bool Equals(QVector2 other)
        {
            return(pos.Equals(other.pos));
        }
Ejemplo n.º 15
0
 public MessageBox(string s, QVector2 v)
 {
     Text        = s;
     MeasureMent = v;
 }