Beispiel #1
0
 protected override void DestructableObjectCollision(DestructableObject other, Collision2D collision)
 {
     if (other.team != team)
     {
         other.DamageThis(damage);
     }
 }
Beispiel #2
0
    public void Explode(int damage)
    {
        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, explosionRadius);
        StartCoroutine(Boom());
        PlayerStats activePlayer = GameManager.activePlayers[whoThrew].GetComponent <PlayerStats>();

        foreach (Collider2D nearbyObject in colliders)
        {
            Rigidbody2D        rb    = nearbyObject.GetComponent <Rigidbody2D>();
            DestructableObject destr = nearbyObject.GetComponent <DestructableObject>();
            if (rb != null && rb.tag == "Player")
            {
                rb.gravityScale = 1;
                rb.AddForce((rb.transform.position - transform.position).normalized
                            * ((1 / (rb.transform.position - transform.position).magnitude) * explosionStrength), ForceMode2D.Impulse);
                rb.GetComponent <PlayerStats>().TakeDamage(damage);
                activePlayer.damageDealt += damage;
                if (rb.GetComponent <PlayerStats>().health <= 0)
                {
                    activePlayer.damageDealt += rb.GetComponent <PlayerStats>().health;
                    activePlayer.kills++;
                }
            }
            if (destr != null)
            {
                destr.Damage(terrainDamage);
            }
        }



        Destroy(gameObject);
    }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1) && GameManager.instance.buildHouseButton.interactable)
        {
            OnBuildHouseClicked();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2) && GameManager.instance.buildPowerplantButton.interactable)
        {
            OnBuildPowerplantClicked();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3) && GameManager.instance.buildWallButton.interactable)
        {
            OnBuildWallClicked();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            OnDemolishClicked();
        }

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out RaycastHit hit, float.MaxValue, GameManager.instance.buildingLayer.value))
        {
            DestructableObject DO = hit.collider.gameObject.GetComponent <DestructableObject>();
            if (prevHighlighted != DO)
            {
                DO.Highlight();
                if (prevHighlighted != null)
                {
                    prevHighlighted.DeHighlight();
                }
                prevHighlighted = DO;
            }
        }
Beispiel #4
0
    protected override void DestructableObjectCollision(DestructableObject other, Collision2D collision)
    {
        //push the other away from this, as fast as it can go
        other.velocity = -collision.relativeVelocity.normalized * other.maxSpeed;

        other.DamageThis(damage);
    }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        if (!Input.GetButtonDown("Fire1"))
        {
            return;
        }
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity, destructableLayer))
        {
            DestructableObject destructableObject = hit.collider.GetComponent <DestructableObject>();
            if (destructableObject)
            {
                int i = destructableObject.getNearbyVerticeIndex(hit.point, searchRadius, hit.triangleIndex);
                Debug.Log("closest index to our hit point is " + i);

                if (i == -1)
                {
                    return;
                }
                destructableObject.ChangeSimilarVertices(i, transform.position, force);
            }
            else
            {
                Debug.LogError("The object " + hit + " needs to have a DestructableObject script attached to it");
            }
        }
        Debug.DrawRay(transform.position, transform.forward * 8, Color.red, 2f);
    }
Beispiel #6
0
 public void AttackEnemy(RaycastHit2D hit)
 {
     if (hit.collider.tag == "Enemy")
     {
         destructableObject = hit.transform.GetComponent <DestructableObject>();
         destructableObject.LoseHP(destructableObjectDamage);
     }
 }
Beispiel #7
0
 public void AttackDestructableObstacle(RaycastHit2D hit)
 {
     if (hit.collider.GetComponent <DestructableObject>())
     {
         destructableObject = hit.transform.GetComponent <DestructableObject>();
         destructableObject.LoseHP(destructableObjectDamage);
     }
 }
Beispiel #8
0
 protected override void DestructableObjectCollision(DestructableObject other)
 {
     if (team != other.team)
     {
         other.DamageThis(damage);
     }
     DestroyThis();
 }
Beispiel #9
0
        private DestructableObject DestructionBlock(string id, string assetName, string type)
        {
            DestructableObject Tile = new DestructableObject(id, this, new SpriteSheet("Textures/Tiles/" + assetName));

            Tile.CanCollide = true;
            Tile.CanBlock   = true;
            Tile.Type       = type;
            return(Tile);
        }
Beispiel #10
0
    protected override void DestructableObjectCollision(DestructableObject other, Collision2D collision)
    {
        if (other.team != team)
        {
            other.DamageThis(damage * difficultyModifier);
        }

        Bounce(collision);
    }
Beispiel #11
0
    protected override void DestructableObjectCollision(DestructableObject other)
    {
        if (other != attachedTo)
        {
            other.DamageThis(damage);

            //Retract the Lazer to only go to what it collided with, not past it
            scale = new Vector2(scale.x, DistanceFrom(other) / originalLength);
        }
    }
    protected override void DestructableObjectCollision(DestructableObject other, Collision2D collision)
    {
        //if the collision speed is larger than the minimum, deal damage to the DestructableObject
        float damageSpeed = collision.relativeVelocity.magnitude - minDamageSpeed;

        if (damageSpeed > 0)
        {
            other.DamageThis(damageSpeed * damageMultiplier * difficultyModifier);
        }
    }
Beispiel #13
0
    /* Doesn't work
     * public List<IEnumerable<T>> getTypes<T>() where T : SpaceObject
     * {
     *  if (typeof(T) == typeof(SpaceObject))
     *  {
     *      return (List<IEnumerable<T>>)getTypes(true, true, true, true);
     *  }
     *  else if (typeof(T) == typeof(NonInteractiveObject))
     *  {
     *      return (List<IEnumerable<T>>)getTypes(false, false, false, true);
     *  }
     *  else if (typeof(T) == typeof(InteractiveObject))
     *  {
     *      return (List<IEnumerable<T>>)getTypes(true, true, true, false);
     *  }
     *  else if (typeof(T) == typeof(DestructableObject))
     *  {
     *      return (List<IEnumerable<T>>)getTypes(true, true, false, false);
     *  }
     *  else if (typeof(T) == typeof(IndestructableObject))
     *  {
     *      return (List<IEnumerable<T>>)getTypes(false, false, true, false);
     *  }
     *  else if (typeof(T) == typeof(Player))
     *  {
     *      return (List<IEnumerable<T>>)getTypes(true, false, false, false);
     *  }
     *  else if (typeof(T).IsSubclassOf(typeof(NonInteractiveObject))
     *  {
     *      List<IEnumerable<T>> items = new List<IEnumerable<T>>();
     *      foreach (T item in theNonInteractives)
     *      {
     *          if (item.GetType().IsSubclassOf(typeof(T)) || item.GetType() == typeof(T))
     *          {
     *              items[0].Add(item);
     *          }
     *      }
     *      return items;
     *  }
     * }
     */

    //The following methods remove or add the given DestructableObject to the correct list.
    public void RemoveFromGame(DestructableObject remove)
    {
        if (remove.GetType() == typeof(Player))
        {
            remove.DestroyThis();
        }
        else
        {
            removeDestructables.Add(remove);
        }
    }
Beispiel #14
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            //
            DestructableObject sc = (DestructableObject)target;

            //
            if (GUILayout.Button("Destroy"))
            {
                sc.SetShatter();
            }
        }
Beispiel #15
0
 protected override void DestructableObjectCollision(DestructableObject other, Collision2D collision)
 {
     if (other.team != this.team)
     {
         other.DamageThis(scale.x * damageMultiplier * difficultyModifier);
     }
     else if (other.GetType() == typeof(Blob))
     {
         if (mergeTimer == 0 && ((Blob)(other)).mergeTimer == 0 && scale.x + other.scale.x < maxSize)
         {
             MergeWith((Blob)other);
         }
     }
 }
Beispiel #16
0
    private void AddToDictionary()
    {
        //Loop through all gameobjects in scene and add to desObjDictionary of it has a collider and
        // Destructable GameObject Script
        foreach (GameObject gameObj in Object.FindObjectsOfType <GameObject>())
        {
            Collider           col        = gameObj.GetComponent <Collider>();
            DestructableObject destScript = gameObj.GetComponent <DestructableObject>();

            if (col != null && destScript != null)
            {
                GameDataModel.DesObjDictionary.Add(col, destScript);
            }
        }
    }
    private void Awake()
    {
        //on awake gather all componets for reset
        _gameObject    = gameObject;
        _transform     = GetComponent <Transform>();
        _rb            = GetComponent <Rigidbody>();
        _do            = GetComponent <DestructableObject>();
        _ren           = GetComponent <Renderer>();
        _playerPhysics = GetComponent <PlayerPhysics>();
        _fireBreathing = GetComponent <FireBreathing>();
        Track();

        //Add thi to the resetables array within the game manager.
        _GameManager._resetables.Add(this);
    }
Beispiel #18
0
    protected virtual void HandleCollision(Collision collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            if (OnHitObject != null)
            {
                OnHitObject(this);
            }
        }

        // Grab the rigidBody of the collision
        Rigidbody collisionRigidbody = collision.gameObject.GetComponent <Rigidbody>();
        // Grab the Health of the collision
        //Health collisionHealth = collision.gameObject.GetComponent<Health>();
        DestructableObject collisionDestructable = collision.gameObject.GetComponent <DestructableObject>();

        // If the collision has a rigidBody
        if (collisionRigidbody != null)
        {
            // if this object has health
            if (health != null)
            {
                // Damage this object based of the magnitude of the relative velocity
                Damage(Mathf.RoundToInt(collision.relativeVelocity.magnitude));
            }

            // if collision object has health
            //if (collisionHealth!=null)
            //    // Damage collision object based of the magnitude of the relative velocity
            //    collisionHealth.Damage(Mathf.RoundToInt(collision.relativeVelocity.magnitude));

            if (collisionDestructable != null)
            {
                // Damage collision object based of the magnitude of the relative velocity
                collisionDestructable.Damage(Mathf.RoundToInt(collision.relativeVelocity.magnitude));
            }

            // If the collision has run out of health
            //if (collisionHealth!=null && collisionHealth.currentHealth <= 0)
            //    // Break that object
            //    collision.gameObject.GetComponent<DestructableObject>().BreakObject();

            // If this object has run out of health
            //if (health!= null && health.currentHealth <= 0)
            //    // Break this object
            //    BreakObject();
        }
    }
Beispiel #19
0
    public void ShowBuildingInfo()
    {
        DestructableObject DO = BuildManager.instance.prevHighlighted;

        if (DO != null)
        {
            GameObject GO = DO.gameObject;

            selectedBuilding = GO.GetComponent <Building>();

            UpdateBuildingInfo();

            buildingInfoPanel.transform.position = Input.mousePosition + new Vector3(buildingInfoPanel.GetComponent <RectTransform>().rect.width / 2.0f + 20, buildingInfoPanel.GetComponent <RectTransform>().rect.height / 2.0f + 20);
            buildingInfoPanel.SetActive(true);
        }
    }
Beispiel #20
0
    protected override void LeftClick()
    {
        anim.Play("Bat Swing");

        //base.LeftClick();
        Ray        ray;
        RaycastHit hit;

        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, 4))
        {
            DestructableObject destructableObject = hit.collider.gameObject.GetComponent <DestructableObject>();
            if (destructableObject != null)
            {
                destructableObject.Damage(100);
            }
        }
    }
Beispiel #21
0
    void Update()
    {
        if (attackActive)
        {
            RaycastHit hit;
            Vector3    directionHeightOffset = new Vector3(0f, -0.5f + (((int)activeStrikeType) * 0.5f), 0f);

            //Casts a Raycast and checks if it hit a Destructable Object (such as a crate or an enemy).
            if (Physics.Raycast(transform.position + bodyCollider.center + directionHeightOffset + additionalOffset, Vector3.right, out hit, 1.5f))
            {
                DestructableObject hitObject = hit.transform.GetComponent <DestructableObject>();
                if (hitObject)
                {
                    attackActive = false;
                    hitObject.OnDestruction(activeStrikeType, playerCharacter.attackDamage);
                }
            }
        }
    }
Beispiel #22
0
    void Shoot()
    {
        muzzleFlash.Play(); //show muzzle flash

        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            if (hit.collider.tag == "Enemy")
            {
                DestructableObject DO = hit.collider.gameObject.GetComponent <DestructableObject>();

                if (DO != null)
                {
                    DO.TakeDamage(damage);
                    Debug.Log("Hit Enemy: " + DO.health + " Hp");
                }
            }
        }
    }
 public void ObjectHit(DestructableObject obj)
 {
     Debug.Log(obj.name + " hit");
     currentMission.CheckMissionObjectives(obj.gameObject.tag, zonesInside, ObjectiveType.Kick);
 }
Beispiel #24
0
 protected override void DestructableObjectCollision(DestructableObject other, Collision2D collision)
 {
     other.DamageThis(damage);
     DestroyThis();
 }
Beispiel #25
0
 public void AddObject(DestructableObject obj)
 {
     objectsList.Add(obj);
 }
Beispiel #26
0
 public void RemoveObject(DestructableObject obj)
 {
     objectsList.Remove(obj);
 }
Beispiel #27
0
    protected virtual void Fire(Transform origin)
    {
        GameObject prefab     = projectilePrefab;
        var        projectile = prefab.GetComponent <Projectile>();
        int        faceIndex  = -1;
        string     playerID   = "";

        if (delivery == ProjectileDeliveryMethod.Rigidbody)
        {
            var projectileInstance = projectile.isPooled ? NetworkObjectPool.Instance.GetInstance(prefab) : Instantiate(prefab);
            projectileInstance.transform.position = origin.position;
            projectileInstance.transform.rotation = origin.rotation;

            if (!projectile.isPooled)
            {
                projectileInstance.gameObject.SetActive(true);
                NetworkServer.Spawn(projectileInstance);
            }

            if (OnProjectileSpawned != null)
            {
                OnProjectileSpawned.Invoke(projectileInstance);
            }

            RpcFire(projectileInstance);
        }
        else if (delivery == ProjectileDeliveryMethod.Raycast)
        {
            var hit = new RaycastHit();

            if (Physics.Raycast(origin.position, origin.forward, out hit, 100.0f, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore))
            {
                Debug.DrawRay(origin.position, origin.forward, Color.green);
                var damageable = hit.transform.GetComponentInParent <Damageable>();

                if (damageable && projectile)
                {
                    damageable.RaycastHit(projectile.profile.damage, prefab, hit, m_Owner);
                    if (!damageable.Alive)
                    {
                        //damageable.Hit(projectile.profile.damage, projectile.gameObject, null, false, hit.point.x, hit.point.y, hit.point.z);
                        DestructableObject dest = hit.transform.GetComponent <DestructableObject>();
                        if (dest != null)
                        {
                            Vector3 vel  = origin.forward * projectile.profile.speed;
                            float   mass = projectile.GetComponent <Rigidbody>().mass;
                            dest.RaycastDestruct(mass, vel);
                            dest.RpcRaycastDestruct(mass, vel);
                        }
                    }
                }
                // Face damage
                BulletTriggerForFace btff = (BulletTriggerForFace)hit.transform.GetComponent(typeof(BulletTriggerForFace));
                if (btff != null)
                {
                    faceIndex = btff.FindHitIndex(hit.point);
                    playerID  = btff.playerRef.sPlrData.playerID;
                }
            }

            OnProjectileRaycast.Invoke(projectile, hit);
            RpcRaycast(origin.position, origin.forward, faceIndex, playerID);
        }
    }
Beispiel #28
0
    //
    public void Dead(string tag, Collider2D col = null)
    {
        if (isDead || isInvincible)
        {
            return;
        }
        //
        switch (shieldState)
        {
        case ShieldEffect.ShieldState.NONE:
            break;

        case ShieldEffect.ShieldState.NORMAL:
        {
            if ((tag != "Concrete") && (tag != "Crash"))
            {
                ActiveShield();
                return;
            }
        }
        break;

        case ShieldEffect.ShieldState.ACTIVE:
        {
            if ((tag != "Concrete") && (tag != "Crash"))
            {
                return;
            }
        }
        break;

        default:
            break;
        }
        //
        // Dead Sequance
        //Debug.Log("Player Dead By [" + tag + "]");
        isDead = true;
        GameManager.instance.gameOver = true;
        //
        SceneControl.instance.SaveRecord();
        // Shatter Effect
        GameObject         obj = Instantiate(dummyDestroy, transform.position, Quaternion.identity);
        DestructableObject dd  = obj.GetComponent <DestructableObject>();

        dd.Flip(sr.flipX);
        if (col != null)
        {
            Vector3 dir = col.transform.position - tf.position;
            switch (tag)
            {
            case "Explosion":
                break;

            case "Thunder":
            {
                float x = dir.x >= 0 ? 7.0f : -7.0f;
                dir.x = x;
                dir.y = 0;
            }
            break;

            case "Laser":
            {
                float y = dir.y >= 0 ? 7.0f : -7.0f;
                dir.x = 0;
                dir.y = y * 2.0f;
            }
            break;

            case "Crash":
            {
                dir.x = 0;
                dir.y = -20.0f;
            }
            break;

            default:
                break;
            }
            Vector3 spcPos = tf.position + dir;
            dd.spc.transform.position = spcPos;
        }
        dd.SetShatter();
        SoundManager.instance.Play(SoundKey.DEAD);

        gameObject.SetActive(false);
        //
        GameManager.instance.ReloadPlayScene();
    }
Beispiel #29
0
 protected override void DestructableObjectCollision(DestructableObject other, Collision2D collision)
 {
 }
Beispiel #30
0
 public void AddToGame(DestructableObject add)
 {
     addDestructables.Add(add);
 }
 protected abstract void DestructableObjectCollision(DestructableObject other);
 public void  ObjectBreak(DestructableObject obj)
 {
     Debug.Log(obj.name + " destroyed");
     currentMission.CheckMissionObjectives(obj.gameObject.tag, zonesInside, ObjectiveType.Break);
 }