예제 #1
0
    public override BaseGamePiece FindTarget()
    {
        List <ShipGamePiece> allShips = ShipManager.GetAllShips();

        //Next Turn Hex
        TileWithFacing startVec = new TileWithFacing()
        {
            position = myGamePiece.currentTile, facing = myGamePiece.currentTileFacing
        };
        TileWithFacing headingTile = startVec.Traverse(HexDirection.Forward, myGamePiece.currentVelocity);

        //Find the ship closest to where I will be if I move forward. Exclude the ship that fired me.
        ShipGamePiece closestShip         = null;
        float         closestShipDistance = float.MaxValue;

        foreach (ShipGamePiece ship in allShips)
        {
            if (ship == myGamePiece.motherGamePiece)
            {
                continue;
            }

            float distance = HexMapHelper.CrowFlyDistance(headingTile.position, myGamePiece.currentLevel, ship.currentTile, ship.currentLevel);
            if (distance < closestShipDistance)
            {
                closestShipDistance = distance;
                closestShip         = ship;
            }
        }

        currentTarget = closestShip;
        Debug.DrawLine(HexMapHelper.GetWorldPointFromTile(myGamePiece.currentTile), HexMapHelper.GetWorldPointFromTile(currentTarget.currentTile), Color.yellow, 5f);
        return(currentTarget);
    }
예제 #2
0
 public void SetSelectedCommandPoint(CommandPointFsm point)
 {
     selectedCommandPoint = point;
     gamePiece.SetDestination(selectedCommandPoint.destinationTile, selectedCommandPoint.destinationFacingTile, selectedCommandPoint.destinationLevel);
     gamePiece.currentVelocity = selectedCommandPoint.endVelocity;
     Debug.DrawLine(HexMapHelper.GetWorldPointFromTile(gamePiece.currentTile), HexMapHelper.GetWorldPointFromTile(selectedCommandPoint.destinationTile), Color.cyan, 5f);
 }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        Vector3    cursorWorldPos = GetPlaneIntersection();
        TileCoords selectedTile   = HexMapHelper.GetTileFromWorldPoint(cursorWorldPos);

        //Debug.Log("SelectedTile = " + selectedTile);
        transform.position = HexMapHelper.GetWorldPointFromTile(selectedTile, HexMapUI.currentUIMapLevel);
    }
예제 #4
0
 // Update is called once per frame
 void Update()
 {
     transform.position = HexMapHelper.GetWorldPointFromTile(
         tilePositionObject.GetPivotTilePosition(), tilePositionObject.GetPivotTileLevel())
                          + (HexMapHelper.GetFacingVector(tilePositionObject.GetPivotTilePosition(), hexDirectionObject.GetTileFacing()) * centerOffset);
     triangle.color     = HexMapUI.GetLevelColor(tilePositionObject.GetPivotTileLevel());
     transform.rotation = HexMapHelper.GetRotationFromFacing(tilePositionObject.GetPivotTilePosition(), hexDirectionObject.GetTileFacing());
 }
예제 #5
0
 public override BaseGamePiece FindTarget()
 {
     //Player Ship
     if (currentTarget != null)
     {
         Debug.DrawLine(HexMapHelper.GetWorldPointFromTile(myGamePiece.currentTile), HexMapHelper.GetWorldPointFromTile(currentTarget.currentTile), Color.yellow, 5f);
     }
     return(currentTarget);
 }
예제 #6
0
    public void PositionAndOrientPiece()
    {
        transform.position = HexMapHelper.GetWorldPointFromTile(currentTile, currentLevel);
        gamePieceModel.transform.rotation = HexMapHelper.GetRotationFromFacing(currentTile, currentTileFacing);

        footprint.SetPivotTile(new TileWithFacing()
        {
            position = currentTile, facing = currentTileFacing
        }, currentLevel);
    }
예제 #7
0
    public void SetDestination(TileCoords tileCoords, TileCoords facingTile, int level)
    {
        destinationTile       = tileCoords;
        destinationFacingTile = facingTile;
        destinationLevel      = level;

        //Position the sprite within the Hex
        sprite.transform.position = HexMapHelper.GetWorldPointFromTile(tileCoords, level) + ((HexMapHelper.GetFacingVector(tileCoords, facingTile) * HexMapHelper.HexWidth * 0.3f));

        //Face the sprite the correct direction
        sprite.transform.rotation = HexMapHelper.GetRotationFromFacing(tileCoords, facingTile);

        //Color the sprite based on height
        sprite.GetComponentInChildren <SpriteRenderer>().color = HexMapUI.GetLevelColor(level);

        SetSpline(sourcePosition, sourceHeading,
                  HexMapHelper.GetWorldPointFromTile(tileCoords, level), HexMapHelper.GetFacingVector(tileCoords, facingTile));
    }
예제 #8
0
    void Start()
    {
        //Randomly Generate Model
        GameObject prefab = template.modelPrefabs.RandomItem();

        GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, modelHolder);

        if (pivotPosition.index == 0)
        {
            pivotPosition = HexMapHelper.GetTileFromWorldPoint(transform.position);
        }
        TileCoords pivotFacing = HexMapHelper.GetNeighborTiles(pivotPosition).RandomItem();

        transform.position             = HexMapHelper.GetWorldPointFromTile(pivotPosition, pivotLevel);
        modelHolder.transform.rotation = HexMapHelper.GetRotationFromFacing(pivotPosition, pivotFacing);

        footprint = new StaticFootprint(template.footprint, pivotPosition, pivotFacing, pivotLevel);
    }
예제 #9
0
    // Start is called before the first frame update
    void Start()
    {
        TileCoords     startTile = HexMapHelper.GetTileFromWorldPoint(transform.position);
        TileWithFacing startVec  = new TileWithFacing()
        {
            position = startTile,
            facing   = HexMapHelper.GetNeighborTiles(startTile)[facingIndex]
        };

        List <TileWithLevel> footprintParts = new List <TileWithLevel>();

        footprintParts.Add(new TileWithLevel()
        {
            position = startVec.position, level = level
        });

        List <Vector3> lineNodes  = new List <Vector3>();
        TileWithFacing currentVec = startVec;

        for (int nodeIndex = 0; nodeIndex < maxLength; nodeIndex++)
        {
            currentVec = currentVec.Traverse(HexDirection.Forward);
            if (currentVec.position == startVec.position)
            {
                break;
            }
            lineNodes.Add(HexMapHelper.GetWorldPointFromTile(currentVec.position, level));
            footprintParts.Add(new TileWithLevel()
            {
                position = currentVec.position, level = level
            });
        }
        line.positionCount = lineNodes.Count;
        line.SetPositions(lineNodes.ToArray());

        footprint = new StaticFootprint(footprintParts);
    }
예제 #10
0
    public override CommandPointFsm SelectCommand()
    {
        var availableCommands = pieceController.navigationSystem.GetAvailableCommandPoints();

        if (currentTarget != null)
        {
            // Missile know where their target will be
            TileCoords targetDestinationTile       = currentTarget.GetDestinationTile();
            int        targetDestinationLevel      = currentTarget.GetDestinationLevel();
            Vector3    targetDestinationWorldSpace = HexMapHelper.GetWorldPointFromTile(targetDestinationTile, targetDestinationLevel);

            CommandPointFsm closestPoint     = null;
            float           closestPointDist = float.MaxValue;

            foreach (CommandPointFsm point in availableCommands)
            {
                if (point.destinationTile == targetDestinationTile && point.destinationLevel == targetDestinationLevel)
                {
                    return(point);
                }

                float distance = Vector3.Distance(targetDestinationWorldSpace, HexMapHelper.GetWorldPointFromTile(point.destinationTile, point.destinationLevel));
                if (distance < closestPointDist)
                {
                    closestPoint     = point;
                    closestPointDist = distance;
                }
            }

            return(closestPoint);
        }
        else
        {
            return(base.SelectCommand());
        }
    }
예제 #11
0
    public static void SpawnMissile(TileCoords tileCoords, TileCoords tileFacing, int level, BaseGamePiece spawningPiece, MissileStats template)
    {
        GameObject newMissile = SimplePool.Spawn(
            instance.missilePrefab,
            Vector3.zero,
            Quaternion.identity,
            instance.gamePieceHolder);

        newMissile.GetComponentInChildren <MissileGamePiece>().currentTileFacing = tileFacing;
        newMissile.GetComponentInChildren <MissileGamePiece>().currentTile       = tileCoords;
        newMissile.GetComponentInChildren <MissileGamePiece>().currentLevel      = level;
        newMissile.GetComponentInChildren <MissileGamePiece>().PositionAndOrientPiece();

        newMissile.GetComponentInChildren <PieceController>().worldBase.transform.position  = HexMapHelper.GetWorldPointFromTile(tileCoords, level);
        newMissile.GetComponentInChildren <PieceController>().worldModel.transform.rotation = HexMapHelper.GetRotationFromFacing(tileCoords, tileFacing);

        newMissile.GetComponentInChildren <NavigationSystem>().GenerateCommandPoints();

        newMissile.GetComponentInChildren <MissileBrain>().FindTarget();
        var selectedCommand = newMissile.GetComponentInChildren <MissileBrain>().SelectCommand();

        newMissile.GetComponentInChildren <PieceController>().SetSelectedCommandPoint(selectedCommand);
    }
예제 #12
0
 void ResetToGamePiecePosition()
 {
     worldBase.transform.position  = HexMapHelper.GetWorldPointFromTile(gamePiece.currentTile, gamePiece.currentLevel);
     worldModel.transform.rotation = HexMapHelper.GetRotationFromFacing(gamePiece.currentTile, gamePiece.currentTileFacing);
 }