コード例 #1
0
ファイル: Laser.cs プロジェクト: ilexp/bmj2017-12
        void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args)
        {
            Ship otherShip = args.CollideWith.GetComponent <Ship>();

            if (otherShip == null)
            {
                return;
            }
            if (args.CollideWith == this.owner)
            {
                return;
            }
            if (otherShip.TeamColor == this.TeamColor)
            {
                return;
            }

            ColorHsva  teamColorHsva = otherShip.TeamColor.ToHsva();
            GameObject obj           = this.hitEffect.Res.Instantiate();

            obj.Transform.Pos   = this.GameObj.Transform.Pos;
            obj.Transform.Angle = this.GameObj.Transform.Angle;
            foreach (ParticleEmitter emitter in obj.GetComponent <ParticleEffect>().Emitters)
            {
                emitter.BaseVel += this.GameObj.Transform.Vel;
                emitter.MinColor = emitter.MinColor.WithHue(MathF.Lerp(emitter.MinColor.H, teamColorHsva.H, teamColorHsva.S));
                emitter.MaxColor = emitter.MaxColor.WithHue(MathF.Lerp(emitter.MaxColor.H, teamColorHsva.H, teamColorHsva.S));
            }
            this.GameObj.ParentScene.AddObject(obj);
            CameraController.ApplyScreenShake(this.GameObj.Transform.Pos, 0.05f);

            otherShip.Hit(this);
            this.GameObj.DisposeLater();
        }
コード例 #2
0
        public void Hit(Laser laser)
        {
            if (this.Disposed)
            {
                return;
            }

            this.health -= 0.2f;
            if (this.health <= 0.0f)
            {
                this.health = 0.0f;
                this.Explode();
            }
            CameraController.ApplyScreenShake(this.GameObj.Transform.Pos, 0.15f, this.GameObj);

            if (this == this.GameObj.ParentScene.FindComponent <Player>().ControlTarget)
            {
                SoundInstance sound = DualityApp.Sound.PlaySound(this.hitSound);
            }
            else
            {
                SoundInstance sound = DualityApp.Sound.PlaySound3D(this.hitSound, this.GameObj);
                sound.Volume  = 0.5f;
                sound.Lowpass = 0.75f;
            }
        }
コード例 #3
0
        public void Explode()
        {
            if (this.Disposed)
            {
                return;
            }

            ColorHsva  teamColorHsva = this.teamColor.ToHsva();
            GameObject explosionObj  = this.explosionPrefab.Res.Instantiate(this.GameObj.Transform.Pos);

            foreach (ParticleEffect effect in explosionObj.GetComponentsDeep <ParticleEffect>())
            {
                foreach (ParticleEmitter emitter in effect.Emitters)
                {
                    emitter.MinColor = emitter.MinColor.WithHue(MathF.Lerp(emitter.MinColor.H, teamColorHsva.H, teamColorHsva.S));
                    emitter.MaxColor = emitter.MaxColor.WithHue(MathF.Lerp(emitter.MaxColor.H, teamColorHsva.H, teamColorHsva.S));
                }
            }
            this.GameObj.ParentScene.AddObject(explosionObj);
            this.GameObj.DisposeLater();
            CameraController.ApplyScreenShake(this.GameObj.Transform.Pos, 1.0f);

            if (this == this.GameObj.ParentScene.FindComponent <Player>().ControlTarget)
            {
                SoundInstance sound = DualityApp.Sound.PlaySound(this.explosionSound);
            }
            else
            {
                SoundInstance sound = DualityApp.Sound.PlaySound3D(this.explosionSound, this.GameObj.Transform.Pos);
                sound.Volume  = 0.75f;
                sound.Lowpass = 0.75f;
            }

            if (this.thrusterSoundInstance != null)
            {
                this.thrusterSoundInstance.FadeOut(0.5f);
                this.thrusterSoundInstance = null;
            }
        }