コード例 #1
0
        private IList<int> GetIdForObj(GameObject obj)
        {
            var bucketsObjIsIn = new LinkedList<int>();

            Vector2 min = new Vector2(
                obj.GetPosition().X - (obj.GetMaxRadius()),
                obj.GetPosition().Y - (obj.GetMaxRadius()));

            Vector2 max = new Vector2(
                obj.GetPosition().X + (obj.GetMaxRadius()),
                obj.GetPosition().Y + (obj.GetMaxRadius()));

            float width = Cols;

            //TopLeft
            AddBucket(min, width, bucketsObjIsIn);

            //TopRight
            AddBucket(new Vector2(max.X, min.Y), width, bucketsObjIsIn);

            //BottomRight
            AddBucket(new Vector2(max.X, max.Y), width, bucketsObjIsIn);

            //BottomLeft
            AddBucket(new Vector2(min.X, max.Y), width, bucketsObjIsIn);

            return bucketsObjIsIn;
        }
コード例 #2
0
 public void AddObject(GameObject obj)
 {
     var cellIds = GetIdForObj(obj);
     foreach (var item in cellIds)
     {
         Buckets.Get(item).Add(obj);
     }
 }
コード例 #3
0
ファイル: Tile.cs プロジェクト: ThaH3lper/AD_Project
        public override bool Blocks(GameObject other)
        {
            if (type == ETileType.WALL || type == ETileType.CRATE)
            {
                if (other is Bullet)
                    ((Bullet)other).CheckKill(this);

                return true;
            }
            return false;
        }
コード例 #4
0
        public override bool Blocks(GameObject other)
        {
            if (other is Tile)
            {
                Tile t = other as Tile;
                if (t.GetTileType() == ETileType.CRATE)
                    return false;
            }

            return owner != other;
        }
コード例 #5
0
ファイル: Entity.cs プロジェクト: ThaH3lper/AD_Project
        public override bool Blocks(GameObject other)
        {
            if (other is Entity)
                return true;

            if (other is Bullet)
            {
               return !((Bullet)other).CheckKill(this);
            }

            return true;
        }
コード例 #6
0
        public override bool Blocks(GameObject other)
        {
            if (other is Entity)
                return true;

            if (other is Tile)
            {
                if(((Tile)other).GetTileType() == ETileType.SPAWN) {
                    ResetHealth();
                    return false;
                }
            }

            if (other is Bullet)
            {
               return !((Bullet)other).CheckKill(this);
            }

            return true;
        }
コード例 #7
0
        public bool CheckKill(GameObject obj)
        {
            if (obj != owner)
            {
                if ( obj is Tile)
                {
                    Tile t = obj as Tile;
                    if (t.GetTileType() == ETileType.CRATE)
                    {
                        color = Color.Blue;
                        speed *= 0.9f;
                        damage *= 0.8f;
                        return true;
                    }
                }

                Dead = true;
                return true;

            }
            return false;
        }
コード例 #8
0
ファイル: GameObject.cs プロジェクト: ThaH3lper/AD_Project
 public virtual bool Blocks(GameObject other)
 {
     return false;
 }
コード例 #9
0
 public void AddText(GameObject entity , string text)
 {
     Texts.Add(new WorldText() { Entity = entity, Text = text, TimeLeft = 3, Offset = new Vector2(-100 + new Random().Next(100) - 50, -50 + new Random().Next(100) - 50) });
 }
コード例 #10
0
        public bool RayCast(GameObject origin, GameObject target)
        {
            var segment = new Segment(origin.GetPosition(), target.GetPosition());

            for (int y = 0; y < Map.getTileMap().GetLength(0); y++)
            {
                for (int x = 0; x < Map.getTileMap().GetLength(1); x++)
                {
                    if (Map.getTileMap()[x, y].GetTileType() != ETileType.WALL) // && Map.getTileMap()[x, y].GetType() != ETileType.CREATE)
                        continue;

                    if (segment.Collide(Map.getTileMap()[x, y].GetRecHit()))
                        return false;
                }
            }

            // Should enemies block raycast?
            foreach (var enemy in Enemies.Where(x => x != origin))
            {
                if (segment.Collide(enemy.GetHitRectangle()))
                    return false;
            }
            return true;
        }
コード例 #11
0
ファイル: BaseEnemy.cs プロジェクト: ThaH3lper/AD_Project
 public override bool Blocks(GameObject other)
 {
     return base.Blocks(other);
 }
コード例 #12
-1
 public GameObject[] GetPossibleColliders(GameObject obj)
 {
     var objects = new LinkedList<GameObject>();
     var bucketIds = GetIdForObj(obj);
     foreach (var item in bucketIds)
     {
         objects.AddRange(Buckets.Get(item));
     }
     return objects.Distinct().ToArray();
 }
コード例 #13
-2
        public System.Collections.Generic.ICollection<GameObject> GetColliders(GameObject obj)
        {
            IList<GameObject> colliders = new LinkedList<GameObject>();

            // Get all possible colliders exept myself and bullets
            colliders.AddRange(collisionCuller.GetPossibleColliders(obj).Where(x => x != obj));

            // Add tiles collisions
            var tileColliders = Map.GetPossibleColliders(obj.GetHitRectangle());
            colliders.AddRange(tileColliders);

            // At last only return those who intersects
            return colliders.Where(x => x.GetHitRectangle().Intersects(obj.GetHitRectangle()) && (x.Blocks(obj) || obj.Blocks(x))).ToList();

        }