• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ICollidable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: AddEntity

 public void AddEntity(ICollidable entity)
 {
     if (!collidableEntities.Contains(entity))
     {
         collidableEntities.Add(entity);
         hashmap.Add(new TaggedVector { Position = new Vector2(entity.Hitbox.X, entity.Hitbox.Y),Identifier = entity });
     }
 }
开发者ID:Wishf,项目名称:Fracture,代码行数:8,代码来源:CollisionManager.cs


示例17: CollisionOccured

        public override void CollisionOccured(ICollidable collisionObject)
        {
            if (collisionObject == SourceComponent) {
                return;
            }

            base.CollisionOccured(collisionObject);
        }
开发者ID:evanlong,项目名称:publicgit,代码行数:8,代码来源:BulletComponent.cs


示例18: Collider

 public Collider(ICollidable owner, Rectangle bounds, ColliderType type)
 {
     this.m_owner = owner;
     this.m_bounds = new DoubleRect(bounds.X, bounds.Y, bounds.Width, bounds.Height);
     this.m_bounds2 = new DoubleRect(bounds.X - 5, bounds.Y - 5, bounds.Width + 10, bounds.Height + 10);
     this.m_type = type;
     this.m_other = null;
 }
开发者ID:BNHeadrick,项目名称:Bros,代码行数:8,代码来源:Collider.cs


示例19: CheckCollision

        public void CheckCollision(ICollidable target)
        {
            if (target is LaserBullet)
                CheckLaserBulletCollision((LaserBullet)target);

            if (target is Ship)
                CheckShipCollision((Ship)target);
        }
开发者ID:naighes,项目名称:AsteroidChallenge,代码行数:8,代码来源:Asteroid.cs


示例20: HandleCollision

        /// <summary>
        /// Handles a collision with a ball, removes a live from a player
        /// </summary>
        /// <param name="other"></param>
        public void HandleCollision(ICollidable other)
        {
            if (other.GetType() != typeof(Ball))
                return;

            this.Player.Lives--;
            this.Level.Reset();
        }
开发者ID:thexa4,项目名称:perfectpong,代码行数:12,代码来源:DeadZone.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IColor类代码示例发布时间:2022-05-24
下一篇:
C# ICollectionView类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap