Example #1
0
 // checks if a game object's position falls within the camera's current radius
 public bool ContainsUpdate(GameObject gameObject)
 {
     return(GetX1() - (tileWidth * UPDATE_OFF_SCREEN_RANGE) < gameObject.GetX() + gameObject.GetScaledWidth() &&
            GetEndBoundX() + (tileWidth * UPDATE_OFF_SCREEN_RANGE) > gameObject.GetX() &&
            GetY1() - (tileHeight * UPDATE_OFF_SCREEN_RANGE) < gameObject.GetY() + gameObject.GetScaledHeight() &&
            GetEndBoundY() + (tileHeight * UPDATE_OFF_SCREEN_RANGE) > gameObject.GetY());
 }
Example #2
0
        public static float GetAdjustedPositionAfterCollisionCheckX(GameObject gameObject, Map map, Direction direction)
        {
            int   numberOfTilesToCheck = Math.Max(gameObject.GetScaledBounds().Height / map.GetTileset().GetScaledSpriteHeight(), 1);
            float edgeBoundX           = direction == Direction.LEFT ? gameObject.GetScaledBounds().GetX1() : gameObject.GetScaledBounds().GetX2();
            Point tileIndex            = map.GetTileIndexByPosition(edgeBoundX, gameObject.GetScaledBounds().GetY1());

            for (int j = -1; j <= numberOfTilesToCheck + 1; j++)
            {
                MapTile mapTile = map.GetMapTile(tileIndex.X.Round(), tileIndex.Y.Round() + j);
                if (mapTile != null && HasCollidedWithMapTile(gameObject, mapTile, direction))
                {
                    if (direction == Direction.RIGHT)
                    {
                        float boundsDifference = gameObject.GetScaledX2() - gameObject.GetScaledBoundsX2();
                        return(mapTile.GetScaledBoundsX1() - gameObject.GetScaledWidth() + boundsDifference);
                    }
                    else if (direction == Direction.LEFT)
                    {
                        float boundsDifference = gameObject.GetScaledBoundsX1() - gameObject.GetX();
                        return(mapTile.GetScaledBoundsX2() - boundsDifference);
                    }
                }
            }
            foreach (EnhancedMapTile enhancedMapTile in map.GetActiveEnhancedMapTiles())
            {
                if (HasCollidedWithMapTile(gameObject, enhancedMapTile, direction))
                {
                    if (direction == Direction.RIGHT)
                    {
                        float boundsDifference = gameObject.GetScaledX2() - gameObject.GetScaledBoundsX2();
                        return(enhancedMapTile.GetScaledBoundsX1() - gameObject.GetScaledWidth() + boundsDifference);
                    }
                    else if (direction == Direction.LEFT)
                    {
                        float boundsDifference = gameObject.GetScaledBoundsX1() - gameObject.GetX();
                        return(enhancedMapTile.GetScaledBoundsX2() - boundsDifference);
                    }
                }
            }
            return(0);
        }
    void OnTap(Gesture e)
    {
        if (unitToCreate == null || !canCreate)
        {
            return;
        }

        if (!unitToCreate.Recharged)
        {
            return;
        }

        selectedTerrainBlockGO = e.Selection;
        if (selectedTerrainBlockGO == null)
        {
            return;
        }

        selectedTerrainBlock = selectedTerrainBlockGO.GetComponent <TerrainBlock>();
        if (selectedTerrainBlock == null)
        {
            return;
        }

        if (selectedTerrainBlock.HasUnit)
        {
            return;
        }

        if (instiantedUnit == null)
        {
            instiantedUnit = Instantiate(unitToCreate.gameObject) as GameObject;
        }

        instiantedUnit.SetXY(selectedTerrainBlockGO.GetX(), selectedTerrainBlockGO.GetY());

        if (selectedTerrainBlock.HasUnit)
        {
            Destroy(instiantedUnit);
        }
        else
        {
            selectedTerrainBlock.unitOnTerrain = instiantedUnit.GetComponent <Unit>();
            selectedTerrainBlock.unitOnTerrain.terrainBlock = selectedTerrainBlock;
            selectedTerrainBlock.unitOnTerrain.UnitPlaced   = true;
        }

        selectedTerrainBlockGO    = null;
        selectedTerrainBlock      = null;
        instiantedUnit            = null;
        unitToCreate.LastUsedTime = Time.time;
    }
Example #4
0
 public static void SetY(this GameObject go, float y)
 {
     go.SetXYZ(go.GetX(), y, go.GetZ());
 }
Example #5
0
 public static void SetYZ(this GameObject go, float y, float z)
 {
     go.SetXYZ(go.GetX(), y, z);
 }
	void OnTap ( Gesture e ) {
		
		if ( unitToCreate == null || !canCreate ) return;
		
		if ( !unitToCreate.Recharged ) return;
		
		selectedTerrainBlockGO = e.Selection;
		if ( selectedTerrainBlockGO == null ) return;
		
		selectedTerrainBlock = selectedTerrainBlockGO.GetComponent<TerrainBlock>();
		if ( selectedTerrainBlock == null ) return;
		
		if ( selectedTerrainBlock.HasUnit ) return;
		
		if ( instiantedUnit == null )
			instiantedUnit = Instantiate ( unitToCreate.gameObject ) as GameObject;
		
		instiantedUnit.SetXY ( selectedTerrainBlockGO.GetX(), selectedTerrainBlockGO.GetY() );
		
		if ( selectedTerrainBlock.HasUnit )
			Destroy ( instiantedUnit );
		else {
			selectedTerrainBlock.unitOnTerrain = instiantedUnit.GetComponent<Unit>();
			selectedTerrainBlock.unitOnTerrain.terrainBlock = selectedTerrainBlock;
			selectedTerrainBlock.unitOnTerrain.UnitPlaced = true;
		}
		
		selectedTerrainBlockGO = null;
		selectedTerrainBlock = null;
		instiantedUnit = null;
		unitToCreate.LastUsedTime = Time.time;
	}
	void OnDrag ( DragGesture e ) {
		if ( unitToCreate == null || !canCreate ) return;
		
		if ( !unitToCreate.Recharged ) return;
		
		switch ( e.State ) {
		case GestureRecognitionState.Started:
			if ( instiantedUnit == null ) {
				instiantedUnit = Instantiate ( unitToCreate.gameObject ) as GameObject;
				instiantedUnit.renderer.enabled = false;
			}
			
			break;
			
		case GestureRecognitionState.InProgress:
			selectedTerrainBlockGO = e.Selection;
			
			if ( selectedTerrainBlockGO == null ) {
				if ( instiantedUnit != null )
					instiantedUnit.renderer.enabled = false;
				return;
			}
			
			selectedTerrainBlock = selectedTerrainBlockGO.GetComponent<TerrainBlock>();
			if ( selectedTerrainBlock == null ) { 
				if ( instiantedUnit != null )
					instiantedUnit.renderer.enabled = false;
				return;
			}
			
			if ( instiantedUnit != null )
				instiantedUnit.renderer.enabled = true;
			
			if ( highlightedTerrainBlocks != null )
			foreach ( TerrainBlock block in highlightedTerrainBlocks )
				block.SpriteRenderer.VertexColor = block.DefaultColor;
			
			// Highlight selection of the row and column from the terrain block.
			highlightedTerrainBlocks = TerrainManager.GetTerrainRowAndColumn (selectedTerrainBlock);
			
			foreach ( TerrainBlock block in highlightedTerrainBlocks ) {
				block.SpriteRenderer.VertexColor = Color.red;
			}
			
			if ( instiantedUnit != null )
				instiantedUnit.SetXY ( selectedTerrainBlockGO.GetX(), selectedTerrainBlockGO.GetY() );
			
			break;
			
		case GestureRecognitionState.Ended:
			if ( highlightedTerrainBlocks != null )
				foreach ( TerrainBlock block in highlightedTerrainBlocks )
					block.SpriteRenderer.VertexColor = block.DefaultColor;
			
			selectedTerrainBlockGO = e.Selection;
			if ( selectedTerrainBlockGO == null ) {
				if ( instiantedUnit != null ) {
					Destroy ( instiantedUnit );
				}
				return; 
			}
			
			selectedTerrainBlock = selectedTerrainBlockGO.GetComponent<TerrainBlock>();
			if ( selectedTerrainBlock == null ) { 
				if ( instiantedUnit != null ) {
					instiantedUnit.renderer.enabled = false;
					Destroy ( instiantedUnit );
				}
				return;
			}
			
			if ( selectedTerrainBlock.HasUnit )
				Destroy ( instiantedUnit );
			else {
				if ( selectedTerrainBlock == null )
					return;
				
				selectedTerrainBlock.unitOnTerrain = instiantedUnit.GetComponent<Unit>();
				selectedTerrainBlock.unitOnTerrain.terrainBlock = selectedTerrainBlock;
				selectedTerrainBlock.unitOnTerrain.UnitPlaced = true;
			}
			
			selectedTerrainBlockGO = null;
			selectedTerrainBlock = null;
			instiantedUnit = null;
			UnitToCreate.LastUsedTime = Time.time;
			
			break;
		}
	}
    void OnDrag(DragGesture e)
    {
        if (unitToCreate == null || !canCreate)
        {
            return;
        }

        if (!unitToCreate.Recharged)
        {
            return;
        }

        switch (e.State)
        {
        case GestureRecognitionState.Started:
            if (instiantedUnit == null)
            {
                instiantedUnit = Instantiate(unitToCreate.gameObject) as GameObject;
                instiantedUnit.renderer.enabled = false;
            }

            break;

        case GestureRecognitionState.InProgress:
            selectedTerrainBlockGO = e.Selection;

            if (selectedTerrainBlockGO == null)
            {
                if (instiantedUnit != null)
                {
                    instiantedUnit.renderer.enabled = false;
                }
                return;
            }

            selectedTerrainBlock = selectedTerrainBlockGO.GetComponent <TerrainBlock>();
            if (selectedTerrainBlock == null)
            {
                if (instiantedUnit != null)
                {
                    instiantedUnit.renderer.enabled = false;
                }
                return;
            }

            if (instiantedUnit != null)
            {
                instiantedUnit.renderer.enabled = true;
            }

            if (highlightedTerrainBlocks != null)
            {
                foreach (TerrainBlock block in highlightedTerrainBlocks)
                {
                    block.SpriteRenderer.VertexColor = block.DefaultColor;
                }
            }

            // Highlight selection of the row and column from the terrain block.
            highlightedTerrainBlocks = TerrainManager.GetTerrainRowAndColumn(selectedTerrainBlock);

            foreach (TerrainBlock block in highlightedTerrainBlocks)
            {
                block.SpriteRenderer.VertexColor = Color.red;
            }

            if (instiantedUnit != null)
            {
                instiantedUnit.SetXY(selectedTerrainBlockGO.GetX(), selectedTerrainBlockGO.GetY());
            }

            break;

        case GestureRecognitionState.Ended:
            if (highlightedTerrainBlocks != null)
            {
                foreach (TerrainBlock block in highlightedTerrainBlocks)
                {
                    block.SpriteRenderer.VertexColor = block.DefaultColor;
                }
            }

            selectedTerrainBlockGO = e.Selection;
            if (selectedTerrainBlockGO == null)
            {
                if (instiantedUnit != null)
                {
                    Destroy(instiantedUnit);
                }
                return;
            }

            selectedTerrainBlock = selectedTerrainBlockGO.GetComponent <TerrainBlock>();
            if (selectedTerrainBlock == null)
            {
                if (instiantedUnit != null)
                {
                    instiantedUnit.renderer.enabled = false;
                    Destroy(instiantedUnit);
                }
                return;
            }

            if (selectedTerrainBlock.HasUnit)
            {
                Destroy(instiantedUnit);
            }
            else
            {
                if (selectedTerrainBlock == null)
                {
                    return;
                }

                selectedTerrainBlock.unitOnTerrain = instiantedUnit.GetComponent <Unit>();
                selectedTerrainBlock.unitOnTerrain.terrainBlock = selectedTerrainBlock;
                selectedTerrainBlock.unitOnTerrain.UnitPlaced   = true;
            }

            selectedTerrainBlockGO    = null;
            selectedTerrainBlock      = null;
            instiantedUnit            = null;
            UnitToCreate.LastUsedTime = Time.time;

            break;
        }
    }
Example #9
0
 // checks if a game object's position falls within the camera's current radius
 // this does not include the extra range granted by the UDPATE_OFF_SCREEN_RANGE value, because there is no point to drawing graphics that can't be seen
 public bool ContainsDraw(GameObject gameObject)
 {
     return(GetX1() - tileWidth < gameObject.GetX() + gameObject.GetScaledWidth() && GetEndBoundX() + tileWidth > gameObject.GetX() &&
            GetY1() - tileHeight < gameObject.GetY() + gameObject.GetScaledHeight() && GetEndBoundY() + tileHeight > gameObject.GetY());
 }