Ejemplo n.º 1
0
        /// <summary>
        /// 将弹药和附近的单位单位做碰撞检测,对是敌方且发生碰撞的最近单位造成伤害且弹药消失
        /// </summary>
        /// <param name="unit">做碰撞检测的目标</param>
        public void CheckCollision(List <VioableUnit> units)
        {
            VioableUnit hitingUnit      = null;
            float       hitingUnitRange = 0;
            Vector3     hittingPoint    = Vector3.Zero;
            Vector3?    v1;

            foreach (VioableUnit unit in units)
            {
                if (unit != null)
                {
                    if (Vector3.Distance(unit.Position, this.position) <= GameConsts.BulletCheckingRange)
                    {
                        //if (weapon.isInstant == false)
                        //{

                        //    if (bulletOver == false)
                        //    {

                        //        if (Collision.IsCollided(unit, this) && unit.Group != Group && unit.Dead != true)
                        //        {
                        //            Damage result;
                        //            result = new Damage(weapon, num);
                        //            unit.GetDamage(result);
                        //            Hit();
                        //        }

                        //    }


                        //}
                        //else{}
                        v1 = Collision.IsCollided(unit, this);
                        if (v1 != null && unit.Group != Group && unit.UnitState != UnitState.dead)
                        {
                            if (hitingUnit != null)
                            {
                                float k = Vector3.Dot(v1.Value - this.positionl, this.Face);
                                if (k < hitingUnitRange)
                                {
                                    hitingUnitRange = k;
                                    hitingUnit      = unit;
                                    hittingPoint    = v1.Value;
                                }
                            }
                            else
                            {
                                hitingUnit      = unit;
                                hitingUnitRange = Vector3.Dot(unit.Position - this.positionl, this.Face);
                                hittingPoint    = v1.Value;
                            }
                        }
                    }
                }
            }
            if (hitingUnit != null)
            {
                Damage result;
                result = new Damage(weapon, num);
                hitingUnit.GetDamage(result);
                //position = (positionl + position) / 2;
                if (hitingUnit.Model != null && position0 != position)
                {
                    Ray     br = new Ray(position0, Vector3.Normalize(position - position0));
                    Vector3?v  = hittingPoint;
                    if (v != null)
                    {
                        position  = v.Value;
                        positionl = v.Value;
                    }
                }
                Hit();
            }
        }
Ejemplo n.º 2
0
        void LoadType(GameWorld gameWorld, WeaponType weaponType)
        {
            this.singleShotWeapon       = weaponType.singleShotWeapon;
            this.damage                 = new Damage();
            this.game                   = gameWorld.game;
            this.gameWorld              = gameWorld;
            this.name                   = weaponType.weaponName;
            this.ammoName               = weaponType.ammoName;
            this.maxAmmo                = weaponType.maxAmmo;
            this.AmmoNum                = this.maxAmmo;
            this.damage.BasicDamage     = weaponType.basicDamage;
            this.damage.FoldArmor       = weaponType.foldArmor;
            this.damage.FoldShield      = weaponType.foldShield;
            this.damage.CrossValue      = weaponType.crossValue;
            this.damage.IsShieldUseless = weaponType.isShieldUseless;
            this.damage.attacker        = unit;
            this.shotSpeed              = weaponType.shotSpeed;
            this.basicSpeed             = weaponType.basicSpeed;
            this.range                  = weaponType.range;
            this.maxAngle               = weaponType.maxAngle;
            this.isInstant              = weaponType.isInstant;
            if (weaponType.shotSound != "")
            {
                shotSound         = gameWorld.Content.Load <SoundEffect>(weaponType.shotSound);
                shotSoundInstance = shotSound.CreateInstance();
            }

            if (weaponType.bulletModelName != "")
            {
                this.bulletEffectType = gameWorld.game.Content.Load <AODModelType>(weaponType.bulletModelName);
            }
            else
            {
                this.bulletEffectType = null;
            }
            this.shotSpan             = weaponType.shotSpan;
            this.isFastWeapon         = weaponType.isFastWeapon;
            this.supershotModeEnabled = weaponType.supershotModeEnabled;
            this.supershotTime        = weaponType.supershotTime;
            this.supershotEnterTime   = weaponType.supershotEnterTime;
            this.supershotCooldown    = weaponType.supershotCooldown;
            if (weaponType.shotEffectName != "")
            {
                this.shotEffect[0] = new ParticleEffect(gameWorld, gameWorld.game.Content.Load <ParticleEffectType>(weaponType.shotEffectName));
                this.shotEffect[1] = new ParticleEffect(gameWorld, gameWorld.game.Content.Load <ParticleEffectType>(weaponType.shotEffectName));

                foreach (ParticleEffect pe in shotEffect)
                {
                    if (pe != null)
                    {
                        pe.BeginToDie();
                    }
                }
            }
            if (weaponType.supershotEffectName != "")
            {
                this.superShotEffect[0] = new ParticleEffect(gameWorld, gameWorld.game.Content.Load <ParticleEffectType>(weaponType.supershotEffectName));
                this.superShotEffect[1] = new ParticleEffect(gameWorld, gameWorld.game.Content.Load <ParticleEffectType>(weaponType.supershotEffectName));
                foreach (ParticleEffect pe in superShotEffect)
                {
                    if (pe != null)
                    {
                        pe.BeginToDie();
                    }
                }
            }
            position[0]    = weaponType.positionIndex1;
            position[1]    = weaponType.positionIndex2;
            this.assetName = weaponType.AssetName;
            //if (weaponType.bulletModelName != "")
            //    this.bulletModel = new ParticleEffect(game, game.Content.Load<ParticleEffectType>(weaponType.bulletModelName));
            //else this.bulletModel = null;
        }