Example #1
0
 public void OnCollisionBegin(Component sender, CollisionEventArgs args)
 {
     Component player = sender.GameObj.GetComponent<Player>();
     if (player.hasKey) {
         unlock();
     }
 }
Example #2
0
        void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args)
        {
            RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs;
            if (bodyArgs == null) return;
            if (bodyArgs.OtherShape.IsSensor) return;

            Bullet otherBullet = bodyArgs.CollideWith.GetComponent<Bullet>();
            int spikeIndex = this.GetSpikeIndex(bodyArgs.MyShape);
            if (spikeIndex != -1 && otherBullet == null)
            {
                this.spikeState[spikeIndex].ContactCount++;
            }

            if (this.state != MindState.Asleep)
            {
                if (spikeIndex != -1)
                {
                    if (this.spikeState[spikeIndex].OpenValue > 0.75f && otherBullet == null)
                        this.FireExplosives();
                }
                else
                {
                    if (otherBullet != null)
                    {
                        this.BlinkSpikes(MathF.Rnd.NextFloat(0.5f, 1.0f));
                        this.BlinkEye(MathF.Rnd.NextFloat(0.35f, 0.6f));
                    }
                }
            }
        }
Example #3
0
 void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args)
 {
     if (args.CollideWith.GetComponent<Asteroid>() != null)
     {
         // GAME OVER MAN. GAME OVER.
         this.Die();
     }
     else
     {
         Powerup powerup = args.CollideWith.GetComponent<Powerup>();
         if (powerup != null)
         {
             powerup.NotifyCollect();
             switch (powerup.Type)
             {
                 case PowerupType.FrontCannon:
                     this.powerFront++;
                     break;
                 case PowerupType.DiagonalCannon:
                     this.powerDiagonal++;
                     break;
                 case PowerupType.SideCannon:
                     this.powerSide++;
                     break;
                 case PowerupType.KillAll:
                     Asteroid[] asteroids = Asteroid.Instances.ToArray();
                     foreach (Asteroid a in asteroids)
                         a.Die();
                     break;
             }
         }
     }
 }
Example #4
0
		void ICmpCollisionListener.OnCollisionSolve(Component sender, CollisionEventArgs args)
		{
			RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs;
			if (bodyArgs.MyShape.IsSensor) return;
			if (bodyArgs.OtherShape.IsSensor) return;

			float impactStrength = bodyArgs.CollisionData.NormalImpulse / (4.0f * bodyArgs.MyShape.Parent.Mass);
			this.NotifyHit(MathF.Pow(impactStrength, 1.5f));
		}
Example #5
0
        void ICmpCollisionListener.OnCollisionEnd(Component sender, CollisionEventArgs args)
        {
            // We'll watch for RigidBody collisions
            RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs;
            if (bodyArgs == null) return;

            if (this.sensorOnly && !bodyArgs.MyShape.IsSensor) return;
            this.collisionCount--;
        }
 public void OnCollisionBegin(Component sender, CollisionEventArgs args)
 {
     if(args is RigidBodyCollisionEventArgs)
     {
         if((args as RigidBodyCollisionEventArgs).MyShape == groundDetecion)
         {
             IsTouchingGround = true;
             activeCollisions++;
         }
     }
 }
		void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args)
		{
			Asteroid asteroid = args.CollideWith.GetComponent<Asteroid>();
			if (asteroid != null)
			{
				asteroid.NotifyHitBy(this);
				args.CollideWith.Collider.ApplyWorldImpulse(this.GameObj.Transform.Vel.Xy.Normalized * 0.01f, this.GameObj.Transform.Pos.Xy);
				SoundInstance sound = DualityApp.Sound.PlaySound3D(GameRes.Data.Sound.HitWeapon_Sound, this.GameObj.Transform.Pos);
				sound.Pitch = MathF.Rnd.NextFloat(0.6f, 1.5f);
				this.GameObj.DisposeLater();
			}
		}
 public void OnCollisionBegin(Component sender, CollisionEventArgs args)
 {
     Health health = (Health)sender.GameObj.GetComponent(typeof(Health));
     if(health != null)
     {
         health.ApplyDamage(Damage);
     }
     if(DestroyOnCollision)
     {
         GameObj.RemoveComponent(this);
     }
 }
 public void OnCollisionEnd(Component sender, CollisionEventArgs args)
 {
     if (args is RigidBodyCollisionEventArgs)
     {
         if ((args as RigidBodyCollisionEventArgs).MyShape == groundDetecion)
         {
             activeCollisions--;
             if(activeCollisions == 0)
             {
                 IsTouchingGround = false;
             }
         }
     }
 }
        void ICmpCollisionListener.OnCollisionSolve(Component sender, CollisionEventArgs args)
        {
            // We'll watch for RigidBody collisions
            RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs;
            if (bodyArgs == null) return;

            if (bodyArgs.CollisionData.NormalImpulse > 0.5f)
            {
                // Create a hit particle
                GameObject hitParticle = GameRes.Data.Misc.HitParticle_Prefab.Res.Instantiate();
                hitParticle.Transform.Pos = this.GameObj.Transform.Pos + new Vector3(bodyArgs.CollisionData.Pos);
                hitParticle.Transform.Scale = Vector3.One * MathF.Sqrt(bodyArgs.CollisionData.NormalImpulse);
                hitParticle.GetComponent<SpriteRenderer>().ColorTint = new ColorRgba(255, 128, 128);
                Scene.Current.RegisterObj(hitParticle);
            }
        }
Example #11
0
        void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args)
        {
            // We'll watch for RigidBody collisions
            RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs;
            if (bodyArgs == null) return;

            if (bodyArgs.CollideWith.GetComponent<EnemyComponent>() != null)
            {
                Client.combatScene(GameRes.Data.Sprites.Desert_Material, this.PlayerParty, bodyArgs.CollideWith.GetComponent<EnemyComponent>().Creatures);
            }
            /*else if (bodyArgs.CollideWith.GetComponent<NPCComponent>() != null)
            {
                Client.combatScene(GameRes.Data.Sprites.Desert_Material, this.PlayerParty, bodyArgs.CollideWith.GetComponent<NPCComponent>().Creatures);
            }*/
            else
            {
                return;
            }

            bodyArgs.CollideWith.Active = false;
            bodyArgs.CollideWith.DisposeLater();
        }
Example #12
0
        void ICmpCollisionListener.OnCollisionSolve(Component sender, CollisionEventArgs args)
        {
            if (args.CollisionData.NormalSpeed > 1.0f && this.GameObj.Transform.Vel.Length > 0.5f)
            {
                SoundInstance collisionSound = DualityApp.Sound.PlaySound(GameRes.Data.Sound.BlockCollide_Sound);
                collisionSound.Pitch = MathF.Rnd.NextFloat(0.8f, 1.25f);
                collisionSound.Volume = MathF.Clamp(args.CollisionData.NormalSpeed / 5.0f, 0.0f, 0.5f);
            }

            if (activeBlock == this && timeFirstContact == 0.0f && MathF.Abs(args.CollisionData.Normal.Y) > 0.05f)
            {
                this.timeFirstContact = Time.GameTimer;
                this.angleFirstTimeHit = this.GameObj.Transform.Angle;
                if (this.GameObj.Transform.Pos.Y <= -500) GameController.Instance.NotifyGameOver();
                this.GameObj.GetComponent<Collider>().IgnoreGravity = false;
                this.GameObj.GetComponent<Collider>().FixedAngle = false;
            }

            if (this.timeFirstContact != 0.0f && Time.GameTimer - timeFirstContact < 3000.0f && this.GameObj.Transform.Vel.Length <= 0.1f)
            {
                float angleDistFromSetup = MathF.CircularDist(this.angleFirstTimeHit, this.GameObj.Transform.Angle);
                if (angleDistFromSetup >= MathF.Pi * 0.1f) GameController.Instance.NotifyBlockFellOver(this.GameObj);
            }
        }
Example #13
0
 public void OnCollisionSolve(Component sender, CollisionEventArgs args)
 {
 }
Example #14
0
		void ICmpCollisionListener.OnCollisionEnd(Component sender, CollisionEventArgs args)
		{
			RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs;
			if (bodyArgs == null) return;
			if (bodyArgs.OtherShape.IsSensor) return;
			
			Bullet otherBullet = bodyArgs.CollideWith.GetComponent<Bullet>();
			int spikeIndex = this.GetSpikeIndex(bodyArgs.MyShape);
			if (spikeIndex != -1 && otherBullet == null)
			{
				this.spikeState[spikeIndex].ContactCount--;
			}
		}
Example #15
0
 public void OnCollisionBegin(Component sender, CollisionEventArgs args)
 {
     Component player = sender.GameObj.GetComponent<Player>();
     player.hasKey = true;
     destroyKey();
 }
Example #16
0
		void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args)
		{
			this.AddCollision(args.CollideWith);
		}
Example #17
0
		void ICmpCollisionListener.OnCollisionEnd(Component sender, CollisionEventArgs args)
		{
			this.RemoveCollision(args.CollideWith);
		}
Example #18
0
 void ICmpCollisionListener.OnCollisionSolve(Component sender, CollisionEventArgs args)
 {
     // nothing to do here
 }
Example #19
0
 public void OnCollisionSolve(Component sender, CollisionEventArgs args)
 {
     throw new NotImplementedException();
 }
 public virtual void CollisionSolve(CollisionEventArgs args)
 {
 }
 void ICmpCollisionListener.OnCollisionEnd(Component sender, CollisionEventArgs args)
 {
     // We'll watch for RigidBody collisions
     RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs;
     if (bodyArgs == null) return;
 }
 public virtual void CollisionBegin(CollisionEventArgs args)
 {
 }
 public virtual void CollisionEnd(CollisionEventArgs args)
 {
 }
Example #24
0
 void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args)
 {
     // did the player hit a gate sensor? +1 point)
     if (!this.isDead && args.CollideWith.GetComponent<RigidBody>().CollisionCategory == CollisionCategory.Cat2)
     {
         // remove the sensor..
         args.CollideWith.RemoveComponent<RigidBody>();
         this.points++;
     }
     else
     {
         // otherwise, you're dead!
         this.isDead = true;
         Body.AnimFirstFrame = 2;
     }
 }
Example #25
0
 public void OnCollisionEnd(Component sender, CollisionEventArgs args)
 {
     canJump = false;
 }
Example #26
0
 public void OnCollisionBegin(Component sender, CollisionEventArgs args)
 {
     if(args.CollideWith.Name.Equals("TopBlock") || args.CollideWith.Name.Equals("TopHorizontalBlock"))
     {
         canJump = true;
     }
 }
Example #27
0
 void ICmpCollisionListener.OnCollisionSolve(Component sender, CollisionEventArgs args)
 {
 }
Example #28
0
 public void OnCollisionBegin(Component sender, CollisionEventArgs args)
 {
     //you win!
 }
Example #29
0
        void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args)
        {
            RigidBodyCollisionEventArgs bodyArgs = args as RigidBodyCollisionEventArgs;
            if (bodyArgs == null) return;
            if (bodyArgs.OtherShape.IsSensor) return;

            // Did we collide with a ship? If it's the same that fired the bullet, ignore this
            Ship otherShip = args.CollideWith.GetComponent<Ship>();
            if (otherShip != null && otherShip.Owner == this.owner) return;

            // Get all the objet references we'll need
            RigidBody		otherBody	= args.CollideWith.RigidBody;
            Transform		transform	= this.GameObj.Transform;
            RigidBody		body		= this.GameObj.RigidBody;
            BulletBlueprint	blueprint	= this.blueprint.Res;

            // Okay, let's determine where *exactly* our bullet hit
            RayCastData firstHit;
            bool hitAnything = RigidBody.RayCast(transform.Pos.Xy - body.LinearVelocity * 2, transform.Pos.Xy + body.LinearVelocity * 2, data =>
            {
                if (data.Shape.IsSensor) return -1.0f;
                return data.Fraction;
            }, out firstHit);

            Vector3 hitPos;
            float hitAngle;
            if (hitAnything)
            {
                hitPos = new Vector3(firstHit.Pos, 0.0f);
                hitAngle = (-firstHit.Normal).Angle;
            }
            else
            {
                // Note that it is possible for the raycast to not hit anything,
                // because it is essentially a line, while our bullet is wider than zero.
                hitPos = transform.Pos;
                hitAngle = transform.Angle;
            }

            // Push around whatever we've just hit and do damage, if it was a ship
            otherBody.ApplyWorldImpulse(body.LinearVelocity * MathF.Min(otherBody.Mass, blueprint.ImpactMass), transform.Pos.Xy);
            if (otherShip != null)
            {
                otherShip.DoDamage(blueprint.Damage);
            }

            // If we hit a part of the world, spawn the world hit effect
            if (otherShip == null && blueprint.HitWorldEffect != null)
            {
                GameObject effectObj = blueprint.HitWorldEffect.Res.Instantiate(hitPos, hitAngle);
                Scene.Current.AddObject(effectObj);
            }

            // Also spawn a generic hit effect in the color of the bullet
            if (blueprint.HitEffect != null)
            {
                GameObject effectObj = blueprint.HitEffect.Res.Instantiate(hitPos, hitAngle);
                ParticleEffect effect = effectObj.GetComponent<ParticleEffect>();
                if (effect != null && this.owner != null)
                {
                    ColorHsva color = this.owner.Color.ToHsva();
                    foreach (ParticleEmitter emitter in effect.Emitters)
                    {
                        emitter.MaxColor = emitter.MaxColor.WithSaturation(color.S).WithHue(color.H);
                        emitter.MinColor = emitter.MinColor.WithSaturation(color.S).WithHue(color.H);
                    }
                }
                Scene.Current.AddObject(effectObj);
            }

            // Play hit sounds
            if (blueprint.HitSound != null)
            {
                SoundInstance inst = DualityApp.Sound.PlaySound3D(blueprint.HitSound, hitPos);
                inst.Pitch = MathF.Rnd.NextFloat(0.95f, 1.05f);
            }
            HitSoundController otherHitSound = otherBody.GameObj.GetComponent<HitSoundController>();
            if (otherHitSound != null)
            {
                otherHitSound.NotifyHit(MathF.Rnd.NextFloat(0.75f, 1.0f));
            }

            // Delete the bullet
            this.GameObj.DisposeLater();
        }
Example #30
0
 public void OnCollisionEnd(Component sender, CollisionEventArgs args)
 {
     //stub
 }