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; }
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; }
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); }
/** * 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(); }
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(); }
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(); }
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); } } } }
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; } } }
public float Dot(Vec2 other) { return x*other.x + y*other.y; }
public Vec2 Add(Vec2 other) { x += other.x; y += other.y; return this; }
public Vec2 Subtract(Vec2 other) { x -= other.x; y -= other.y; return this; }
public Vec2 SetVec(Vec2 vec) { x = vec.x; y = vec.y; return this; }
public Vec2 Reflect(Vec2 normal, float bounciness) { var vectorPartLength = Dot(normal); var projectedVector = normal.Clone().Scale(vectorPartLength); return Subtract(projectedVector.Scale(1 + bounciness)); }
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); }