Example #1
0
            protected override void OnAdded()
            {
                var rectCollider = new RectangleCollider();

                rectCollider.Area      = new RectF(0, 0, 100, 100);
                rectCollider.IsVisible = true;
                rectCollider.Tag       = "A";
                AddCollider(rectCollider);

                var lineCollider = new LineCollider();

                lineCollider.StartingPosition = new Vector2DF(110, 110);
                lineCollider.EndingPosition   = new Vector2DF(200, 200);
                lineCollider.Thickness        = 10;
                lineCollider.Tag       = "B";
                lineCollider.IsVisible = true;
                AddCollider(lineCollider);

                var circleCollider = new CircleCollider();

                circleCollider.Center    = new Vector2DF(300, 300);
                circleCollider.Radius    = 90;
                circleCollider.Tag       = "C";
                circleCollider.IsVisible = true;
                AddCollider(circleCollider);

                Scale    = new Vector2DF(0.5f, 0.5f);
                velocity = new Vector2DF(4, 0);
            }
Example #2
0
    private bool collisionWithLine(LineCollider line)
    {
        bool inside1 = collisionWithPoint(line.startPos);
        bool inside2 = collisionWithPoint(line.endPos);

        if (inside1 || inside2)
        {
            return(true);
        }

        float lineLength = (line.endPos - line.startPos).magnitude;

        // Dot product of line and circle
        float dot = (((transform.position.x - line.startPos.x) * (line.endPos.x - line.startPos.x)) + ((transform.position.y - line.startPos.y) * (line.endPos.y - line.startPos.y))) / Mathf.Pow(lineLength, 2);

        float   closestX = line.startPos.x + (dot * (line.endPos.x - line.startPos.x));
        float   closestY = line.startPos.y + (dot * (line.endPos.y - line.startPos.y));
        Vector3 closest  = new Vector3(closestX, closestY);

        if (!lineCollisionWithPoint(line, closest))
        {
            return(false);
        }

        float dist = (closest - transform.position).magnitude;

        return(dist <= radius);
    }
        public Slash(GraphicsDevice device, int minLength)
        {
            //_vertexBuffer = new VertexBuffer(device, typeof(VertexPositionNormalTexture), _vertices.Length, BufferUsage.None);

            m_attack = new AttackComponent(0.6f, 0.1f);
            m_attack.Unlock();
            m_attack.Enable();

            _minLength = minLength;

            m_sliceCollider   = new LineCollider(m_attack);
            _slashStart       = new Transform();
            _slashEnd         = new Transform();
            _slashStart.Scale = new Vector2(5, 5);
            _slashEnd.Scale   = new Vector2(10, 10);

            _device = device;

            InitMatrices();
            InitVertices();

            World.UL_Global.Add(this, 0);

            m_effect = new BasicEffect(device);
            m_effect.LightingEnabled    = false;
            m_effect.VertexColorEnabled = false;

            m_effect.World      = _world;
            m_effect.View       = _view;
            m_effect.Projection = _projection;
        }
Example #4
0
    private bool lineCollisionWithPoint(LineCollider line, Vector3 point)
    {
        float distToStart = (point - line.startPos).magnitude;
        float distToEnd   = (point - line.endPos).magnitude;
        float lineLength  = (line.endPos - line.startPos).magnitude;

        float lineWidth = TerrainGenerator.instance.lineWidth;

        return(distToStart + distToEnd >= lineLength - lineWidth && distToStart + distToEnd <= lineLength + lineWidth);
    }
Example #5
0
        public Enemy(float x, float y, int health, float cooldown) : base(x, y)
        {
            this.health   = health;
            cooldownTimer = cooldown;

            solidChecker = new LineCollider(0, 0, 0, 0, -1);
            AddCollider(solidChecker);

            EnemySpawner.Instance.AddEnemy(this);
        }
Example #6
0
        public static BlobAssetReference <QuadTree> CreateBlobAssetReference()
        {
            using (var builder = new BlobBuilder(Allocator.Temp)) {
                ref var rootQuadTree = ref builder.ConstructRoot <QuadTree>();

                var colliders = builder.Allocate(ref rootQuadTree.Colliders, 2);
                LineCollider.Create(builder, ref colliders[0], new float2(1f, 20f), new float2(3f, 4f), 5f, 6f);
                PointCollider.Create(builder, ref colliders[1], new float3(7f, 8f, 9f));

                return(builder.CreateBlobAssetReference <QuadTree>(Allocator.Persistent));
            }
 void Awake()
 {
     if (lineCollider == null)
     {
         // DontDestroyOnLoad(gameObject);
         lineCollider = this;
     }
     else if (lineCollider != this)
     {
         Destroy(gameObject);
     }
 }
Example #8
0
        public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
        {
            Convert(entity, dstManager);
            var table = gameObject.GetComponentInParent <TableBehavior>().Item;

            transform.GetComponentInParent <Player>().RegisterPlunger(Item, entity, gameObject);

            Item.Init(table);
            var hit = Item.PlungerHit;

            dstManager.AddComponentData(entity, new PlungerStaticData {
                MomentumXfer    = data.MomentumXfer,
                ScatterVelocity = data.ScatterVelocity,
                FrameStart      = hit.FrameBottom,
                FrameEnd        = hit.FrameTop,
                FrameLen        = hit.FrameLen,
                RestPosition    = hit.RestPos,
                IsAutoPlunger   = data.AutoPlunger,
                SpeedFire       = data.SpeedFire,
                NumFrames       = Item.MeshGenerator.NumFrames
            });

            dstManager.AddComponentData(entity, new PlungerColliderData {
                JointEnd0    = LineZCollider.Create(hit.JointEnd[0]),
                JointEnd1    = LineZCollider.Create(hit.JointEnd[1]),
                LineSegEnd   = LineCollider.Create(hit.LineSegEnd),
                LineSegSide0 = LineCollider.Create(hit.LineSegSide[0]),
                LineSegSide1 = LineCollider.Create(hit.LineSegSide[1])
            });

            dstManager.AddComponentData(entity, new PlungerMovementData {
                FireBounce     = 0f,
                Position       = hit.Position,
                RetractMotion  = false,
                ReverseImpulse = 0f,
                Speed          = 0f,
                TravelLimit    = hit.FrameTop,
                FireSpeed      = 0f,
                FireTimer      = 0
            });

            dstManager.AddComponentData(entity, new PlungerVelocityData {
                Mech0            = 0f,
                Mech1            = 0f,
                Mech2            = 0f,
                PullForce        = 0f,
                InitialSpeed     = 0f,
                AutoFireTimer    = 0,
                AddRetractMotion = false,
                RetractWaitLoop  = 0,
                MechStrength     = data.MechStrength
            });
        }
Example #9
0
 void CreateLine()
 {
     currentLine     = Instantiate(linePrefab, Vector3.zero, Quaternion.identity);
     lineRender      = currentLine.GetComponent <LineRenderer>();
     edgeCol         = currentLine.GetComponent <EdgeCollider2D>();
     lineCol         = currentLine.GetComponent <LineCollider>();
     lineCol.lineObj = this.gameObject;
     linePoints.Clear();
     linePoints.Add(Camera.main.ScreenToWorldPoint(Input.mousePosition));
     linePoints.Add(Camera.main.ScreenToWorldPoint(Input.mousePosition));
     lineRender.SetPosition(0, linePoints[0]);
     lineRender.SetPosition(1, linePoints[1]);
     edgeCol.points = linePoints.ToArray();
 }
Example #10
0
        public Cultist(float x, float y, Room room)
            : base(x, y, room)
        {
            sprite = SpriteData.GetAnimation("cultist");
            sprite.Play("idle");
            AddGraphic(sprite);

            damageCollider = AddCollider(new CircleCollider(16, Global.Tags.Enemy));
            damageCollider.SetOrigin(16, 32);

            visionCollider = AddCollider(new LineCollider(0, -8, 0, -8, Global.Tags.Vision));
            AddCollider(visionCollider);
            hp = 10;
        }
Example #11
0
        // OOof
        public PlayerLaser(GameScreen screen, Vector2 speed, Vector2 startPosition) : base(screen)
        {
            lc         = new LineCollider(Vector2.Zero);
            this.speed = speed;

            this.startPosition = startPosition;
            Position           = startPosition + speed * 20;

            foreach (GameObject o in screen.GameObjects)
            {
                if (o is WallObject w)
                {
                }
            }

            thickness = 8;

            deleteTimer = new Timer(20, false);
        }
Example #12
0
        public Slash(float x, float y, float dirX, float dirY, Damage.Side side)
            : base(x, y)
        {
            sprite = new Spritemap(Global.imagePath + "Player/Slash.png", 64, 64);
            sprite.Add(0, new Anim("0-3", "3"));
            sprite.Angle    = MathHelper.ToDegrees((float)Math.Atan2(dirX, dirY)) + 90;
            sprite.FlippedY = dirX > 0;
            sprite.SetOrigin(0, 32);

            AddGraphic(sprite);
            sprite.Play(0);
            sprite.Anims[0].NoRepeat();
            sprite.Anims[0].OnComplete += () => { RemoveSelf(); };

            AddComponents(damage = new Damage(5, x, y, side));

            var col = new LineCollider(-dirX * 10, -dirY * 10, -dirX * 50, -dirY * 50, Global.Tags.Attack);

            AddCollider(col);
            AddComponent(new YSort());
        }
Example #13
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Point        point = collision.gameObject.GetComponent <Point>();
        Line         line  = collision.gameObject.GetComponent <Line>();
        LineCollider col   = collision.gameObject.GetComponent <LineCollider>();

        currentHealth--;
        if (currentHealth == 1)
        {
            StartCoroutine("Lose");
        }

        if (point != null)
        {
            Destroy(point.gameObject);
        }
        else if (line != null && col != null)
        {
            Destroy(line.gameObject);
        }
    }
Example #14
0
 void Start()
 {
     lineCol         = currentLine.GetComponent <LineCollider>();
     lineCol.lineObj = this.gameObject;
 }
Example #15
0
 // Don't think this one is necessary for this assignment however it would be pretty straight forward to implement.  I will not cause running outta time
 private bool collisionWithLine(LineCollider other)
 {
     return(false);
 }
Example #16
0
    private void Update()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            if (Input.GetMouseButtonDown(0))
            {
                // Get the line renderer of the tapped line
                cashedLine = hit.transform.GetComponentInParent <LineRenderer>();

                // Disable the line for some time
                if (cashedLine != null)
                {
                    StartCoroutine(DisableLine(cashedLine));
                }

                // Destroy all packets which are still active on the tapped line
                LineCollider lineCollider = hit.transform.gameObject.GetComponent <LineCollider>();

                foreach (var collider in lineCollider.GetColliders())
                {
                    Destroy(collider.gameObject);
                }

                // Increment virus terminated count
                Server.instance.ModifyVirusPackets(lineCollider.GetDestoyedColliderCount());
                lineCollider.ClearColliderSet();
            }
        }

        #region  Packet Spawning

        // Virus Packet spawning
        if (virusPacketSpawnTime <= 0 && canSpawnPackets)
        {
            GeneratePacket(virusPacketPrefab);
            virusPacketSpawnTime = startvirusPacketSpawnTime;
            if (startvirusPacketSpawnTime > virusPacketMintime)
            {
                startvirusPacketSpawnTime -= virusPacketDecreaseTime;
            }
        }
        else
        {
            virusPacketSpawnTime -= Time.deltaTime;
        }

        // Good packet spawning
        if (goodPacketSpawnTime <= 0 && canSpawnPackets)
        {
            GeneratePacket(goodPacketPrefab);
            goodPacketSpawnTime = startGoodPacketSpawnTime;
        }
        else
        {
            goodPacketSpawnTime -= Time.deltaTime;
        }
        #endregion
    }