当前位置: 首页>>代码示例>>C#>>正文


C# ICollidable类代码示例

本文整理汇总了C#中ICollidable的典型用法代码示例。如果您正苦于以下问题:C# ICollidable类的具体用法?C# ICollidable怎么用?C# ICollidable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ICollidable类属于命名空间,在下文中一共展示了ICollidable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Update

        /// <summary>
        /// Frame Renewal, move actors and detect collisions
        /// </summary>
        /// <param name="gameTime">Snapshot of Timing values</param>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            ICollidable[] activeCollidables = new ICollidable[_collidables.Count];
            _collidables.CopyTo(activeCollidables);

            foreach (ICollidable collider in activeCollidables)
            {
                foreach (ICollidable collidee in activeCollidables)
                {
                    if (collider.Equals(collidee))
                        continue;

                    // Boundingbox intersection using demorgen to see if two collidables overlap
                    if (collider.Position.X < (collidee.Position.X + collidee.Size.X) &&
                        (collider.Position.X + collider.Size.X) > collidee.Position.X &&
                        collider.Position.Y < (collidee.Position.Y + collidee.Size.Y) &&
                        (collider.Position.Y + collider.Size.Y) > collidee.Position.Y)
                        {
                            collider.HandleCollision(collidee);
                        }
                }
            }
        }
开发者ID:thexa4,项目名称:perfectpong,代码行数:29,代码来源:CollisionManager.cs

示例2: Collided

        public override void Collided(ICollidable i_Collidable)
        {
            Bullet bullet = i_Collidable as Bullet;
            Enemy enemy = i_Collidable as Enemy;
            Sprite collidableSprite = i_Collidable as Sprite;
            List<Vector2> collidedPoints;
            bool autoPixelClear = true;
            if (bullet != null)
            {
                CollisionServices.eCollisionDirection collisionDirection = m_CollisionServices.GetCollisionDirection(this, collidableSprite);
                int halfBulletHeight = (int)(bullet.Height * 0.55);
                if (m_CollisionServices.IsPixelsIntersect(this, collidableSprite, out collidedPoints, !autoPixelClear))
                {
                    m_HitSound.Play();
                    Sprite barrier = this as Sprite;
                    m_CollisionServices.ClearPixelsInVerticalDirection(ref barrier, collidedPoints, collisionDirection, halfBulletHeight);
                    this.GameScreen.Remove(bullet);
                    bullet.Dispose();
                }
            }

            if (enemy != null)
            {
                m_CollisionServices.IsPixelsIntersect(this, collidableSprite, out collidedPoints, autoPixelClear);
            }
        }
开发者ID:barcohen10,项目名称:Space-Invaders,代码行数:26,代码来源:Barrier.cs

示例3: HasCollided

 /// <summary>
 /// Determines whether the specified _other has collided.
 /// @see AddAsteroid
 /// @see CalculateNewRotations
 /// </summary>
 /// <param name="_other">The _other.</param>
 public override void HasCollided(ICollidable _other)
 {
     if (_other.GetType() == typeof(MediumAsteroid))
     {
         if (isMergeable)
         {
             drawn = false;
             MediumAsteroid other = (MediumAsteroid)_other;
             other.isMergeable = false;
             other.drawn = false;
             foreach (IObjectAdderObserver observer in objectObservers)
             {
                 observer.AddAsteroid(AsteroidFactory.createNewAsteroid(1, position, RandomGenerator.GetRandomFloat(0, 6.283)));
             }
         }
     }
     else if (_other.GetType() == typeof(Bullet))
     {
         drawn = false;
         float[] rotationsValue = CalculateNewRotations(this, (Bullet)_other);
         foreach (IObjectAdderObserver observer in objectObservers)
         {
             observer.AddAsteroid(AsteroidFactory.createNewAsteroid(3, position, rotationsValue[0] + Rotation));
             observer.AddAsteroid(AsteroidFactory.createNewAsteroid(3, position, rotationsValue[1] + Rotation));
         }
     }
 }
开发者ID:SamuelDaigle,项目名称:TP1-Asteroids,代码行数:33,代码来源:MediumAsteroid.cs

示例4:

 void IBlockState.Collide(ICollidable otherObject)
 {
     if (CollisionHelper.GetCollisionSide(block, otherObject) == CollisionSide.Top)
     {
         otherObject.TakeDamage(otherObject, 0);
     }
 }
开发者ID:CtrlC-CtrlV,项目名称:megaman-mario,代码行数:7,代码来源:BlockCollidingState.cs

示例5: Collider

 public Collider(ICollidable owner, Rectangle bounds, ColliderType type, int npc_id)
 {
     this.m_owner = owner;
     this.m_bounds = new DoubleRect(bounds.X, bounds.Y, bounds.Width, bounds.Height);
     this.m_type = type;
     this.m_npc_id = npc_id;
 }
开发者ID:gripp,项目名称:psychic-octo-nemesis,代码行数:7,代码来源:Collider.cs

示例6: CanCollide

        public override bool CanCollide(ICollidable object1, ICollidable object2)
        {
            ICollidableCircle typeCorrectedObject1 = object1 as ICollidableCircle;
            ICollidableCircle typeCorrectedObject2 = object2 as ICollidableCircle;

            return (typeCorrectedObject1 != null && typeCorrectedObject2 != null);
        }
开发者ID:Creou,项目名称:CollisionLib,代码行数:7,代码来源:CircleToCircleCollider.cs

示例7: Collided

        public void Collided(ICollidable other)
        {
            if (other == _world)
            {
                //Console.WriteLine("Velocity " + _fsBody.LinearVelocity.Y);
                if (Math.Abs(_fsBody.LinearVelocity.Y) < 1 && behaviorState == BehaviorState.Flying)
                {
                    this.behaviorState = BehaviorState.Walking;
                }
                else if (_fsBody.LinearVelocity.Y < -20 && behaviorState == BehaviorState.Flying)
                {
                    this.behaviorState = BehaviorState.Dead;
                    myCorpse.SetAnimationState(CivvieSprite.AnimationState.Dead);
                }

                if (this.behaviorState == BehaviorState.Dead)
                {
                    _world.StopPhysicsing(_fsBody);
                }
            }

            if (other is CivvieController)
            {
                var otherCivvie = other as CivvieController;
                if (otherCivvie._fsBody.LinearVelocity.Length() > 50)
                {
                    otherCivvie.Die();
                    this.Die();
                }
            }
        }
开发者ID:ohwillie,项目名称:demon_door,代码行数:31,代码来源:CivvieController.cs

示例8: ActivateBlock

 public override bool ActivateBlock(Vector2 direction, ICollidable ob)
 {
     
     Mario mario = ob as Mario;
     if(mario != null) mario.Kill();
     return true;
 }
开发者ID:rpwachowski,项目名称:SMBClone,代码行数:7,代码来源:KillBlockState.cs

示例9: ActivateBlock

        public override bool ActivateBlock(Vector2 direction, ICollidable ob)
        {

            IMario sender = ob as IMario;

            if (ob == null) return false;
            if (!(direction.Y > Utility.ZERO)) return false;
            
            if (sender != null && sender.IsBig())
            {
                SoundManager.PlayBreakingSound();
                SprintFourGame.GetInstance().Components.Remove(Block);
                if(!SprintFourGame.GetInstance().LevelIsInfinite)
                    Levels.Level.BlockGrid[(int)Block.Position.X / Utility.BLOCK_POSITION_SCALE, (int)Block.Position.Y / Utility.BLOCK_POSITION_SCALE] = new NullBlock();
            } 
            else 
            {
                nudged = true;
                delay = Utility.DELAY;
            }
            Block.Position = new Vector2(Block.Position.X, Block.Position.Y - Utility.BLOCK_NUDGED_DISTANCE);
            foreach (IEnemy enemy in CollisionDetectionManager.EnemyList.Where(enemy => enemy.Bounds.Intersects(Block.Bounds))) { 
                enemy.Kill();
                SoundManager.PlayKickSound();
                }
            return true;
        }
开发者ID:rpwachowski,项目名称:SMBClone,代码行数:27,代码来源:BrickBlockState.cs

示例10: PrimitiveLine

        /// <summary>
        /// Creates a new primitive line object.
        /// </summary>
        public PrimitiveLine(ICollidable obj = null)
        {
            // create pixels
            pixel = new Texture2D(G.Game.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            var pixels = new Color[1];
            pixels[0] = Color.White;
            pixel.SetData(pixels);

            Colour = Color.White;
            Position = new Vector2(0, 0);
            Depth = 0;

            vectors = new ArrayList();

            if (obj != null)
            {
                switch (obj.Shape.Type)
                {
                    case ShapeType.Circle:
                        CreateCircle((Circle) obj.Shape);
                        break;
                    case ShapeType.Rectangle:
                        CreateRectangle((Rectangle) obj.Shape);
                        break;
                }
                shape = obj.Shape;
                this.obj = obj;
            }
        }
开发者ID:DJSymBiotiX,项目名称:BType2,代码行数:32,代码来源:Primitives.cs

示例11: OnCollision

 // handles specific collisonbehaviour
 public void OnCollision(ICollidable collidable) {
     if (_t2.ElapsedMilliseconds <= 300) return;
     if (!(collidable is Apple)){
         SendDeath(this);
     }
     Body.Add(new Vector2D(Body[Body.Count - 1].X, Body[Body.Count - 1].Y));
 }
开发者ID:mikand13,项目名称:school_portfolio,代码行数:8,代码来源:Snake.cs

示例12: CollilisionPair

        public CollilisionPair(ICollidable object1, ICollidable object2)
        {
            if (object1 == object2) { throw new InvalidOperationException("Cannot collide an object with itself."); }

            this.Object1 = object1;
            this.Object2 = object2;
        }
开发者ID:Creou,项目名称:CollisionLib,代码行数:7,代码来源:CollilisionPair.cs

示例13: Add

        public void Add(ICollidable obj)
        {
            if(!IsDivided())
            {
                Objects.Add(obj);

                if (obj.Primary)
                    PrimaryCount++;

                if (PrimaryCount > 0 && Objects.Count > Threshold && Divide())
                {
                    Add(Objects);
                    Objects.Clear();
                }

            }
            else
            {
                for (int i = 0; i < Children.Length; i++)
                {
                    if (Children[i].Enabled && Children[i].QuadIntersects(obj.Shape))
                    {
                        Children[i].Add(obj);
                    }
                }
            }
        }
开发者ID:DJSymBiotiX,项目名称:BType2,代码行数:27,代码来源:QuadTree.cs

示例14: Collided

        public override void Collided(ICollidable i_Collidable)
        {
            PixelSensitiveSprite pixelSensitiveSpriteHitRectangle = i_Collidable as PixelSensitiveSprite;
            if (pixelSensitiveSpriteHitRectangle is Bullet)
            {
                Rectangle bulletHitRectangle;
                if (pixelSensitiveSpriteHitRectangle.Velocity.Y < 0)
                {
                    bulletHitRectangle = new Rectangle(pixelSensitiveSpriteHitRectangle.Bounds.Left,
                        (int)(pixelSensitiveSpriteHitRectangle.Bounds.Top - k_BulletHitPercentage * pixelSensitiveSpriteHitRectangle.Bounds.Height), pixelSensitiveSpriteHitRectangle.Bounds.Width,
                        (int)(pixelSensitiveSpriteHitRectangle.Bounds.Height));

                }
                else
                {
                    bulletHitRectangle = new Rectangle(pixelSensitiveSpriteHitRectangle.Bounds.Left,
                        (int)(pixelSensitiveSpriteHitRectangle.Bounds.Top + k_BulletHitPercentage * pixelSensitiveSpriteHitRectangle.Bounds.Height), pixelSensitiveSpriteHitRectangle.Bounds.Width,
                        (int)(pixelSensitiveSpriteHitRectangle.Bounds.Height));

                }

                handleSpriteCollision(pixelSensitiveSpriteHitRectangle, bulletHitRectangle);
                m_SoundManager.PlaySoundEffect(Sounds.k_BarrierHit);
                onBarrierHit();
            }

            Invader invader = i_Collidable as Invader;
            if (invader != null)
            {
                RemoveFromTexture(invader.Bounds);
                onBarrierHit();
            }

            Texture.SetData(Pixels);
        }
开发者ID:BorisBorshevsky,项目名称:MonoGameSpaceInvanders,代码行数:35,代码来源:Barrier.cs

示例15: CheckForCollision

            /// <summary>
            /// Determines if two objects have collided using Axis-Aligned Bounding Box
            /// </summary>
            /// <param name="first">The first object to check.</param>
            /// <param name="second">The second object to check.</param>
            /// <returns>True if a collision was detected, false otherwise.</returns>
            /// <remarks>
            /// https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection
            ///
            ///    Ax,Ay                    Bx,By
            ///      ---------------          ---------------
            ///      -             -          -             -
            ///      -             -          -             -
            ///      -             -          -             -
            ///      -             -          -             -
            ///      ---------------          ---------------
            ///                  AX,AY                     BX,BY
            ///
            /// They are seperate if any of these statements are true:
            ///
            ///  AX is less than Bx
            ///  BX is less than Ax
            ///  AY is less than By
            ///  BY is less than Ay
            ///
            /// </remarks>
            public static CollisionResult CheckForCollision(ICollidable first, ICollidable second, Vector2 velocity)
            {
                if (first == null)
                                {
                                        throw new ArgumentNullException("first");
                                }

                                if (second == null)
                                {
                                        throw new ArgumentNullException("second");
                                }

                                Rectangle a = first.BoundingBox;
                                Rectangle b = second.BoundingBox;

                                //bool haveCollided = !(a.Right < b.X
                                //         || b.Right < a.X
                                //         || a.Bottom < b.Y
                                //         || b.Bottom < a.Y);

                                bool haveCollided = (a.Right > b.X && b.Right > a.X && a.Bottom > b.Y && b.Bottom > a.Y);

                                a.Offset(Convert.ToInt32(velocity.X), Convert.ToInt32(velocity.Y));
                                bool willCollided = (a.Right > b.X && b.Right > a.X && a.Bottom > b.Y && b.Bottom > a.Y);

                                CollisionResult collisionResult = new CollisionResult();
                                collisionResult.HaveCollided = haveCollided;
                                collisionResult.WillCollide = willCollided;
                                collisionResult.CorrectionVector = null;
                                return collisionResult;
            }
开发者ID:TheProjecter,项目名称:xna-space-invaders,代码行数:57,代码来源:CollisionDetection.AxisAlignedBoundingBoxes.cs


注:本文中的ICollidable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。