コード例 #1
0
 void OnDestroy()
 {
     if ((this._pathPositions != null) && (PathScript.sharedInstance() != null))
     {
         PathScript.sharedInstance().removeSegmentsFromPositions(this._pathPositions);
     }
 }
コード例 #2
0
    public void blockPathPosition(Position pos)
    {
        bool positionIsInPath = false;
        int  i = this._pathPositionIndex;

        while (!positionIsInPath && i < this._pathPositions.Count)
        {
            Position p = (Position)this._pathPositions[i];
            positionIsInPath = (pos.isEqualTo(p));
            i++;
        }

        if (positionIsInPath)
        {
            Position  startPos = (Position)this._pathPositions[this._pathPositionIndex - 1];
            Position  endPos   = MapScript.sharedInstance().getHomePosition();
            ArrayList positions;
            if (PathScript.sharedInstance().existsPathFromPosToPos(startPos, endPos, out positions))
            {
                PathScript.sharedInstance().addSegmentsFromPositions(positions);
                PathScript.sharedInstance().removeSegmentsFromPositions(this._pathPositions);
                this._pathPositions     = positions;
                this._pathPositionIndex = 0;
                this.getNextPosition();
            }
        }
    }
コード例 #3
0
ファイル: MapScript.cs プロジェクト: ricardperez/RowerRefense
 void updateSelectionIsAvailable()
 {
     if (this._selectedPosition.isEqualTo(this._homePosition) || this._selectedPosition.isEqualTo(this._doorPosition))
     {
         this.setSelectionIsAvailable(false);
     }
     else
     {
         DefenseScript d;
         if (CreateDefensesScript.sharedInstance().anyDefenseAtPosition(this._selectedPosition, out d))
         {
             this.setSelectionIsAvailable(false);
         }
         else
         {
             ArrayList pathPositions;
             if (PathScript.sharedInstance().existsPathFromPosToPosIfBlockingPosition(this.getDoorPosition(), this.getHomePosition(), this._selectedPosition, out pathPositions))
             {
                 this.setSelectionIsAvailable(true);
             }
             else
             {
                 this.setSelectionIsAvailable(false);
             }
         }
     }
 }
コード例 #4
0
 // Update is called once per frame
 void Update()
 {
     if (!this._startPositionGot)
     {
         ArrayList checkpoints = PathScript.sharedInstance().getPathCheckpointsPositions();
         if (checkpoints != null)
         {
             Position firstPosition = (Position)checkpoints[0];
             this._startPosition    = MapScript.sharedInstance().getPointForMapCoordinates(firstPosition);
             this._startPositionGot = true;
         }
     }
     else
     {
         if (this.isWaiting())
         {
             this._timeToStartRound -= Time.deltaTime;
             if (!this.isWaiting())
             {
                 this._nRounds++;
                 this._secondsPerEnemy = (this.startSecondsPerEnemy / (1 + this._nRounds / 5.0f));
             }
         }
         else
         {
             bool addEnemy = false;
             if (this._nEnemiesInCurrentRound == 0)
             {
                 addEnemy = true;
             }
             else
             {
                 this._timeSinceLastEnemy += Time.deltaTime;
                 if (this._timeSinceLastEnemy >= this._secondsPerEnemy)
                 {
                     addEnemy = true;
                 }
             }
             if (addEnemy)
             {
                 this.addEnemy();
                 if (this._nEnemiesInCurrentRound == this.nEnemiesPerRound)
                 {
                     this._nEnemiesInCurrentRound = 0;
                     this._timeToStartRound       = this.timeBetweenRounds;
                 }
             }
         }
     }
 }
コード例 #5
0
ファイル: MapScript.cs プロジェクト: ricardperez/RowerRefense
    public bool tryToBlockPosition(Position pos)
    {
        DefenseScript defense;
        bool          anyDefense = CreateDefensesScript.sharedInstance().anyDefenseAtPosition(pos, out defense);

        if (anyDefense)
        {
            return(false);
        }
        else
        {
            bool pathCanBlockPosition = PathScript.sharedInstance().blockPosition(pos);
            return(pathCanBlockPosition);
        }
    }
コード例 #6
0
ファイル: MapScript.cs プロジェクト: ricardperez/RowerRefense
    // Use this for initialization
    void Start()
    {
        this._floorPlane   = new Plane(this.map.transform.up, (this.map.transform.position + Vector3.up * this.map.transform.localScale.y * 0.5f));
        this._tileSize     = new Vector2((this.map.transform.localScale.x / this.mapWidth), (this.map.transform.localScale.z / this.mapHeight));
        this._mapOrigin    = this.map.transform.position;
        this._mapOrigin.x -= (this._tileSize.x * this.mapWidth * 0.5f - this._tileSize.x * 0.5f);
        this._mapOrigin.y -= (this._tileSize.y * this.mapHeight * 0.5f - this._tileSize.y * 0.5f);

        Vector3 selScale = this.selection.transform.localScale;

        selScale.x = this._tileSize.x;
        selScale.z = this._tileSize.y;
        this.selection.transform.localScale = selScale;

        Vector3 doorScale = this.door.transform.localScale;

        doorScale.x = this._tileSize.x;
        doorScale.z = this._tileSize.y;
        this.door.transform.localScale = doorScale;
        this._doorPosition             = new Position(0, 0);

        Vector3 homeScale = this.home.transform.localScale;

        homeScale.x = this._tileSize.x;
        homeScale.z = this._tileSize.y;
        this.home.transform.localScale = homeScale;
        this._homePosition             = new Position(this.mapWidth / 2, this.mapHeight / 2);

        this.setPositionForTile(this.door, this._doorPosition);
        this.setPositionForTile(this.home, this._homePosition);

        this.map.renderer.material.mainTextureScale = new Vector2(this.mapWidth, this.mapHeight);


        this._selectedPosition = new Position(-1, -1);
        _selectionVisible      = true;
        this.setSelectionPosition(new Position(0, 0));
        this.setSelectionVisible(false);

        PathScript.sharedInstance().recalculatePath();

        _isRendering2d = false;
        this.set2dRendering();

        this._selectionIsAvailable = true;
    }
コード例 #7
0
    // Use this for initialization
    void Start()
    {
        this._pathPositions = (ArrayList)PathScript.sharedInstance().getPathCheckpointsPositions().Clone();
        PathScript.sharedInstance().addSegmentsFromPositions(this._pathPositions);

        Position firstPosition = (Position)this._pathPositions[0];

        this._pathPositionIndex = 0;
        this.transform.position = MapScript.sharedInstance().getPointForMapCoordinates(firstPosition);
        this.getNextPosition();

        foreach (Transform child in this.transform)
        {
            if (child.tag == "LifeBar")
            {
                this._lifeBar = child.gameObject;
                break;
            }
        }

        this._initialLife = this.life;
    }