public static void AddEntityCollider(Vector3 colliderPosition, Entity entityToLink)
    {
        /* TODO We will eventually reach INT_MAX with collidersSpawned.
         * We need to change the solution. */

        // Spawn new gameobject and attach box collider to it
        GameObject     gm             = new GameObject("Sector Collider" + collidersSpawned);
        EntityCollider entityCollider = gm.AddComponent <EntityCollider>();

        // Modify components
        entityCollider.EntityColliderIndex = collidersSpawned;
        entityCollider.LinkedEntity        = entityToLink;
        colliders.Add(entityCollider.EntityColliderIndex, entityCollider);
        collidersSpawned++;
        // Link the collider to the entity
        BootStrapper.Entity_Manager.SetComponentData(entityToLink, new EntityLinkedColliderData {
            Value = entityCollider.EntityColliderIndex
        });
        // Orientate the gameobject
        entityCollider.transform.position = colliderPosition;
        entityCollider.transform.SetParent(WorldReference.SectorColliderParent);
        // Add a collider to the gameobject
        entityCollider.Collider      = gm.AddComponent <BoxCollider>();
        entityCollider.Collider.size = (BootStrapper.Entity_Manager.GetComponentData <EntityBoundsData> (entityToLink)).Value;
    }
Exemple #2
0
 void RemoveWorldEntity()
 {
     if (hit.collider != null)
     {
         EntityCollider entityCollider = hit.collider.GetComponent <EntityCollider>();
         if (entityCollider != null)
         {
             EntitySpawner.DestroyEntity(entityCollider.LinkedEntity);
         }
     }
 }
 public static void RemoveEntityCollider(EntityLinkedColliderData colliderData)
 {
     try {
         EntityCollider temp = GetEntityCollider(colliderData);
         colliders.Remove(colliderData.Value);
         MonoBehaviour.Destroy(temp.gameObject);
     }
     catch (Exception e) {
         Debug.LogException(e);
     }
 }
Exemple #4
0
        public bool HasHitBarrier(List <Barrier> barriers_)
        {
            foreach (Barrier b in barriers_)
            {
                EntityCollider fuckDean          = new EntityCollider(m_collider);
                Vector2        m_newPosition     = fuckDean.GetPosition() + m_velocity;
                Vector2        m_barrierPosition = b.GetPosition();

                fuckDean.SetPosition(m_collider.GetPosition() + m_velocity);

                if (CollisionHandler.CheckForCollision(fuckDean, b.GetCollider()))
                {
                    Debug.AddText(new DebugText("New Position = " + m_newPosition, new Vector2(10.0f, 180.0f)));

                    return(true);
                }
            }
            return(false);
        }
Exemple #5
0
    void OnCollide(EntityCollider collider, RaycastHit hit)
    {
        float hurtAmt = 0;

        if(hit.transform.gameObject.layer == Main.layerEnemy) {
            Enemy enemy = hit.transform.GetComponentInChildren<Enemy>();
            if(enemy.state != State.die) {
                EnemyStat enemyStat = enemy.stat != null ? enemy.stat as EnemyStat : null;
                if(enemyStat != null) {
                    if(state == State.attack) {
                        if(!enemy.isBlinking && enemy.state != State.spawning) {
                            enemyStat.curHP -= stat.damage;
                        }
                    }
                    else if(enemyStat.damage > 0) {
                        hurtAmt = enemyStat.damage;
                    }

                    if(enemyStat.level >= SceneWorld.instance.curLevel) {
                        Vector3 enemyPos = hit.transform.position;
                        Vector3 pos = transform.position;

                        if(pos.y > enemyPos.y) {
                            entMove.Jump(attackHitJumpSpd*mScale, false);
                        }
                        else {
                            entMove.ResetCurYVel();
                            entMove.Jump(-attackHitJumpSpd*mScale, false);
                        }
                    }
                }
            }
        }
        else if(!isBlinking && hit.transform.gameObject.layer == Main.layerEnemyProjectile) {
            EnemyBullet bullet = hit.transform.GetComponentInChildren<EnemyBullet>();
            if(bullet != null) {
                hurtAmt = bullet.damage;
            }
            else {
                EnemyProjectile proj = hit.transform.GetComponentInChildren<EnemyProjectile>();
                if(proj == null) { //try parent
                    proj = hit.transform.parent.GetComponentInChildren<EnemyProjectile>();
                }

                hurtAmt = proj.damage;
            }
        }

        if(hurtAmt > 0) {
            if(guardActive && mCurNumGuards > 0) {
                GuardDec();
            }
            else {
                stat.curHP -= hurtAmt;
            }
        }
    }
Exemple #6
0
 void Start()
 {
     //start init
     collider    = GetComponent <EntityCollider>();
     newPosition = new Matrix2(transform.position.x, transform.position.y);
 }
 protected virtual void Awake()
 {
     //get components
     ec = GetComponent <EntityCollider>();
     rb = GetComponent <Rigidbody2D>();
 }