Exemplo n.º 1
0
    public override void onTargetReached()
    {
        Vector3 explodePosition = m_target.transform.position;

        if (m_target != null)
        {
            DestroyObject(m_target);
        }
        GameObject [] aAllEnemies = TDWorld.getWorld().getAllEnemiesUnsafe();
        foreach (GameObject thisObject in aAllEnemies)
        {
            if (thisObject == null)
            {
                continue;
            }
            if ((thisObject.transform.position - explodePosition).magnitude > TDWorld.getWorld().m_configuration.towerCanonBallDamageRadius)
            {
                continue;
            }
            TDEnemy enemy = TDWorld.getWorld().getTDEnemy(thisObject);
            if (enemy == null)
            {
                continue;
            }
            if (enemy.canFly())
            {
                continue;
            }
            enemy.receiveDamage(m_damage.clone(enemy), null);
        }
    }
Exemplo n.º 2
0
 protected void deadTime()
 {
     if (Time.time - m_deathTime > TDWorld.getWorld().m_configuration.heroDeathTime)
     {
         resurrect();
     }
 }
Exemplo n.º 3
0
    void fightHero()
    {
        TDWorld world = TDWorld.getWorld();
        TDHero  hero  = world.getTDHero();

        if (!hero.isAlive())
        {
            m_state = State.eRunToPlayer;
            cleanPath();
            return;
        }
        if ((hero.transform.position - transform.position).magnitude < fightRadius())
        {
            cleanPath();
            TDDamage damage = new TDDamage(TDDamage.Type.ePhysical, physicalDamage() * Time.deltaTime, 0.0f);           // Replace by override TDEnemy::getDamage
            hero.receiveDamage(damage, this);
        }
        else
        {
            if ((null == m_path) || (Time.time - m_timer > world.m_configuration.enemyRecalcPathTime))
            {
                m_timer = Time.time;
                hasPathTo(hero.gameObject);
            }
        }
    }
Exemplo n.º 4
0
    protected override void onTargetReached(GameObject obj)
    {
        TDWorld    world  = TDWorld.getWorld();
        GameObject player = world.getPlayer();

        if (obj == player)
        {
            return;
        }

        TDEnemy tdEnemy = world.getTDEnemy(obj);

        if (null != tdEnemy)
        {
            m_state = State.eFight;
            return;
        }

        if (world.isFakeTarget(obj))
        {
            DestroyObject(obj);
        }

        m_state = State.ePatrol;
    }
Exemplo n.º 5
0
    private void fight()
    {
        TDWorld world   = TDWorld.getWorld();
        TDEnemy tdEnemy = world.getTDEnemy(target());

        if (null == tdEnemy)
        {
            m_state = State.ePatrol;
            return;
        }
        if ((target().transform.position - transform.position).magnitude > world.m_configuration.heroFightRadius)
        {
            if (hasPathTo(target()))
            {
                m_state = State.eWalk;
            }
            else
            {
                m_state = State.ePatrol;
            }
            return;
        }
        TDDamage damage = new TDDamage(TDDamage.Type.ePhysical, world.m_configuration.heroPhysicalDamagePerSec * Time.deltaTime, 0f);

        tdEnemy.receiveDamage(damage, this);
    }
Exemplo n.º 6
0
    public override void moveToTarget()
    {
        Vector3 dir = m_target.transform.position - transform.position;

        dir.y = 0f;
        float pathGone = 1.0f - dir.magnitude / m_startDistance;

        if (m_pathGone > pathGone)
        {
            onTargetReached();
            return;
        }
        m_pathGone = pathGone;
        dir.Normalize();
        dir *= speed() * Time.deltaTime;
        transform.Translate(dir);
        // Parabola y = ax^2 + c
        float a = 0f, b = 0f, c = 0f;

        if (pathGone < 0.5f)
        {
            a = 4.0f * (-2.5f + TDWorld.getWorld().m_configuration.towerCanonBallParabolaHeight);
            b = 1f;
            c = 2.0f;
        }
        else
        {
            pathGone -= 0.5f;
            a         = -4.0f * TDWorld.getWorld().m_configuration.towerCanonBallParabolaHeight;
            c         = TDWorld.getWorld().m_configuration.towerCanonBallParabolaHeight;
        }
        float y = a * (pathGone * pathGone) + b * pathGone + c;

        transform.position = new Vector3(transform.position.x, y, transform.position.z);
    }
Exemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        if (TDWorld.getWorld().m_configuration.drawGrid == 0)
        {
            return;
        }
        TDGrid grid = TDWorld.getWorld().m_grid;

        if (grid == null)
        {
            return;
        }
        if (m_aLines == null)
        {
            m_aLines = new GameObject[grid.nbCellsX + grid.nbCellsY + 2];
            GameObject terrainGridLinePrefab = (GameObject)Resources.Load("TerrainGridLinePrefab");
            for (int i = 0; i < m_aLines.Length; i++)
            {
                GameObject obj = (GameObject)Instantiate(terrainGridLinePrefab, new Vector3(), new Quaternion());
                m_aLines[i] = obj;
                obj.AddComponent <LineRenderer>();
            }
        }

        int   lrCount = 0;
        float startX  = grid.m_startX;
        float startY  = grid.m_startY;
        float stepX   = grid.m_gridX;
        float stepY   = grid.m_gridY;

        for (uint i = 0; i <= grid.nbCellsX; i++)
        {
            GameObject line = m_aLines[lrCount];
            lrCount++;
            LineRenderer lineRenderer = line.GetComponent <LineRenderer>();
            lineRenderer.SetWidth(1, 1);
            lineRenderer.SetColors(Color.blue, Color.blue);
            lineRenderer.SetVertexCount(2);
            Vector3 startLine = new Vector3(startX + ((float)i) * stepX, startY, 0);
            Vector3 endLine   = new Vector3(startX + ((float)i) * stepX, startY + grid.width, 0);
            lineRenderer.SetPosition(0, TDWorld.getWorld().from2dTo3d(startLine));
            lineRenderer.SetPosition(1, TDWorld.getWorld().from2dTo3d(endLine));
        }

        for (uint i = 0; i <= grid.nbCellsY; i++)
        {
            GameObject line = m_aLines[lrCount];
            lrCount++;
            LineRenderer lineRenderer = line.GetComponent <LineRenderer>();
            lineRenderer.SetWidth(1, 1);
            lineRenderer.SetColors(Color.blue, Color.blue);
            lineRenderer.SetVertexCount(2);
            Vector3 startLine = new Vector3(startX, startY + ((float)i) * stepY, 0);
            Vector3 endLine   = new Vector3(startX + grid.length, startY + ((float)i) * stepY, 0);
            lineRenderer.SetPosition(0, TDWorld.getWorld().from2dTo3d(startLine));
            lineRenderer.SetPosition(1, TDWorld.getWorld().from2dTo3d(endLine));
        }
    }
Exemplo n.º 8
0
    // Use this for initialization
    protected override void Start()
    {
        base.Start();
        GameObject respawnPoint = TDWorld.getWorld().getHeroRespawnPoint();

        transform.position = respawnPoint.transform.position;
        m_state            = State.ePatrol;
        receiveModifier(new TDHealthRegeneration(10000.0f, TDWorld.getWorld().m_configuration.heroAutoHealPerSec));
    }
Exemplo n.º 9
0
    protected void resurrect()
    {
        m_HP = getStartHP();
        GameObject respawnPoint = TDWorld.getWorld().getHeroRespawnPoint();

        transform.position = respawnPoint.transform.position;
        m_state            = State.ePatrol;
        renderer.enabled   = true;
        DestroyObject(m_cross);
    }
Exemplo n.º 10
0
    protected override void onTargetReached(GameObject obj)
    {
        TDWorld    world  = TDWorld.getWorld();
        GameObject player = world.getPlayer();

        if (obj == player)
        {
            TDPlayer tdP = world.getTDPlayer();
            tdP.receiveDamage(1);
        }
        DestroyObject(gameObject);
    }
Exemplo n.º 11
0
    // Update is called once per frame
    void Update()
    {
        float currentTime = Time.time;
        float respawn     = getRestoration();

        if (currentTime < (m_restTime + respawn))
        {
            return;
        }
        GameObject [] aAllEnemies = TDWorld.getWorld().getAllEnemiesUnsafe();
        double        recDist     = -1;
        GameObject    recObject   = null;
        TDDamage      damage      = getTowerDamage();

        foreach (GameObject thisObject in aAllEnemies)
        {
            if (thisObject == null)
            {
                continue;
            }
            float dist            = (transform.position - thisObject.transform.position).magnitude;
            float efficientRadius = getEfficientRadius();
            if (dist < efficientRadius)
            {
                TDEnemy enemy = TDWorld.getWorld().getTDEnemy(thisObject);
                if (enemy.canFly())
                {
                    if (!shootsFlying())
                    {
                        continue;
                    }
                }
                if (!TDWorld.getWorld().m_strategy.shouldShootAt(enemy, damage))
                {
                    continue;
                }
                if ((recDist < 0) || (recDist > dist))
                {
                    recDist   = dist;
                    recObject = thisObject;
                }
            }
        }
        if (recObject == null)
        {
            return;
        }
        TDEnemy recEnemy = TDWorld.getWorld().getTDEnemy(recObject);

        TDWorld.getWorld().m_strategy.shootingAt(recEnemy, damage);
        shootTo(recEnemy);
        m_restTime = Time.time;
    }
Exemplo n.º 12
0
 protected override void setTarget(GameObject newTarget)
 {
     if (null != target())
     {
         TDWorld world = TDWorld.getWorld();
         if (world.isFakeTarget(target()))
         {
             DestroyObject(target());
         }
     }
     base.setTarget(newTarget);
 }
Exemplo n.º 13
0
    public void runToBase()
    {
        GameObject player = TDWorld.getWorld().getPlayer();

        if (hasPathTo(player))
        {
            m_state = State.eWalk;
        }
        else
        {
            m_state = State.ePatrol;
        }
    }
Exemplo n.º 14
0
 override public void receiveDamage(TDDamage damage, TDActor source)
 {
     base.receiveDamage(damage, source);
     if (null != source)
     {
         TDWorld world = TDWorld.getWorld();
         TDHero  hero  = world.getTDHero();
         if (source == hero)
         {
             m_state = State.eFightHero;
         }
     }
 }
Exemplo n.º 15
0
    // Use this for initialization
    protected override void Start()
    {
        base.Start();
        GameObject enemyHealthPrefab = (GameObject)Resources.Load("EnemyHealthBarPrefab");

        m_healthBar = (GameObject)Instantiate(enemyHealthPrefab, new Vector3(0.5f, 0.5f), new Quaternion());
        updateHealthBar();

        TDWorld    world  = TDWorld.getWorld();
        GameObject player = world.getPlayer();

        hasPathTo(player);

        m_state = State.eRunToPlayer;

        m_timer = Time.time;
    }
Exemplo n.º 16
0
    // Update is called once per frame
    void Update()
    {
        if (m_target == null)
        {
            Destroy(gameObject);
            return;
        }
        moveToTarget();
        Vector3 dir  = m_target.transform.position - transform.position;
        float   dist = dir.magnitude;

        // Second condition prevents round-off situation when target is almost reached but not damaged
        if ((dist < TDWorld.getWorld().m_configuration.hitDistance) ||
            (dist > (m_recDistance + TDWorld.getWorld().m_configuration.hitDistance)))
        {
            onTargetReached();
            Destroy(gameObject);
        }
        m_recDistance = dist;
    }
Exemplo n.º 17
0
    void OnDestroy()
    {
        Destroy(m_healthBar);
        if (OnEventDestroy != null)
        {
            OnEventDestroy(this);
        }
        TDWorld world = TDWorld.getWorld();

        if (world == null)
        {
            return;
        }
        TDPlayer player = world.getTDPlayer();

        if (player == null)
        {
            return;
        }
        player.reward(killReward());
    }
Exemplo n.º 18
0
    bool buildPath(GameObject target)
    {
        m_currentCellIndex = -1;
        setTarget(null);
        TDWorld world = TDWorld.getWorld();
        TDGrid  grid  = world.m_grid;

        TDGrid.Cell startCell  = grid.getCell(world.from3dTo2d(gameObject.transform.position));
        TDGrid.Cell endCell    = grid.getCell(world.from3dTo2d(target.transform.position));
        bool        pathExists = false;

        if (canFly())
        {
            pathExists = grid.buildAirPath(startCell, endCell, out m_path);
        }
        else
        {
            pathExists = grid.buildPath(startCell, endCell, out m_path);
        }
        m_currentCellIndex = 0;
        setTarget(target);
        return(pathExists);
    }
Exemplo n.º 19
0
    private void patrol()
    {
        m_path = null;
        TDWorld world = TDWorld.getWorld();

        GameObject [] aEnemies = world.getAllEnemiesUnsafe();
        foreach (GameObject enemy in aEnemies)
        {
            if ((enemy.transform.position - transform.position).magnitude < world.m_configuration.heroPatrolRadius)
            {
                TDEnemy tdEnemy = world.getTDEnemy(enemy);
                if (tdEnemy.canFly())
                {
                    continue;
                }
                if (hasPathTo(enemy))
                {
                    m_state = State.eWalk;
                    break;
                }
            }
        }
    }
Exemplo n.º 20
0
    void runToPlayer()
    {
        TDWorld world = TDWorld.getWorld();

        if ((null == m_path) || (Time.time - m_timer > world.m_configuration.enemyRecalcPathTime))
        {
            GameObject player = world.getPlayer();
            m_timer = Time.time;
            hasPathTo(player);
        }
        TDHero hero = world.getTDHero();

        if (hero.isAlive())
        {
            if ((hero.transform.position - transform.position).magnitude < heroHostileRadius())
            {
                if (Random.value < heroHostileChance())
                {
                    cleanPath();
                    m_state = State.eFightHero;
                }
            }
        }
    }
Exemplo n.º 21
0
 public override float getStartSpeed()
 {
     return(TDWorld.getWorld().m_configuration.enemyGargoyleSpeed);
 }
Exemplo n.º 22
0
 protected override float fightRadius()
 {
     return(TDWorld.getWorld().m_configuration.enemyGargoyleFightRadius);
 }
Exemplo n.º 23
0
 protected override float physicalDamage()
 {
     return(TDWorld.getWorld().m_configuration.enemyGargoylePhysicalDamagePerSec);
 }
Exemplo n.º 24
0
 protected override float heroHostileRadius()
 {
     return(TDWorld.getWorld().m_configuration.enemyGargoyleHeroHostileRadius);
 }
Exemplo n.º 25
0
 public override uint getStartHP()
 {
     return(TDWorld.getWorld().m_configuration.enemyGargoyleHP);
 }
Exemplo n.º 26
0
 protected override uint killReward()
 {
     return(TDWorld.getWorld().m_configuration.enemyGargoyleKillReward);
 }
Exemplo n.º 27
0
 public override float getRestoration()
 {
     return(TDWorld.getWorld().m_configuration.towerArcherRestoration);
 }
Exemplo n.º 28
0
 public override uint price()
 {
     return(TDWorld.getWorld().m_configuration.towerArcherPrice);
 }
Exemplo n.º 29
0
 public override TDDamage getTowerDamage()
 {
     return(new TDDamage(TDDamage.Type.ePhysical, TDWorld.getWorld().m_configuration.towerArcherPhysicalDamage, 0));
 }
Exemplo n.º 30
0
 public override float getEfficientRadius()
 {
     return(TDWorld.getWorld().m_configuration.towerArcherRadius);
 }