Exemple #1
0
    private void OnReceivePath(TankUnit unit, int index, Path path)
    {
        unit.instances[index].path           = path;
        unit.instances[index].pathUpdateTime = Time.time + pathUpdateInterval;

        unit.instances[index].hasRequestedPath = false;
    }
 public bool HasClearShot(TankUnit enemyUnit)
 {
     if (Match.map.GetObstacleDistance(Tank.GetPosition(), enemyUnit.Tank.GetPosition()) == null)
     {
         return(true);
     }
     return(false);
 }
Exemple #3
0
    private void RequestPath(TankUnit unit, int index, Vector3 target)
    {
        unit.instances[index].hasRequestedPath = true;

        PathRequestManager.RequestPath(
            start:                          unit.instances[index].tank.transform.position,
            end:                            target,
            preferBreakWalls:       unit.behaviour.preferBreakWalls,
            callback:                       path => OnReceivePath(unit, index, path)
            );
    }
Exemple #4
0
    public void Spawn(TankType type, Vector3 position)
    {
        TankUnit unit  = units[type];
        int      index = unit.nextIndex;

        unit.nextIndex++;

        var tank = unit.instances[index].tank;

        tank.GetComponent <Breakable>().OnBreak += () => UnSpawn(type, index);
        tank.OnCollideBreakable += breakable => AddTargetBreakable(type, index, breakable);
        tank.collisionMask       = tankCollisionMask;

        StartCoroutine(UnearthTank(tank, position, type, index));
    }
Exemple #5
0
    void OnCollisionEnter(Collision collision)
    {
        TankUnit tank = collision.gameObject.GetComponent <TankUnit>();
        HeliUnit heli = collision.gameObject.GetComponent <HeliUnit>();

        if (tank != null && tank.IsUpsideDown() && tank.owner == this.owner)
        {
            tank.Repair();
            Destroy(this.gameObject);
        }
        else if (heli != null && heli.enabled == false && heli.owner == this.owner)
        {
            heli.Repair();
            heli.enabled = true;
            Destroy(this.gameObject);
        }

        if (collision.gameObject.GetComponent <Unit>() != null)
        {
            this.standing = false;
        }
    }
        private void simulateTurn(TankUnit activeUnit, TankUnit enemyUnit, int step)
        {
            if (step % reloadSteps == 0 && activeUnit.HasLowAmmo())
            {
                activeUnit.Tank.Reload();
            }

            // enemy in range and in line of sight
            if (activeUnit.IsEnemyInRange(enemyUnit) && activeUnit.HasClearShot(enemyUnit))
            {
                if (activeUnit.Tank.Shoot())
                {
                    enemyUnit.Tank.TakeHit();
                }

                // run away if low on ammo and in enemy range
                if (activeUnit.HasLowAmmo() && activeUnit.IsInEnemyRange(enemyUnit))
                {
                    activeUnit.MoveTowards(activeUnit.Tank.GetPosition() - (enemyUnit.Tank.GetPosition() - activeUnit.Tank.GetPosition()));
                }
            }
            // enemy not in range or not in line of sight
            else
            {
                // advance towards the enemy and shoot if in range
                activeUnit.MoveTowards(enemyUnit.Tank.GetPosition());

                if (activeUnit.IsEnemyInRange(enemyUnit) && activeUnit.HasClearShot(enemyUnit))
                {
                    if (activeUnit.Tank.Shoot())
                    {
                        enemyUnit.Tank.TakeHit();
                    }
                }
            }
        }
 public MatchSimulator(Map map, Tank tank1, Tank tank2)
 {
     this.map  = map;
     tankUnit1 = new TankUnit(this, tank1);
     tankUnit2 = new TankUnit(this, tank2);
 }
 public bool IsInEnemyRange(TankUnit enemyUnit)
 {
     return(enemyUnit.Range > Vector2.Distance(Tank.GetPosition(), enemyUnit.Tank.GetPosition()));
 }