Пример #1
0
    void Update()
    {
        // 3 - Retrieve axis information
        float inputX = Input.GetAxis("Horizontal");
        float inputY = Input.GetAxis("Vertical");

        // 4 - Movement per direction
        movement = new Vector2(
            speed.x * inputX,
            speed.y * inputY);

        // 5 - Shooting
        bool shoot = Input.GetButtonDown("Fire1");

        shoot |= Input.GetButtonDown("Fire2");
        // Careful: For Mac users, ctrl + arrow is a bad idea

        if (shoot)
        {
            WeaponProjectile weapon = GetComponent <WeaponProjectile>();
            if (weapon != null)
            {
                // false because the player is not an enemy
                weapon.Attack(false);
            }
        }
    }
 /** Adds a weapon's projectile to the pool and sets it inactive. */
 public void AddProjectileToPool(WeaponProjectile proj)
 {
     if( projectiles != null && proj != null )
     {
         proj.transform.SetParent( transform );
         projectiles.Add( proj );
     //			proj.gameObject.SetActive( false );
     }
 }
Пример #3
0
    protected override void OnActivate()
    {
        // Spawn Rose
        WeaponProjectile rose = roseProjectile.Spawn(GM.PlayerPos, Quaternion.identity);

        rose.InitData(CamManager.Inst.MainCam.ScreenToWorldPoint(Input.mousePosition) - GM.PlayerPos, roseProjectileData);

        // Deactivate Item
        Deactivate();
    }
    public float hitRateRange = 3; // How many degrees that the aim can vary.

    public override void Attack(UnitRoot target, UnitRoot attacker)
    {
        int damage = GetDamageRoll();

        WeaponProjectile weaponProjectile = Instantiate(projectilePrefab.gameObject).GetComponent <WeaponProjectile>();

        weaponProjectile.transform.position = this.transform.position;

        weaponProjectile.Set(damage, baseStats.forceValue, hitRateRange, target, attacker);
    }
Пример #5
0
        private void Shoot()
        {
            timeBetweenShots = 0f;
            Debug.Log("Shoot!");
            WeaponProjectile instance = gun.projectiles.popOrCreate(gun.weapon.projectile.prefab.GetComponent <WeaponProjectile>(), barrelEnd.transform.position, Quaternion.identity);

            instance.gameObject.SetActive(true);
            instance.transform.parent = owner.transform.parent;
            instance.gun = gun;
            Physics.IgnoreCollision(instance.GetComponent <Collider>(), GetComponent <Collider>());
            instance.Launch(barrelEnd.transform.position, barrelEnd.transform.forward);
            gun.playTriggerSound();
        }
Пример #6
0
    private void OnCastComplete()
    {
        // Stop the active effect once we cast
        if (this.activeEffect != null)
        {
            this.activeEffect.Stop();
        }

        // Create the projectile
        if (this.Projectile != null)
        {
            WeaponProjectile.Create(
                this.Projectile,
                this,
                this.LaunchPoint,
                (this.currentDirection == Direction.Left ? -1 : 1));
        }
    }
Пример #7
0
        public static WeaponBase Read(this NetworkReader reader)
        {
            WeaponType weaponType = (WeaponType)reader.ReadByte();

            switch (weaponType)
            {
            case WeaponType.Default:
                return(WeaponDefault.OnDeserialize(reader));

            case WeaponType.Melee:
                return(WeaponMelee.OnDeserialize(reader));

            case WeaponType.Projectile:
                return(WeaponProjectile.OnDeserialize(reader));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #8
0
    void DoShot()
    {
        MuzzleSource.clip = ShotAudio;
        MuzzleSource.Play();
        switch (ProjT)
        {
        case ProjectileType.Direct:

            var np = GameObject.Instantiate <GameObject>(ProjBase.gameObject) as GameObject;
            np.transform.position = MuzzleBase.transform.position;
            np.transform.rotation = MuzzleBase.transform.rotation;
            var wp = new WeaponProjectile();
            wp.Speed      = 5.0f;
            wp.Projectile = np.transform;
            WeaponMan.Projectiles.Add(wp);


            break;
        }
        Debug.Log("Shot!");
    }
    public static WeaponProjectile Create(WeaponProjectile instance, SpriteCharacterController owner, Transform launchPoint, int directionX)
    {
        WeaponProjectile projectile = GameObject.Instantiate<WeaponProjectile>(instance);

        // Prevent hitting the player who cast it
        Physics2D.IgnoreCollision(owner.GetComponent<Collider2D>(), projectile.GetComponent<Collider2D>());

        // Set the start position
        Vector2 position = launchPoint.position;
        projectile.transform.position = position;
        projectile.directionX = directionX;

        // Flip the sprite if necessary
        if (directionX < 0)
        {
            Vector3 scale = projectile.transform.localScale;
            scale.x = -scale.x;
            projectile.transform.localScale = scale;
        }

        return projectile;
    }
Пример #10
0
        private void GetNextTarget()
        {
            currentTarget++;
            if (currentTarget > maxTargets)
            {
                parentDrawable.Alive = false;
                return;
            }

            target = Locator.EnemyTracker.GetClosestEnemy(parentDrawable.Transform.Position);
            if (target == null || !ScreenBounds.IsOnScreen(target.Transform.Position))
            {
                parentDrawable.Alive = false;
                return;
            }
            turnToTargetAction.DrawTarget = target;

            if (target.EnemyType == EnemyType.Boss)
            {
                int bonusDamage = maxTargets - currentTarget;
                currentTarget = maxTargets;
                WeaponProjectile temp = parentDrawable as WeaponProjectile;
                if (temp != null)
                {
                    temp.Combat().Damage = 10 * bonusDamage;
                    temp.Combat().TakeDamage(temp.Combat().CurrentHealth - 1);
                }

                return;
            }

            target.AliveChanged += (Entity e) =>
            {
                this.OnNextUpdate += (GameTime g) =>
                {
                    GetNextTarget();
                };
            };
        }
Пример #11
0
    public static WeaponProjectile Create(WeaponProjectile instance, SpriteCharacterController owner, Transform launchPoint, int directionX)
    {
        WeaponProjectile projectile = GameObject.Instantiate <WeaponProjectile>(instance);

        // Prevent hitting the player who cast it
        Physics2D.IgnoreCollision(owner.GetComponent <Collider2D>(), projectile.GetComponent <Collider2D>());

        // Set the start position
        Vector2 position = launchPoint.position;

        projectile.transform.position = position;
        projectile.directionX         = directionX;

        // Flip the sprite if necessary
        if (directionX < 0)
        {
            Vector3 scale = projectile.transform.localScale;
            scale.x = -scale.x;
            projectile.transform.localScale = scale;
        }

        return(projectile);
    }
Пример #12
0
    public void InitializeModules(AgentGenome genome, Agent agent)
    {
        atmosphereSensorList = new List <AtmosphereSensor>();
        basicJointList       = new List <BasicJoint>();
        basicWheelList       = new List <BasicWheel>();
        contactSensorList    = new List <ContactSensor>();
        gravitySensorList    = new List <GravitySensor>();
        healthModuleList     = new List <HealthModule>();
        oscillatorList       = new List <InputOscillator>();
        raycastSensorList    = new List <RaycastSensor>();
        shieldList           = new List <Shield>();
        targetSensorList     = new List <TargetSensor>();
        thrusterEffectorList = new List <ThrusterEffector>();
        torqueEffectorList   = new List <TorqueEffector>();
        trajectorySensorList = new List <TrajectorySensor>();
        valueList            = new List <InputValue>();
        weaponProjectileList = new List <WeaponProjectile>();
        weaponTazerList      = new List <WeaponTazer>();

        for (int i = 0; i < genome.bodyGenome.atmosphereSensorList.Count; i++)
        {
            AtmosphereSensor atmosphereSensor = new AtmosphereSensor();
            atmosphereSensor.Initialize(genome.bodyGenome.atmosphereSensorList[i], agent);
            atmosphereSensorList.Add(atmosphereSensor);
        }
        for (int i = 0; i < genome.bodyGenome.basicJointList.Count; i++)
        {
            BasicJoint basicJoint = new BasicJoint();
            basicJoint.Initialize(genome.bodyGenome.basicJointList[i], agent);
            basicJointList.Add(basicJoint);
            //basicJointList[i].Initialize(genome.basicJointList[i]);
        }
        for (int i = 0; i < genome.bodyGenome.basicWheelList.Count; i++)
        {
            BasicWheel basicWheel = new BasicWheel();
            basicWheel.Initialize(genome.bodyGenome.basicWheelList[i], agent);
            basicWheelList.Add(basicWheel);
            //OLD:
            //basicWheelList[i].Initialize(genome.basicWheelList[i]);
        }
        for (int i = 0; i < genome.bodyGenome.contactSensorList.Count; i++)
        {
            ContactSensor contactSensor = new ContactSensor();
            //agent.segmentList[genome.contactSensorList[i].parentID].AddComponent<ContactSensorComponent>();
            contactSensor.Initialize(genome.bodyGenome.contactSensorList[i], agent);
            contactSensorList.Add(contactSensor);

            //contactSensorList[i].Initialize(genome.contactSensorList[i]);
        }
        for (int i = 0; i < genome.bodyGenome.gravitySensorList.Count; i++)
        {
            GravitySensor gravitySensor = new GravitySensor();
            gravitySensor.Initialize(genome.bodyGenome.gravitySensorList[i], agent);
            gravitySensorList.Add(gravitySensor);
        }
        for (int i = 0; i < genome.bodyGenome.healthModuleList.Count; i++)
        {
            HealthModule healthModule = new HealthModule();
            //agent.segmentList[genome.healthModuleList[i].parentID].AddComponent<HealthModuleComponent>();
            healthModule.Initialize(genome.bodyGenome.healthModuleList[i], agent);
            healthModuleList.Add(healthModule);
            //healthModuleList[i].Initialize(genome.healthModuleList[i]);
        }
        for (int i = 0; i < genome.bodyGenome.oscillatorInputList.Count; i++)
        {
            InputOscillator inputOscillator = new InputOscillator();
            inputOscillator.Initialize(genome.bodyGenome.oscillatorInputList[i], agent);
            oscillatorList.Add(inputOscillator);
            //oscillatorList[i].Initialize(genome.oscillatorInputList[i]);
        }
        for (int i = 0; i < genome.bodyGenome.raycastSensorList.Count; i++)
        {
            RaycastSensor raycastSensor = new RaycastSensor();
            raycastSensor.Initialize(genome.bodyGenome.raycastSensorList[i], agent);
            raycastSensorList.Add(raycastSensor);
            //raycastSensorList[i].Initialize(genome.raycastSensorList[i]);
        }
        for (int i = 0; i < genome.bodyGenome.shieldList.Count; i++)
        {
            Shield shield = new Shield();
            shield.Initialize(genome.bodyGenome.shieldList[i], agent);
            shieldList.Add(shield);
        }
        for (int i = 0; i < genome.bodyGenome.targetSensorList.Count; i++)
        {
            TargetSensor targetSensor = new TargetSensor();
            targetSensor.Initialize(genome.bodyGenome.targetSensorList[i], agent);
            targetSensorList.Add(targetSensor);
            //targetSensorList[i].Initialize(genome.targetSensorList[i]);
        }
        for (int i = 0; i < genome.bodyGenome.thrusterList.Count; i++)
        {
            // Create Functional GameObjects & Components:
            // none in this case

            // Create Logic Module:
            ThrusterEffector thrusterEffector = new ThrusterEffector();
            // Initialize and HookUp Logic Module:
            thrusterEffector.Initialize(genome.bodyGenome.thrusterList[i], agent);
            // If Visible, Create Renderable GameObjects & Components:
            if (isVisible)
            {
                // Find appropriate Prefab based on Agent & Module Genome:
                GameObject thrusterGO = Instantiate(Resources.Load("Prefabs/Modules/Thrusters/thrusterTest")) as GameObject;
                thrusterGO.transform.parent        = agent.segmentList[genome.bodyGenome.thrusterList[i].parentID].transform;
                thrusterGO.transform.localPosition = genome.bodyGenome.thrusterList[i].forcePoint;
                thrusterGO.transform.localRotation = Quaternion.identity;
                // Hook into Logic Module
                thrusterEffector.thrusterComponent = thrusterGO.GetComponent <ThrusterComponent>();
            }
            // Add Logic Module to Agent's Master List
            thrusterEffectorList.Add(thrusterEffector);
        }
        for (int i = 0; i < genome.bodyGenome.torqueList.Count; i++)
        {
            TorqueEffector torqueEffector = new TorqueEffector();
            torqueEffector.Initialize(genome.bodyGenome.torqueList[i], agent);
            torqueEffectorList.Add(torqueEffector);
            //torqueEffectorList[i].Initialize(genome.torqueList[i]);
        }
        for (int i = 0; i < genome.bodyGenome.trajectorySensorList.Count; i++)
        {
            TrajectorySensor trajectorySensor = new TrajectorySensor();
            trajectorySensor.Initialize(genome.bodyGenome.trajectorySensorList[i], agent);
            trajectorySensorList.Add(trajectorySensor);
        }
        for (int i = 0; i < genome.bodyGenome.valueInputList.Count; i++)
        {
            InputValue inputValue = new InputValue();
            inputValue.Initialize(genome.bodyGenome.valueInputList[i], agent);
            valueList.Add(inputValue);
            //valueList[i].Initialize(genome.valueInputList[i]);
        }
        for (int i = 0; i < genome.bodyGenome.weaponProjectileList.Count; i++)
        {
            WeaponProjectile weaponProjectile = new WeaponProjectile();
            weaponProjectile.Initialize(genome.bodyGenome.weaponProjectileList[i], agent);

            if (isVisible)
            {
                // Find appropriate Prefab based on Agent & Module Genome:
                GameObject weaponGO = Instantiate(Resources.Load("Prefabs/Modules/WeaponProjectiles/projectileTest")) as GameObject;
                weaponGO.transform.parent        = agent.segmentList[genome.bodyGenome.weaponProjectileList[i].parentID].transform;
                weaponGO.transform.localPosition = genome.bodyGenome.weaponProjectileList[i].muzzleLocation;
                weaponGO.transform.localRotation = Quaternion.identity;
                // Hook into Logic Module
                weaponProjectile.weaponProjectileComponent = weaponGO.GetComponent <WeaponProjectileComponent>();
            }

            weaponProjectileList.Add(weaponProjectile);

            /*weaponProjectileList[i].Initialize(genome.weaponProjectileList[i]);
             *
             * if (isVisible) {
             *  GameObject particleGO = Instantiate(Resources.Load(weaponProjectileList[i].GetParticleSystemURL())) as GameObject;
             *  ParticleSystem particle = particleGO.GetComponent<ParticleSystem>();
             *  ParticleSystem.EmissionModule emission = particle.emission;
             *  emission.enabled = false;
             *  particle.gameObject.transform.parent = rootObject.transform;
             *  particle.gameObject.transform.localPosition = new Vector3(0f, 0.5f, 0f);
             *  particle.gameObject.transform.localRotation = Quaternion.identity;
             *  weaponProjectileList[i].particles = particle; // save reference
             * }
             */
        }
        for (int i = 0; i < genome.bodyGenome.weaponTazerList.Count; i++)
        {
            WeaponTazer weaponTazer = new WeaponTazer();
            weaponTazer.Initialize(genome.bodyGenome.weaponTazerList[i], agent);

            if (isVisible)
            {
                // Find appropriate Prefab based on Agent & Module Genome:
                GameObject weaponGO = Instantiate(Resources.Load("Prefabs/Modules/WeaponTazers/tazerTest")) as GameObject;
                weaponGO.transform.parent        = agent.segmentList[genome.bodyGenome.weaponTazerList[i].parentID].transform;
                weaponGO.transform.localPosition = genome.bodyGenome.weaponTazerList[i].muzzleLocation;
                weaponGO.transform.localRotation = Quaternion.identity;
                // Hook into Logic Module
                weaponTazer.weaponTazerComponent = weaponGO.GetComponent <WeaponTazerComponent>();
            }

            weaponTazerList.Add(weaponTazer);

            /*weaponTazerList[i].Initialize(genome.weaponTazerList[i]);
             * if (isVisible) {
             *  GameObject particleGO = Instantiate(Resources.Load(weaponTazerList[i].GetParticleSystemURL())) as GameObject;
             *  ParticleSystem particle = particleGO.GetComponent<ParticleSystem>();
             *  ParticleSystem.EmissionModule emission = particle.emission;
             *  emission.enabled = false;
             *  particle.gameObject.transform.parent = weaponTazerList[i].parentBody.transform;
             *  particle.gameObject.transform.localPosition = weaponTazerList[i].muzzleLocation;
             *  particle.gameObject.transform.localRotation = Quaternion.identity;
             *  weaponTazerList[i].particles = particle; // save reference
             * }
             */
        }
    }
Пример #13
0
 /// <summary>
 /// Настройка поведения снаряда
 /// </summary>
 public void SetupProjectileBehaviour(WeaponProjectile weaponProjectile, Vector3 velocity, ProjectileCallback projectileCallback = ProjectileCallback.PROJECTILE_CALLBACK_NONE)
 {
     this.weaponProjectile   = weaponProjectile;
     this.projectileCallback = projectileCallback;
     gameObject.GetComponent <Rigidbody>().velocity = velocity;
 }
Пример #14
0
    /** Shoot current range weapon. Returns true if the weapon still has ammo left, false if it's empty (the melee weapon will be
     *  equipped automatically).
     */
    public bool UseWeapon()
    {
        if( currentWeapon.type != WeaponType.Melee )
        {
            if( activeProjectile != null ) return true; // current projectile limit: 1

            // TODO passive: init visual rep here and let visual rep decide when to init proj (fkn timing shit bullshittery)
            WeaponProjectile proj = pool.GetProjectileInstanceForWeapon( currentWeapon.WeaponID );
            if( proj == null )
            {
                GameObject obj = currentWeapon.GetProjectile();
                obj = (GameObject)Instantiate( obj, Vector3.zero, Quaternion.identity );
                proj = obj.GetComponent<WeaponProjectile>();
            }
            proj.transform.position = transform.TransformPoint( currentWeapon.GetProjectileSpawnPosition() );
            proj.Initialize( proj.transform.position, new Vector3(4f, 0f, -4f), currentWeapon.projectileSpeed, currentWeapon.WeaponID, this );
            activeProjectile = proj;
        }

        bool hasAmmo = currentWeapon.UseAmmo();

        if( !hasAmmo )
        {
            if( currentWeapon.type != WeaponType.Melee )
            {
                currentRangeWeapon = standardRange;
                currentRangeInstance = standardRangeInstance;
            }
            else
            {
                currentMeleeWeapon = standardMelee;
                currentMeleeInstance = standardMeleeInstance;
            }
        }

        return hasAmmo;
    }
Пример #15
0
    public void ProjectileDone()
    {
        if( activeProjectile == null ) { Debug.Log("FAIL"); return; }

        Debug.Log("ADD TO POOL");
        pool.AddProjectileToPool( activeProjectile );
        activeProjectile = null;
    }