예제 #1
0
 public LineSegment(Vec2 pStart, Vec2 pEnd, uint pColor = 0xffffffff, uint pLineWidth = 1,
     bool pGlobalCoords = false)
 {
     Start = pStart;
     End = pEnd;
     Color = pColor;
     LineWidth = pLineWidth;
     UseGlobalCoords = pGlobalCoords;
 }
예제 #2
0
 public LineSegment(Vec2 pStart, Vec2 pEnd, GameObject owner, uint pColor = 0xffffffff, uint pLineWidth = 1, bool pGlobalCoords = false)
 {
     _owner = owner;
     Start = pStart;
     End = pEnd;
     Color = pColor;
     LineWidth = pLineWidth;
     UseGlobalCoords = pGlobalCoords;
 }
예제 #3
0
 public Polygon(Vec2[] points, uint color, Level.Level level, int id, float realPosX, float realPosY)
 {
     _points = points;
     _realPosX = realPosX;
     _realPosY = realPosY;
     _level = level;
     _color = color;
     _id = id;
     DrawOnCanvas();
     _lines = new LineSegment[_points.Length];
     CreateLines();
     foreach (var line in _lines) _level.AddChild(line);
 }
예제 #4
0
        /**
         * Creates a ball with a radius, a start position, a start velocity, and optionally a color.
         * Note the Color? this means that pColor can be null (which is not possible normally for structs since they are value types).
         */
        public Ball(int pRadius, Vec2 position = null, Vec2 velocity = null, Vec2 acceleration = null, Color? pColor = null)
            : base(pRadius*2, pRadius*2)
        {
            graphics.SmoothingMode= SmoothingMode.HighQuality;
            radius = pRadius;
            Position = position;
            Velocity = velocity;
            Acceleration = acceleration;
            _ballColor = pColor ?? Color.Blue;

            //Draw();
            if (Position != null)
            {
                x = Position.x;
                y = Position.y;
            }
            Step();
        }
예제 #5
0
        public Paddle(Level.Level level, Vec2 position = null)
            : base("../assets/sprite/player/player.png", 13, 1)
        {
            SetOrigin(width/2, 0);
            _level = level;
            _position = position;
            if (UtilitySettings.DebugMode) alpha = 0;

            if (Position != null)
            {
                x = Position.x;
                y = Position.y;
            }

            CreateLines();

            CreateLimit();
        }
예제 #6
0
        public Ball(int pRadius, AnimationSprite sprite, Vec2 position = null, Vec2 velocity = null, Vec2 acceleration = null)
            : base(pRadius * 2, pRadius * 2)
        {
            _spriteOverlay = sprite;
            _spriteOverlay.SetOrigin(_spriteOverlay.width / 2, _spriteOverlay.height / 2);
            AddChild(_spriteOverlay);
            radius = pRadius;
            Position = position;
            Velocity = velocity;
            Acceleration = acceleration;

            _ballColor = Color.FromArgb(0x000000);

            Draw();
            if (Position != null)
            {
                x = Position.x;
                y = Position.y;
            }
            Step();
        }
예제 #7
0
        private void CreatePolygons(ObjectGroup objectGroup)
        {
            foreach (var tiledObject in objectGroup.TiledObjects)
            {
                if (tiledObject.Polygon != null)
                {
                    var pointArr = tiledObject.Polygon.Points.Split(' ');
                    var vectorArray = new Vec2[pointArr.Length];
                    for (var i = 0; i < pointArr.Length; i++)
                    {
                        var pointCoords = pointArr[i].Split(',');
                        vectorArray[i] = new Vec2(
                            float.Parse(pointCoords[0], CultureInfo.InvariantCulture.NumberFormat),
                            float.Parse(pointCoords[1], CultureInfo.InvariantCulture.NumberFormat));
                    }

                    uint polyColor = 0;
                    if (tiledObject.Properties != null)
                    {
                        foreach (var property in tiledObject.Properties)
                        {
                            if (property.Property.Name.ToLower() == "colour" ||
                                property.Property.Name.ToLower() == "color")
                            {
                                polyColor = Convert.ToUInt32(property.Property.Value, 16) + 0xFF000000;
                            }
                        }
                        var poly = new Polygon(vectorArray, polyColor, this, tiledObject.ID, tiledObject.X,
                            tiledObject.Y);
                        poly.SetXY(tiledObject.X, tiledObject.Y);
                        _polyList.Add(poly);
                    }
                }
            }
        }
예제 #8
0
 private void CreateLines()
 {
     var relativePoints = new Vec2[_points.Length];
     for (var i = 0; i < _points.Length; i++)
     {
         relativePoints[i] = new Vec2();
         relativePoints[i].x = _points[i].x + _realPosX;
         relativePoints[i].y = _points[i].y + _realPosY;
     }
     for (var i = 0; i < relativePoints.Length; i++)
     {
         if (i < relativePoints.Length - 1)
         {
             if (UtilitySettings.DebugMode)
                 Console.WriteLine("Creating Line " + i + " with coords: " + relativePoints[i] +
                                   relativePoints[i + 1]);
             _lines[i] = new LineSegment(relativePoints[i], relativePoints[i + 1], this, _color);
             if (!UtilitySettings.DebugMode) _lines[i].Color = 0x00000000;
         }
         else
         {
             if (UtilitySettings.DebugMode)
                 Console.WriteLine("Creating Line " + i + " with coords: " +
                                   relativePoints[relativePoints.Length - 1] + relativePoints[0]);
             _lines[i] = new LineSegment(relativePoints[relativePoints.Length - 1], relativePoints[0], this,
                 _color);
             if (!UtilitySettings.DebugMode) _lines[i].Color = 0x00000000;
         }
     }
 }
예제 #9
0
 public float Dot(Vec2 other)
 {
     return x*other.x + y*other.y;
 }
예제 #10
0
 public Vec2 Add(Vec2 other)
 {
     x += other.x;
     y += other.y;
     return this;
 }
예제 #11
0
 public Vec2 Subtract(Vec2 other)
 {
     x -= other.x;
     y -= other.y;
     return this;
 }
예제 #12
0
 public Vec2 SetVec(Vec2 vec)
 {
     x = vec.x;
     y = vec.y;
     return this;
 }
예제 #13
0
 public Vec2 Reflect(Vec2 normal, float bounciness)
 {
     var vectorPartLength = Dot(normal);
     var projectedVector = normal.Clone().Scale(vectorPartLength);
     return Subtract(projectedVector.Scale(1 + bounciness));
 }
예제 #14
0
 public static void RenderLine(Vec2 pStart, Vec2 pEnd, uint pColor = 0xffffffff, uint pLineWidth = 1,
     bool pGlobalCoords = false)
 {
     RenderLine(pStart.x, pStart.y, pEnd.x, pEnd.y, pColor, pLineWidth, pGlobalCoords);
 }