Exemplo n.º 1
0
    public void Register(RectCollider collider, string layer)
    {
        int   chunkIndex = Peaks(collider.rect.center.x);
        Chunk chunk      = GetChunk(chunkIndex);

        chunk.Add(collider, layer);
    }
Exemplo n.º 2
0
        public override void Init()
        {
            Sprite sprite = new Sprite();

            gameObject.AddComponent(sprite);

            gameObject.GetComponent <Sprite>().Load("Sprites/MainGuySpriteSheet_0");
            gameObject.GetComponent <Sprite>().scale = 1;
            gameObject.GetComponent <Sprite>().rect  = new Rectangle(46, 0, 32, 36);


            Transform transform = new Transform();

            gameObject.AddComponent(transform);
            //  gameObject.GetComponent<Transform>().position = new Vector2(Screen.width / 2 - gameObject.GetComponent<Sprite>().rect.Width, Screen.height / 2 - gameObject.GetComponent<Sprite>().rect.Height);
            gameObject.GetComponent <Transform>().position = new Vector2(pos_X, pos_Y - 32 * (gameObject.GetComponent <Sprite>().scale - 1));

            RectCollider collider = new RectCollider();

            gameObject.AddComponent(collider);
            gameObject.GetComponent <RectCollider>().Set(gameObject.GetComponent <Sprite>(), gameObject.GetComponent <Transform>());

            SpriteRenderer render = new SpriteRenderer();

            gameObject.AddComponent(render);
            gameObject.GetComponent <SpriteRenderer>().layer = 1;
            gameObject.GetComponent <SpriteRenderer>().Set(gameObject.GetComponent <Sprite>());
        }
Exemplo n.º 3
0
    bool IsCollided(out RectCollider collider, Vector2 endPoint)
    {
        Vector2 outsidePointTarget;

        if (!MathHelper.LineIntersectRect(out outsidePointTarget, _gunRoot.position, endPoint, GameCamera.instance.viewport))
        {
            Debug.LogWarning("No collision with the viewport and the aiming line");
        }

        Rect boundingBox = MathHelper.ConstructRect(outsidePointTarget, _gunRoot.position);

#if UNITY_EDITOR
        _boundingBox = boundingBox;
#endif

        List <RectCollider> found = ColliderManager.instance.FindCollisions(boundingBox, "interactable");

        Vector2 intersection;
        for (int i = 0; i < found.Count; i++)
        {
            if (MathHelper.LineIntersectRect(out intersection, _gunRoot.position, endPoint, found[i].rect))
            {
                collider = found[i];
                return(true);
            }
        }

        collider = null;
        return(false);
    }
Exemplo n.º 4
0
        public SongButton(Rectangle rect, String folder)
        {
            String[] songfiles = Directory.GetFiles(folder, "*.wav", SearchOption.TopDirectoryOnly);
            String[] dmlfiles  = Directory.GetFiles(folder, "*.dml", SearchOption.TopDirectoryOnly);

            if (dmlfiles.Count() > 0)
            {
                dmlfile = dmlfiles[0];
            }

            String[] pngs   = Directory.GetFiles(folder, "*.png", SearchOption.TopDirectoryOnly);//gets images from folder
            String[] jpgs   = Directory.GetFiles(folder, "*.jpg", SearchOption.TopDirectoryOnly);
            String[] images = new String[pngs.Length + jpgs.Length];
            pngs.CopyTo(images, 0);
            jpgs.CopyTo(images, pngs.Length);
            if (images.Count() > 0)
            {
                String image = images[0];
                texture = Texture2D.FromStream(Globals.graphics.GraphicsDevice, File.OpenRead(image));//reads images from stream(non content)
            }
            else
            {
                texture = new Texture2D(Globals.graphics.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
                texture.SetData <Color>(new Color[] { Color.White });
            }
            this.song = songfiles[0];
            if (songfiles.Length > 0)
            {
                this.music = new Wave(songfiles[0]);
            }
            this.title    = songfiles[0];
            this.rect     = rect;
            CollisionMask = new RectCollider(rect);
        }
        public override void Init()
        {
            Sprite sprite = new Sprite();

            gameObject.AddComponent(sprite);
            gameObject.GetComponent <Sprite>().Load("Sprites/tomatoes01");
            gameObject.GetComponent <Sprite>().scale = 1;
            gameObject.GetComponent <Sprite>().rect  = new Rectangle(0, 50, 50, 45);

            Transform transform = new Transform();

            gameObject.AddComponent(transform);
            gameObject.GetComponent <Transform>().position = new Vector2(Screen.width / 2 - gameObject.GetComponent <Sprite>().rect.Width, Screen.height / 2 - gameObject.GetComponent <Sprite>().rect.Height);

            RectCollider collider = new RectCollider();

            gameObject.AddComponent(collider);
            gameObject.GetComponent <RectCollider>().Set(gameObject.GetComponent <Sprite>(), gameObject.GetComponent <Transform>());

            SpriteRenderer render = new SpriteRenderer();

            gameObject.AddComponent(render);
            gameObject.GetComponent <SpriteRenderer>().layer = 5;
            gameObject.GetComponent <SpriteRenderer>().Set(gameObject.GetComponent <Sprite>());
        }
Exemplo n.º 6
0
    void FilterCollisions(List <RectCollider> colliders, Rect rect)
    {
        int removeIndex = -1;
        int removeCount = 0;

        for (int i = 0; i < colliders.Count; i++)
        {
            RectCollider c = colliders[i];

            if (!c.rect.Overlaps(rect))
            {
                removeCount++;

                if (removeIndex == -1)
                {
                    removeIndex = i;
                }
            }
            else
            {
                if (removeIndex != -1)
                {
                    // swap with the first remove item
                    colliders[removeIndex] = c;
                    removeIndex++;
                }
            }
        }

        if (removeIndex > -1)
        {
            colliders.RemoveRange(removeIndex, removeCount);
        }
    }
Exemplo n.º 7
0
 protected virtual void Awake()
 {
     if (__collider == null)
     {
         __collider = GetComponent <RectCollider>();
     }
 }
 public CollisionInfo(bool hitBottom, bool hitTop, bool hitRight, bool hitLeft, RectCollider obj)
 {
     this.hitBottom = hitBottom;
     this.hitTop    = hitTop;
     this.hitRight  = hitRight;
     this.hitLeft   = hitLeft;
     this.obj       = obj;
 }
Exemplo n.º 9
0
 public static void RegisterCollider(RectCollider collider)
 {
     if (colliders == null)
     {
         colliders = new List <RectCollider>();
     }
     colliders.Add(collider);
 }
Exemplo n.º 10
0
        public SceneButton(string n, string texture_name, Vector2 topleft, Rectangle rect)
        {
            name     = n;
            locked   = false;
            selected = false;

            texture       = Globals.content.Load <Texture2D>(texture_name);
            CollisionMask = new RectCollider(rect);
        }
Exemplo n.º 11
0
    public void Actualize(float dt)
    {
        RectCollider playerCollider = Player.instance.collider;

        List <RectCollider> colliders = ColliderManager.instance.FindCollisions(playerCollider.rect, _colliderLayer);

        for (int i = 0; i < colliders.Count; i++)
        {
            colliders[i].triggerZone.OnTrigger();
        }
    }
Exemplo n.º 12
0
        public SceneButton(string n, string texture_name, Vector2 topleft)
        {
            // Constructor edited by: Michael Ala
            name     = n;
            locked   = false;
            selected = false;

            // Initialize RectCollider
            texture       = Globals.content.Load <Texture2D>(texture_name);
            CollisionMask = new RectCollider(topleft.X, topleft.Y, texture.Width, texture.Height);
        }
Exemplo n.º 13
0
    public void Add(RectCollider collider, string layer)
    {
        if (!_quadTreeDict.ContainsKey(layer))
        {
            QuadTrees qt = new QuadTrees(_bounds);

            _quadTreeDict.Add(layer, qt);
            _quadTreeList.Add(qt);
        }

        _quadTreeDict[layer].Insert(collider);
    }
Exemplo n.º 14
0
        public override void Initialize()
        {
            D3D9Manager.Instance.OnMouseClickEvent += OnClick;

            if (rectCollider == null)
            {
                rectCollider = new RectCollider()
                {
                    Range = new Rectangle(0, 0, ButtonTexture.Width, ButtonTexture.Height)
                };
            }
        }
Exemplo n.º 15
0
        public bool CheckCollision(CircleCollider circle, RectCollider rect)
        {
            var closestX = MathHelper.Clamp(circle.X, rect.X, rect.X + rect.Widht);
            var closestY = MathHelper.Clamp(circle.Y, rect.Y, rect.Y + rect.Height);

            // Calculate the distance between the circle's center and this closest point
            var distanceX = circle.X - closestX;
            var distanceY = circle.Y - closestY;

            // If the distance is less than the circle's radius, an intersection occurs
            var distanceSquared = (distanceX * distanceX) + (distanceY * distanceY);

            return(distanceSquared < (circle.Radius * circle.Radius));
        }
Exemplo n.º 16
0
        public bool CollisionCheck(RectCollider area, out List <Entity> e)
        {
            var collidedWith = new List <Entity>();

            e = collidedWith;
            foreach (var entity in Entities)
            {
                if (!entity.destroy && entity.Collider.Active && entity.Collider.Collide(area))
                {
                    collidedWith.Add(entity);
                }
            }

            return(collidedWith.Count > 0);
        }
Exemplo n.º 17
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        RectCollider rect = other.gameObject.GetComponent <RectCollider>();

        if (rect != null)
        {
            if (rect.blockType == BlockType.breakable)
            {
                Destroy(other.gameObject);
            }
            if (rect.blockType == BlockType.coinblock)
            {
                other.gameObject.GetComponent <SpriteRenderer>().sprite = aout;
            }
        }
    }
Exemplo n.º 18
0
        public void Initialize(GameServiceContainer gameServices, ContentManager content, PropertyMap propMap, Vector2 position)
        {
            Health = propMap.GetInt("Health");
            Tag    = propMap["Tag"];

            _spriteSheet = content.Load <Texture2D>(SPRITE_SHEET_PATH);

            Sprite = new Sprite(0, 0, SPRITE_SIZE, SPRITE_SIZE, _spriteSheet);

            Position = position;

            IPhysicsManager physicsManager = gameServices.GetService <IPhysicsManager>();

            this.Collider = physicsManager.CreateRectCollider(this, new Vector2(ROCK_SIZE), false);

            _debugTexture = content.Load <Texture2D>(DEBUG_TEXTURE_PATH);
        }
Exemplo n.º 19
0
        public override void Initialize()
        {
            D3D9Manager.Instance.AddMessageHandler(MsgProc);
            D3D9Manager.Instance.OnMouseClickEvent += OnMouseClick;

            if (Range == null)
            {
                if (FieldTexture != null)
                {
                    Range = new RectCollider(new Rectangle(0, 0, FieldTexture.Width, FieldTexture.Height));
                }
                else
                {
                    Range = new RectCollider(new Rectangle(0, 0, 50, 50 * MaxLength));
                }
            }
        }
Exemplo n.º 20
0
        public void Insert(RectCollider collider)
        {
            QuadTree <RectCollider> quadTree = collider.isDynamic ? dynamicQT : staticQT;

            quadTree.Insert(collider, collider.rect);
        }
Exemplo n.º 21
0
 public static void DeleteCollider(RectCollider collider)
 {
     colliders.Remove(collider);
 }
Exemplo n.º 22
0
 private bool IntersectsWith(BoxCollider boxCollider)
 {
     return(RectCollider.IntersectsWith(boxCollider.RectCollider));
 }
Exemplo n.º 23
0
 public bool CheckCollision(RectCollider rect1, RectCollider rect2)
 {
     return(rect1.Rect.Intersects(rect2.Rect));
 }
Exemplo n.º 24
0
 public void Update()
 {
     CollisionMask = new RectCollider(rect);
 }