本文整理汇总了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);
}
}
}
}
示例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);
}
}
示例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));
}
}
}
示例4:
void IBlockState.Collide(ICollidable otherObject)
{
if (CollisionHelper.GetCollisionSide(block, otherObject) == CollisionSide.Top)
{
otherObject.TakeDamage(otherObject, 0);
}
}
示例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;
}
示例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);
}
示例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();
}
}
}
示例8: ActivateBlock
public override bool ActivateBlock(Vector2 direction, ICollidable ob)
{
Mario mario = ob as Mario;
if(mario != null) mario.Kill();
return true;
}
示例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;
}
示例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;
}
}
示例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));
}
示例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;
}
示例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);
}
}
}
}
示例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);
}
示例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