示例#1
0
        public static bool IsEnimyDangerous(Entity enimy)
        {
            if (enimy.GetATK() > 4)
            {
                return(true);
            }
            if (enimy.GetHealth() > 4)
            {
                if (enimy.GetATK() - enimy.GetHealth() > 4)
                {
                    return(true);
                }
            }
            else if (enimy.GetHealth() > 2) // 3,4
            {
                if (enimy.GetATK() - enimy.GetHealth() > 3)
                {
                    return(true);
                }
            }
            else // 1,2
            {
                if (enimy.GetATK() - enimy.GetHealth() > 2)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#2
0
 private void Update()
 {
     if (m_selectionButtons != null || m_attackButtons != null)
     {
         if (!m_selectionButtons.activeInHierarchy && !m_attackButtons.activeInHierarchy)
         {
             m_selectionButtons.SetActive(true);
         }
         if (m_selectionButtons.activeInHierarchy)
         {
             m_attackButtons.SetActive(false);
         }
         else if (m_attackButtons.activeInHierarchy)
         {
             m_selectionButtons.SetActive(false);
         }
         if ((m_mainEntity.GetHealth() <= 0 || m_defendEntity.GetHealth() <= 0) && hasBattled == false)
         {
             m_attackButtons.SetActive(false);
             hasBattled = true;
             GameStateOver();
         }
         m_mainHealth.text          = m_mainEntity.GetHealth().ToString() + "/" + saveDefendPlayerHealth.ToString();
         m_mainHealthSlider.value   = (int)m_mainEntity.GetHealth();
         m_defendHealthSlider.value = (int)m_defendEntity.GetHealth();
     }
 }
        /// <summary>
        /// Snapshot a minion.
        /// </summary>
        /// <param name="minion">The Entity.</param>
        /// <returns>The RockMinion.</returns>
        private static RockMinion SnapshotMinion(Entity minion)
        {
            var rockMinion = new RockMinion();

            rockMinion.RockId           = minion.GetEntityId();
            rockMinion.Name             = minion.GetName();
            rockMinion.CardId           = minion.GetCardId();
            rockMinion.Health           = minion.GetRealTimeRemainingHP();
            rockMinion.BaseHealth       = minion.GetHealth();
            rockMinion.CanAttack        = minion.CanAttack();
            rockMinion.CanBeAttacked    = minion.CanBeAttacked();
            rockMinion.Damage           = minion.GetATK();
            rockMinion.HasTaunt         = minion.HasTaunt();
            rockMinion.HasWindfury      = minion.HasWindfury();
            rockMinion.HasDivineShield  = minion.HasDivineShield();
            rockMinion.HasAura          = minion.HasAura();
            rockMinion.IsStealthed      = minion.IsStealthed();
            rockMinion.IsExhausted      = minion.IsExhausted();
            rockMinion.IsFrozen         = minion.IsFrozen();
            rockMinion.IsAsleep         = minion.IsAsleep();
            rockMinion.HasDeathrattle   = minion.HasDeathrattle();
            rockMinion.HasInspire       = minion.HasInspire();
            rockMinion.HasTriggerVisual = minion.HasTriggerVisual();
            rockMinion.HasLifesteal     = minion.HasLifesteal();
            rockMinion.IsPoisonous      = minion.IsPoisonous();
            rockMinion.IsEnraged        = minion.IsEnraged();
            rockMinion.HasBattlecry     = minion.HasBattlecry();
            rockMinion.Race             = (RockRace)(int)minion.GetRace();

            return(rockMinion);
        }
示例#4
0
	protected void LateUpdate()
	{
		if(player == null || health == null)
		{
			player = EntityUtils.GetEntityWithTag("Player");

			if(player == null)
			{
				return;
			}

			health = player.GetHealth();

			if(health == null)
			{
				return;
			}
		}

		float current = health.CurrentHealth;
		float max = health.StartingHealth;

		float alpha = 1 - current / max;

		Color color = image.material.color;
		color.a = alpha * 0.65f;
		image.material.color = color;
	}
    // Use this for initialization
    void Start()
    {
        healtBarWidth = (int)healtBarMaxSize;
        myhb = (GameObject)Instantiate(myHealtBar,transform.position,transform.rotation) as GameObject;

        ParentEntityObject = GetComponent<Entity>();

        maxhp = ParentEntityObject.GetHealth();
    }
示例#6
0
        public void PerformBehaviour(Entity target, Entity instigator)
        {
            if (instigator == null)
            {
                return;
            }

            if (!instigator.GetIsHuman())
            {
                return;
            }

            var amount = target.GetHealAmount();

            instigator.SetHealth(instigator.GetHealth() + amount);
            if (instigator.GetHealth() > instigator.GetMaxHealth())
            {
                instigator.SetHealth(instigator.GetMaxHealth());
            }
        }
示例#7
0
 void Enhance(Entity entity)
 {
     if (!(entity is Turret) && entity.faction == Core.faction && entity != Core && !boosted.Contains(entity))
     {
         var maxHealths = entity.GetMaxHealth();
         maxHealths[0] += healthAddition * abilityTier;
         var healths = entity.GetHealth();
         healths[0]            += healthAddition * abilityTier;
         entity.damageAddition += damageAddition;
         boosted.Add(entity);
     }
 }
示例#8
0
        private static bool ApplyHealAmount(Entity user, InventoryItem itemUsed, ItemSpec itemSpec)
        {
            var healAmount = itemSpec.GetHealAmount();

            if (healAmount == 0)
            {
                return(false);
            }

            user.SetHealth(user.GetHealth() + healAmount);

            return(true);
        }
示例#9
0
 private void Start()
 {
     m_mainEntity.Load();
     m_defendEntity.Load();
     m_mainLevel.text              = m_mainEntity.GetLevel().ToString();
     m_mainHealth.text             = m_mainEntity.GetHealth().ToString() + "/" + saveHealthPlayer.ToString();
     m_defendLevel.text            = m_defendEntity.GetLevel().ToString();
     saveHealthPlayer              = m_mainEntity.GetHealth();
     saveDefendPlayerHealth        = m_mainEntity.GetHealth();
     m_mainHealthSlider.maxValue   = (int)saveHealthPlayer;
     m_defendHealthSlider.maxValue = (int)saveDefendPlayerHealth;
 }
示例#10
0
 /// <summary>
 /// Heals all nearby allies
 /// </summary>
 protected override void Execute()
 {
     AudioManager.PlayClipByID("clip_healeffect", transform.position);
     for (int i = 0; i < AIData.entities.Count; i++)
     {
         if (AIData.entities[i].faction == Core.GetFaction())
         {
             Entity ally = AIData.entities[i];
             float  d    = (ally.transform.position - Core.transform.position).sqrMagnitude;
             if (d < 100)
             {
                 if (ally.GetHealth()[0] < ally.GetMaxHealth()[0])
                 {
                     ally.TakeShellDamage(-500f, 0f, GetComponentInParent <Entity>());
                 }
                 if (ally.GetHealth()[1] < ally.GetMaxHealth()[1])
                 {
                     ally.TakeCoreDamage(-500f);
                 }
             }
         }
     }
     isOnCD = true;
 }
        /// <summary>
        /// Snapshot a card.
        /// </summary>
        /// <param name="card">The Entity.</param>
        /// <returns>The RockCard.</returns>
        private static RockCard SnapshotCard(Entity card)
        {
            var rockCard = new RockCard();

            rockCard.RockId = card.GetEntityId();
            rockCard.Name   = card.GetName();
            rockCard.CardId = card.GetCardId();
            rockCard.Cost   = card.GetCost();
            if (card.IsMinion())
            {
                rockCard.CardType = RockCardType.Minion;
            }
            else if (card.IsSpell())
            {
                rockCard.CardType = RockCardType.Spell;
            }
            else if (card.IsEnchantment())
            {
                rockCard.CardType = RockCardType.Enchantment;
            }
            else if (card.IsWeapon())
            {
                rockCard.CardType = RockCardType.Weapon;
            }
            else
            {
                rockCard.CardType = RockCardType.None;
            }

            rockCard.Damage    = card.GetATK();
            rockCard.Health    = card.IsWeapon() ? card.GetCurrentDurability() : card.GetHealth();
            rockCard.HasTaunt  = card.HasTaunt();
            rockCard.HasCharge = card.HasCharge();
            rockCard.Options   = new List <RockCard>();

            if (card.HasSubCards())
            {
                foreach (var subCardID in card.GetSubCardIDs())
                {
                    rockCard.Options.Add(SnapshotCard(GameState.Get().GetEntity(subCardID)));
                }
            }

            return(rockCard);
        }
示例#12
0
 /// <summary>
 /// Heals all nearby allies
 /// </summary>
 protected override void Execute()
 {
     AudioManager.PlayClipByID("clip_healeffect", transform.position);
     for (int i = 0; i < AIData.entities.Count; i++)
     {
         if (AIData.entities[i].faction == Core.GetFaction())
         {
             Entity ally = AIData.entities[i];
             float  d    = (ally.transform.position - Core.transform.position).sqrMagnitude;
             if (d < range * range)
             {
                 if (ally.GetHealth()[0] < ally.GetMaxHealth()[0])
                 {
                     ally.TakeShellDamage(-heal * Mathf.Max(1, abilityTier), 0f, GetComponentInParent <Entity>());
                 }
             }
         }
     }
 }
示例#13
0
        private static void GetMoreHungry(Entity target)
        {
            var hunger = target.GetHunger();

            // can't be any more hungry!
            if (hunger < Consts.MaxHunger)
            {
                hunger++;
                target.SetHunger(hunger);
            }

            if (hunger == Consts.MaxHunger)
            {
                var health = target.GetHealth();
                if (health > 0)
                {
                    health--;
                    target.SetHealth(health);
                }
            }
        }
示例#14
0
    /*
     * Calculate the estimated combat strength
     */
    public float CalcCombatPower()
    {
        if (isPlayer)
        {
            return(3f * (1 + 1f * GetComponent <Entity>().health / GetComponent <Entity>().maxHealth));
        }

        // Depending on the units health it adds 50% (zero health) to 100% (at full health) of its original power to the squad power

        combatPower = 0;

        foreach (Transform t in members)
        {
            Entity entity = t.GetComponent <Entity>();

            // Combat power shrinks linearly to half, when health drops

            combatPower += (float)(entity.combatStrength * ((1f * entity.GetHealth() / entity.maxHealth) * 0.5 + 0.5));
        }

        return(combatPower);
    }
示例#15
0
    protected override void OnAction(SpellStateType prevStateType)
    {
        base.OnAction(prevStateType);
        Entity     entity = base.GetSourceCard().GetEntity();
        Actor      actor  = SceneUtils.FindComponentInParents <Actor>(this);
        GameObject main   = this.m_minionPieces.m_main;
        bool       flag   = entity.HasTag(GAME_TAG.PREMIUM);

        if (flag)
        {
            main = this.m_minionPieces.m_premium;
            SceneUtils.EnableRenderers(this.m_minionPieces.m_main, false);
        }
        GameObject portraitMesh = actor.GetPortraitMesh();

        main.GetComponent <Renderer>().material = portraitMesh.GetComponent <Renderer>().sharedMaterial;
        main.SetActive(true);
        SceneUtils.EnableRenderers(main, true);
        if (entity.HasTaunt())
        {
            if (flag)
            {
                this.m_minionPieces.m_taunt.GetComponent <Renderer>().material = this.m_premiumTauntMaterial;
            }
            this.m_minionPieces.m_taunt.SetActive(true);
            SceneUtils.EnableRenderers(this.m_minionPieces.m_taunt, true);
        }
        if (entity.IsElite())
        {
            if (flag)
            {
                this.m_minionPieces.m_legendary.GetComponent <Renderer>().material = this.m_premiumEliteMaterial;
            }
            this.m_minionPieces.m_legendary.SetActive(true);
            SceneUtils.EnableRenderers(this.m_minionPieces.m_legendary, true);
        }
        this.m_attack.SetGameStringText(entity.GetATK().ToString());
        this.m_health.SetGameStringText(entity.GetHealth().ToString());
    }
	protected void Update()
	{
		if(player == null || health == null)
		{
			player = EntityUtils.GetEntityWithTag("Player");

			if(player == null)
			{
				return;
			}

			health = player.GetHealth();
		}

		if(health.CurrentHealth <= (health.StartingHealth / 4))
		{
			if(audioChannel == null || !audioChannel.IsPlaying)
			{
				audioChannel = audioManager.Play(audio);
			}
		}
	}
        public MyGame(SceneManager sceneManager) : base(sceneManager)
        {
            //Set window title
            sceneManager.Title = "DOOMED";
            //Set the render and update delegates
            sceneManager.renderer = Render;
            sceneManager.updater  = Update;

            //Creates managers
            entityManager = new EntityManager();
            systemManager = new SystemManager();
            inputManager  = new InputManager(sceneManager);

            cameraList = new List <Camera>();
            //Creates new camera object for the main game camera
            mainCamera = new Camera(new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 1, 0), 60, 1920 / 1080f, 0.01f, 100f);
            cameraList.Add(mainCamera);
            //Creates a new camera for the minimap
            minimapCamera = new Camera(new Vector3(12f, 20, 12f), new Vector3(12f, -1, 12f), new Vector3(0, 0, -1), 25f, 25f, 0.01f, 100f);
            cameraList.Add(minimapCamera);

            playerIgnoreCollisionWith  = new List <string>();
            bulletIgnoreCollisionWith  = new List <string>();
            droneIgnoreCollisionWith   = new List <string>();
            powerUpIgnoreCollisionWith = new List <string>();
            despawnedEntities          = new List <Entity>();



            //Sets light position
            lightPosition = new Vector4(0f, 20f, 0f, 1);

            //Creates initial Entities
            CreateEntities();


            //Sets reference to player entity
            player = entityManager.FindEntity("Player");

            //Creates Systems
            CreateSystems();

            //Gets reference from input manager of the list of buttons pressed
            keyboardInput = inputManager.Keyboard();
            mouseInput    = inputManager.MouseInput();

            //Sets cursor visibility state
            inputManager.CursorVisible(false);

            //Sets mouse sensitivity
            mouseSensitivity = 0.001f;

            //Sets camera starting position
            mainCamera.Position = player.GetTransform().Translation;

            //Sets base values for shooting variables
            bulletCount = 0;
            fireRate    = 0.3f;
            nextShot    = 0;

            //Sets no clip to false on load
            noClip = false;

            //Sets buffs to false on load
            damageBuff       = false;
            speedBuff        = false;
            disableDroneBuff = false;

            //Sets collision and drone disabling to false on load
            disableCollisions = false;
            disableDrone      = false;

            //Sets paused to false on load
            paused = false;

            //Sets health
            health    = player.GetHealth().Health;
            healthMax = player.GetHealth().Health;

            //Sets drone count
            foreach (Entity entity in entityManager.Entities())
            {
                if (entity.Name.Contains("Drone"))
                {
                    droneCount++;
                }
            }
        }
    private void Update()
    {
        if (dragging)
        {
            var xPos = Input.mousePosition.x;
            AbilityHandler.RearrangeID(xPos, (AbilityID)abilities[0].GetID(), (AbilityID)abilities[0].GetID() == AbilityID.SpawnDrone ?
                                       (abilities[0] as SpawnDrone).spawnData.drone : null);
        }

        // update the number of off-CD abilities
        if (offCDCountText)
        {
            offCDCountText.text = abilities.FindAll(a => a && !a.IsDestroyed() && a.GetCDRemaining() == 0).Count + "";
        }

        if (tooltip)
        {
            tooltip.transform.position = Input.mousePosition;
        }

        if (!entity || (entity as PlayerCore).GetIsInteracting())
        {
            return;
        }

        // there's no point in running Update if there is no ability
        if (!abilities.Exists(ab => ab && !ab.IsDestroyed()) || entity.GetIsDead())
        {
            if (offCDCountText)
            {
                offCDCountText.text = "";
            }
            if (image)
            {
                image.color = new Color(.1f, .1f, .1f);       // make the background dark
            }
            if (gleam)
            {
                Destroy(gleam.gameObject);       // remove other sprites; destroying makes them irrelevant
            }
            if (cooldown)
            {
                Destroy(cooldown.gameObject);
            }
            return;
        }

        abilities.Sort((a, b) => {
            if (!a.IsDestroyed() && b.IsDestroyed())
            {
                return(-1);
            }
            else if (a.IsDestroyed() && !b.IsDestroyed())
            {
                return(1);
            }
            if (a.GetCDRemaining() > b.GetCDRemaining())
            {
                return(1);
            }
            else if (a.GetCDRemaining() < b.GetCDRemaining())
            {
                return(-1);
            }
            else if (a.GetTier() > b.GetTier())
            {
                return(-1);
            }
            else if (a.GetTier() < b.GetTier())
            {
                return(1);
            }
            else
            {
                return(0);
            }
        });

        ReflectDescription(abilities[0]);
        ReflectTier(abilities[0]);
        ReflectName(abilities[0]);

        if (entity.GetHealth()[2] < abilities[0].GetEnergyCost())
        {
            image.color = new Color(0, 0, 0.3F); // make the background dark blue
        }
        else
        {
            image.color = abilities[0].GetActiveTimeRemaining() != 0 ? Color.green : Color.white;
        }
        cooldown.fillAmount = abilities[0].GetCDRemaining() / abilities[0].GetCDDuration();

        if (!entity.GetIsDead())
        {
            bool hotkeyAccepted = (InputManager.GetKeyDown(keycode) && !InputManager.GetKey(KeyName.TurretQuickPurchase));
            if (abilities[0] is WeaponAbility)
            {
                foreach (var ab in abilities)
                {
                    ab.Tick(hotkeyAccepted || (clicked && Input.mousePosition == oldInputMousePos) ? 1 : 0);
                }
            }
            else
            {
                abilities[0].Tick(hotkeyAccepted ||
                                  (clicked && Input.mousePosition == oldInputMousePos) ? 1 : 0);
                for (int i = 1; i < abilities.Count; i++)
                {
                    abilities[i].Tick(0);
                }
            }
        }

        clicked = false;

        // gleam (ability temporarily going white when cooldown refreshed) stuff
        if (gleaming)
        {
            Gleam();
        }

        if (abilities[0].GetCDRemaining() != 0)
        {
            gleamed = false;
        }
        else if (!gleamed && !gleaming)
        {
            gleamed     = true;
            gleaming    = true;
            gleam.color = Color.white;
        }
    }
示例#19
0
    void Update()
    {
        line.gameObject.transform.position = gameObject.transform.position;
        if (initialized && targetingSystem.GetTarget() && !Core.IsInvisible && duration > 0)
        {
            if (Core.GetHealth()[2] < energyCost * Time.deltaTime)
            {
                duration = 0;
                return;
            }

            duration -= Time.deltaTime;
            var pos = targetingSystem.GetTarget().position;
            line.positionCount = 2;
            line.SetPosition(0, line.gameObject.transform.position);
            var vec = (pos - line.gameObject.transform.position).normalized;
            //var angle = Mathf.Atan(vec.y / vec.x);
            var targetBearing = GetBearingFromVector(vec);


            // vec = (GetMousePos() - transform.position).normalized;
            var originalBearing = beamBearing;

            var diff = targetBearing - originalBearing;

            var  c          = 65 * Time.deltaTime;
            bool goForwards = false;

            if (originalBearing < 180)
            {
                goForwards = targetBearing - originalBearing < 180 && targetBearing - originalBearing > 0;
            }
            else
            {
                var limit = originalBearing + 180 - 360;
                goForwards = targetBearing < 180 ? (targetBearing < limit) : (targetBearing > originalBearing);
            }

            if (Mathf.Abs(diff) <= c)
            {
                originalBearing = targetBearing;
            }
            else
            {
                originalBearing += goForwards ? c : -c;
            }

            beamBearing = originalBearing;
            if (beamBearing > 360)
            {
                beamBearing -= 360;
            }

            if (beamBearing < 0)
            {
                beamBearing += 360;
            }

            var newAngle = GetAngleFromBearing(originalBearing) * Mathf.Deg2Rad;

            // Debug.LogError(angle * Mathf.Rad2Deg + " " + GetBearingFromVector(vec) + " " + GetAngleFromBearing(GetBearingFromVector(vec)));
            line.SetPosition(1, transform.position + GetVectorByBearing(originalBearing) * range);
            ThickenLine(0.005F);

            var dps         = damage * Time.deltaTime;
            var raycastHits = Physics2D.RaycastAll(transform.position, GetVectorByBearing(originalBearing), range);
            for (int i = 0; i < raycastHits.Length; i++)
            {
                var damageable = raycastHits[i].transform.GetComponentInParent <IDamageable>();
                if (raycastHits[i].transform && damageable != null && damageable.GetFaction() != Core.faction && !damageable.GetIsDead() && damageable.GetTerrain() != Entity.TerrainType.Ground)
                {
                    var hitTransform = raycastHits[i].transform;

                    var magnitude = (hitTransform.position - transform.position).magnitude;
                    line.SetPosition(1, transform.position + GetVectorByBearing(originalBearing) * magnitude);
                    Core.TakeEnergy(energyCost * Time.deltaTime);

                    var part = hitTransform.GetComponentInChildren <ShellPart>();

                    var residue = damageable.TakeShellDamage(dps, 0, GetComponentInParent <Entity>());

                    // deal instant damage

                    if (part)
                    {
                        part.TakeDamage(residue);
                    }

                    break;
                }
            }

            if (!hitPrefab)
            {
                hitPrefab = ResourceManager.GetAsset <GameObject>("weapon_hit_particle");
            }

            if (line.positionCount > 1)
            {
                Instantiate(hitPrefab, line.GetPosition(1), Quaternion.identity); // instantiate hit effect
            }
        }
        else
        {
            if (!targetingSystem.GetTarget() && duration > 0)
            {
                duration = 0;
            }

            if (line.startWidth > startWidth)
            {
                ThickenLine(-0.01F);
            }

            if (duration <= 0)
            {
                if (transform.parent.GetComponentInChildren <AudioSource>())
                {
                    Destroy(transform.parent.GetComponentInChildren <AudioSource>().gameObject);
                }
            }
        }
    }
示例#20
0
 // Update is called once per frame
 void Update()
 {
     health.part = 1f * player.GetHealth() / player.maxHealth;
 }
示例#21
0
        public void Update(FrameEventArgs e)
        {
            //Game time and delta time
            dt = (float)e.Time;
            sceneManager.dt   = dt;
            time             += (float)e.Time;
            SceneManager.time = time;
            //Pause button toggle timer
            pauseToggleTimer += dt;

            //Pauses game when escape is pressed and unpauses when pressed again
            if (keyboardInput.Contains("Escape") && pauseToggleTimer > 0.25f)
            {
                if (paused != true)
                {
                    paused           = true;
                    pauseToggleTimer = 0;
                }
                else
                {
                    paused           = false;
                    pauseToggleTimer = 0;
                }
            }

            //Checks game isn't paused
            if (paused != true)
            {
                light.GetTransform().Translation -= light.GetTransform().Forward *dt;
                test.GetTransform().Translation  -= test.GetTransform().Forward *test.GetVelocity().Velocity *dt;
                test.GetTransform().Translation  += test.GetTransform().Right *test.GetVelocity().Velocity *dt;
                test.GetTransform().Rotation     += new Vector3(0, 0.1f * dt, 0);
                //Button toggle on/off timers
                noClipToggleTimer           += dt;
                disableCollisionToggleTimer += dt;
                disableDroneToggleTimer     += dt;

                //Buff timers
                damageBuffTimer   += dt;
                speedBuffTimer    += dt;
                disableDroneTimer += dt;

                //Damage delay timers
                damageDelay += dt;

                //Gets mouse position from input manager every frame
                mousePos = inputManager.MousePosition();

                #region Player Movement and collision with drone logic
                if (keyboardInput.Contains("Up"))
                {
                    //Moves player forward when W is pressed
                    player.GetTransform().Translation += player.GetTransform().Forward *player.GetVelocity().Velocity *dt;
                    //Moves camera forward to stay in line with player position
                    mainCamera.MoveCamera(player.GetTransform().Translation);
                }
                if (keyboardInput.Contains("Down"))
                {
                    //Moves player backwards when S is pressed
                    player.GetTransform().Translation -= player.GetTransform().Forward *player.GetVelocity().Velocity *dt;
                    //Moves camera backwards to stay in line with player position
                    mainCamera.MoveCamera(player.GetTransform().Translation);
                }
                if (keyboardInput.Contains("Right"))
                {
                    //Moves player right when D is pressed
                    player.GetTransform().Translation += player.GetTransform().Right *player.GetVelocity().Velocity *dt;
                    //Moves camera right to stay in line with player position
                    mainCamera.MoveCamera(player.GetTransform().Translation);
                }
                if (keyboardInput.Contains("Left"))
                {
                    //Moves player left when A is pressed
                    player.GetTransform().Translation -= player.GetTransform().Right *player.GetVelocity().Velocity *dt;
                    //Moves camera left to stay in line with player position
                    mainCamera.MoveCamera(player.GetTransform().Translation);
                }

                if (player.GetCollidedWith().Count > 0)
                {
                    foreach (string entityName in player.GetCollidedWith())
                    {
                        //Removes a life from the player when colliding with a drone
                        if (entityName.Contains("Drone") && damageDelay > 0.5f)
                        {
                            player.GetHealth().Health -= 1;
                            health     -= 1;
                            damageDelay = 0;
                        }

                        if (entityName.Contains("Health") || entityName.Contains("Disable") || entityName.Contains("Speed") || entityName.Contains("Damage"))
                        {
                            //    player.GetAudio().PlayOnAwake = true;
                        }
                    }
                }

                //Checks if drone collides with player
                foreach (Entity entity in entityManager.Entities())
                {
                    if (entity.Name.Contains("Drone"))
                    {
                        if (entity.GetCollidedWith().Count > 0)
                        {
                            foreach (string entityName in entity.GetCollidedWith())
                            {
                                if (entityName.Contains("Player"))
                                {
                                    //     entity.GetAudio().PlayOnAwake = true;
                                }
                            }
                        }
                    }
                }
                //Game over screen when player runs out of lives
                if (player.GetHealth().Health <= 0)
                {
                    //Game over logic
                    sceneManager.LoadScene(new GameOverScene(sceneManager));
                }
                #endregion

                #region Player Rotation on the Y axis based on mouse movement on the X axis
                if (sceneManager.Focused)
                {
                    //Amount mouse has moved since last update call
                    mouseDelta = oldMousePos - mousePos;

                    //Adjusts player rotation on the x and y axis based on the mouse movement on the x and y axis if no clip is on
                    if (noClip == true)
                    {
                        player.GetTransform().Rotation += new Vector3(mouseDelta.Y, mouseDelta.X, 0.0f) * mouseSensitivity;
                    }
                    //Adjusts player rotation on the y axis based on mouse movement on the x axis if no clip is off
                    else
                    {
                        player.GetTransform().Rotation += new Vector3(0.0f, mouseDelta.X, 0.0f) * mouseSensitivity;
                    }

                    //clamp x rotation
                    if (player.GetTransform().Rotation.X > MathHelper.DegreesToRadians(89))
                    {
                        player.GetTransform().Rotation = new Vector3(MathHelper.DegreesToRadians(89), player.GetTransform().Rotation.Y, 0.0f);
                    }
                    if (player.GetTransform().Rotation.X < MathHelper.DegreesToRadians(-89))
                    {
                        player.GetTransform().Rotation = new Vector3(MathHelper.DegreesToRadians(-89), player.GetTransform().Rotation.Y, 0.0f);
                    }

                    //Adjusts camera rotation to stay in line with player rotation
                    mainCamera.RotateCamera(player.GetTransform().Rotation);

                    //Centers cursor to center of screen
                    inputManager.CenterCursor();

                    //Resets mouse position
                    oldMousePos = mousePos;
                }
                #endregion

                #region Shooting logic on left click
                //Creates new bullet entity on click based on fire rate
                if (mouseInput.Contains("Left") && time > nextShot)
                {
                    Entity bullet = new Entity("Bullet(" + bulletCount + ")");
                    bullet.AddComponent(new ComponentTransform(player.GetTransform().Translation - new Vector3(0, 0.25f, 0), player.GetTransform().Rotation, new Vector3(0.05f, 0.05f, 0.05f)));
                    bullet.AddComponent(new ComponentGeometry("Geometry/sphere.obj"));
                    bullet.AddComponent(new ComponentTexture("Textures/Blue.png"));
                    bullet.AddComponent(new ComponentVelocity(10f));
                    bullet.AddComponent(new ComponentShader("Shaders/vPulsating.glsl", "Shaders/fPulsating.glsl"));
                    bullet.AddComponent(new ComponentAudio("Audio/GUNSHOT.wav", false, true));
                    bullet.AddComponent(new ComponentSphereCollider((0.05f), bulletIgnoreCollisionWith));
                    entityManager.AddEntity(bullet);

                    //Assigns new entity to appropriate system(s)
                    systemManager.AssignNewEntity(bullet);

                    //Iterates bullet count
                    bulletCount++;

                    //Sets timestamp for when next shot can be fired
                    nextShot = time + fireRate;
                }

                //Bullet movement and collisions
                foreach (Entity entity in entityManager.Entities())
                {
                    //Moves bullet and destroys on collision
                    if (entity.Name.Contains("Bullet"))
                    {
                        entity.GetTransform().Translation += entity.GetTransform().Forward *entity.GetVelocity().Velocity *dt;

                        //Destroys bullet if it has collided with something
                        if (entity.GetCollidedWith().Count > 0)
                        {
                            //Removes entity from systems to remove it from game
                            systemManager.DestroyEntity(entity);

                            //Adds entity to despawn list to remove final reference of entity from entity manager to clear it from memory
                            despawnedEntities.Add(entity);
                        }
                    }

                    //Bullet collision with drones
                    if (entity.Name.Contains("Drone"))
                    {
                        if (entity.GetCollidedWith().Count > 0)
                        {
                            foreach (string entityName in entity.GetCollidedWith())
                            {
                                //Removes life from drone when bullet hits
                                if (entityName.Contains("Bullet"))
                                {
                                    if (damageBuff == true)
                                    {
                                        entity.GetHealth().Health -= 2;
                                    }
                                    else
                                    {
                                        entity.GetHealth().Health -= 1;
                                    }
                                }
                            }
                        }
                        //Destroys drone when it reaches 0 lives
                        if (entity.GetHealth().Health <= 0)
                        {
                            //Removes entity from systems to remove it from game
                            systemManager.DestroyEntity(entity);
                            droneCount--;

                            //Adds entity to despawn list to remove final reference of entity from entity manager to clear it from memory
                            despawnedEntities.Add(entity);
                        }
                    }
                }
                #endregion

                #region No Clip and debug keys logic
                //Activates no clip, allows player to move and rotate freely in 3d space, multiplies speed by 4
                if (keyboardInput.Contains("N") && noClipToggleTimer > 0.25f)
                {
                    if (noClip == false)
                    {
                        noClip            = true;
                        disableCollisions = true;
                        noClipToggleTimer = 0;
                        player.GetVelocity().Velocity *= 4;
                    }
                    else
                    {
                        noClip            = false;
                        disableCollisions = false;
                        noClipToggleTimer = 0;
                        player.GetVelocity().Velocity /= 4;
                    }
                }

                //Moves player up when noclip is true
                if (keyboardInput.Contains("Space") && noClip == true)
                {
                    player.GetTransform().Translation += new Vector3(0, 1, 0) * player.GetVelocity().Velocity *dt;
                    mainCamera.MoveCamera(player.GetTransform().Translation);
                }

                //Disables/Enables drones when D is pressed
                if (keyboardInput.Contains("D") && disableDroneToggleTimer > 0.25f)
                {
                    if (disableDrone == false)
                    {
                        disableDrone            = true;
                        disableDroneToggleTimer = 0;
                    }
                    else
                    {
                        disableDrone            = false;
                        disableDroneToggleTimer = 0;
                    }
                }

                //Disables/Enables collisions when C is pressed
                if (keyboardInput.Contains("C") && disableCollisionToggleTimer > 0.25f)
                {
                    if (disableCollisions == false)
                    {
                        disableCollisions           = true;
                        disableCollisionToggleTimer = 0;
                    }
                    else
                    {
                        disableCollisions           = false;
                        disableCollisionToggleTimer = 0;
                    }
                }
                #endregion

                #region Power Up logic
                foreach (Entity entity in entityManager.Entities())
                {
                    if (entity.Name.Contains("Health"))
                    {
                        if (entity.GetCollidedWith().Contains("Player"))
                        {
                            //If player
                            if (player.GetHealth().Health < 3)
                            {
                                player.GetHealth().Health += 1;
                                health += 1;
                            }

                            //Removes entity from systems to remove it from game
                            systemManager.DestroyEntity(entity);

                            //Adds entity to despawn list to remove final reference of entity from entity manager to clear it from memory
                            despawnedEntities.Add(entity);
                        }
                    }

                    if (entity.Name.Contains("Damage"))
                    {
                        if (entity.GetCollidedWith().Contains("Player"))
                        {
                            //Sets damage buff to true and sets timer for damage buff
                            if (damageBuff == false)
                            {
                                damageBuff      = true;
                                damageBuffTimer = 0;
                            }

                            //Removes entity from systems to remove it from game
                            systemManager.DestroyEntity(entity);

                            //Adds entity to despawn list to remove final reference of entity from entity manager to clear it from memory
                            despawnedEntities.Add(entity);
                        }
                    }

                    if (entity.Name.Contains("Speed"))
                    {
                        if (entity.GetCollidedWith().Contains("Player"))
                        {
                            //Sets speed buff to true and sets timer for speed buff
                            if (speedBuff == false)
                            {
                                speedBuff      = true;
                                speedBuffTimer = 0;
                                player.GetVelocity().Velocity *= 2;
                            }

                            //Removes entity from systems to remove it from game
                            systemManager.DestroyEntity(entity);

                            //Adds entity to despawn list to remove final reference of entity from entity manager to clear it from memory
                            despawnedEntities.Add(entity);
                        }
                    }

                    if (entity.Name.Contains("Disable"))
                    {
                        if (entity.GetCollidedWith().Contains("Player"))
                        {
                            //Sets disable drones to true and sets timer for disabled drones
                            if (disableDroneBuff == false)
                            {
                                disableDroneBuff  = true;
                                disableDroneTimer = 0;
                            }

                            //Removes entity from systems to remove it from game
                            systemManager.DestroyEntity(entity);

                            //Adds entity to despawn list to remove final reference of entity from entity manager to clear it from memory
                            despawnedEntities.Add(entity);
                        }
                    }

                    //Disables buffs when timers reach their end
                    if (damageBuff == true && damageBuffTimer > 3)
                    {
                        damageBuff = false;
                    }

                    if (speedBuff == true && speedBuffTimer > 3)
                    {
                        speedBuff = false;
                        player.GetVelocity().Velocity /= 2;
                    }

                    if (disableDroneBuff == true && disableDroneTimer > 3)
                    {
                        disableDroneBuff = false;
                    }
                }
                #endregion

                #region Victory condition check
                //Checks if all drones are destroyed
                dronesDestroyed = true;
                foreach (Entity entity in entityManager.Entities())
                {
                    if (entity.Name.Contains("Drone"))
                    {
                        dronesDestroyed = false;
                    }
                }

                //Exits game when all drones destroyed, planned to go to victory screen instead of exit.
                if (dronesDestroyed || keyboardInput.Contains("V"))
                {
                    sceneManager.LoadScene(new VictoryScene(sceneManager));
                }
                #endregion

                //Enables/Disables drone and collisions based on appropriate bools
                foreach (Entity entity in entityManager.Entities())
                {
                    //Collisions
                    if (entity.GetComponentBoxCollider() != null)
                    {
                        if (entity.GetComponentBoxCollider().Disabled != disableCollisions)
                        {
                            entity.GetComponentBoxCollider().Disabled = disableCollisions;
                        }
                    }
                    else if (entity.GetComponentSphereCollider() != null)
                    {
                        if (entity.GetComponentSphereCollider().Disabled != disableCollisions)
                        {
                            entity.GetComponentSphereCollider().Disabled = disableCollisions;
                        }
                    }

                    //Drones
                    if (entity.GetComponentAI() != null)
                    {
                        if (entity.GetComponentAI().Disabled != disableDrone)
                        {
                            entity.GetComponentAI().Disabled = disableDrone;
                        }

                        if (entity.GetComponentAI().Disabled != disableDroneBuff && disableDrone != true)
                        {
                            entity.GetComponentAI().Disabled = disableDroneBuff;
                        }
                    }
                }

                //Removes all references to destroyed entities to remove them from memory
                foreach (Entity entity in despawnedEntities)
                {
                    entityManager.Entities().Remove(entity);
                }
                despawnedEntities.Clear();

                //Calls Update Systems every frame
                systemManager.UpdateSystems();
            }
        }
示例#22
0
    private void OnGUI()
    {
        //update information panel
        if (playerMode != PlayerMode.paused)
        {
            {
                if (UiElements.WaveText)
                {
                    UiElements.WaveText.text = Mathf.Clamp(waveManager.GetCurrentWaveNumber(), 1, waveManager.GetCurrentWaveNumber()) + "/" + waveManager.GetTotalWavesNumber();
                }
                if (UiElements.Resources)
                {
                    UiElements.Resources.text = Mathf.RoundToInt(resourceManager.GetResources()) + "$";
                }
                if (UiElements.Health && hq)
                {
                    UiElements.Health.text = "Health " + hq.GetHealth().ToString("F00");
                }
            }
        }

        UiElements.PauseMenu.gameObject.SetActive(paused);
        UiElements.DefeatMenu.gameObject.SetActive(playerMode == PlayerMode.defeat);

        UiElements.PlaceHqBanner.gameObject.SetActive(playerMode == PlayerMode.placeHQ);

        //Normal mode
        //___________________________________________________________________________________________________________________________________________
        if (playerMode == PlayerMode.normal)
        {
            UiElements.BuildMenu.gameObject.SetActive(true);
            UiElements.SelectedMenu.gameObject.SetActive(false);
        }

        //Build mode
        //___________________________________________________________________________________________________________________________________________
        else if (playerMode == PlayerMode.build)
        {
            UiElements.BuildMenu.gameObject.SetActive(false);
            UiElements.SelectedMenu.gameObject.SetActive(false);
        }

        //Selected mode
        //___________________________________________________________________________________________________________________________________________
        else if (playerMode == PlayerMode.selected)
        {
            UiElements.BuildMenu.gameObject.SetActive(false);
            UiElements.SelectedMenu.gameObject.SetActive(true);
        }

        //Wave mode
        //___________________________________________________________________________________________________________________________________________
        else if (playerMode == PlayerMode.waveInProgres)
        {
            UiElements.BuildMenu.gameObject.SetActive(false);
            UiElements.SelectedMenu.gameObject.SetActive(false);
        }

        //Defeat mode
        //___________________________________________________________________________________________________________________________________________
        else if (playerMode == PlayerMode.defeat)
        {
            UiElements.BuildMenu.gameObject.SetActive(false);
            UiElements.SelectedMenu.gameObject.SetActive(false);
            UiElements.DefeatMenu.gameObject.SetActive(true);
        }

        //Victory mode
        //___________________________________________________________________________________________________________________________________________
        else if (playerMode == PlayerMode.victory)
        {
            UiElements.BuildMenu.gameObject.SetActive(false);
            UiElements.SelectedMenu.gameObject.SetActive(false);
            UiElements.VictoryMenu.gameObject.SetActive(true);
        }

        //Place HQ mode
        //___________________________________________________________________________________________________________________________________________
        else if (playerMode == PlayerMode.placeHQ)
        {
            UiElements.BuildMenu.gameObject.SetActive(false);
            UiElements.SelectedMenu.gameObject.SetActive(false);
            UiElements.DefeatMenu.gameObject.SetActive(false);
        }

        //disable menus when paused
        if (paused)
        {
            UiElements.BuildMenu.gameObject.SetActive(false);
            UiElements.SelectedMenu.gameObject.SetActive(false);
        }
    }