public void FillTargetPositions(GameObject ship) { Transform targets = ship.transform.Find("AttackPoints"); if (targets != null) { Transform tfTarget = targets.Find("AttackPointH"); if (tfTarget != null) { mTargets.AddFirst(tfTarget); } else { return; } Transform tfNext = targets.Find("AttackPointR"); if (tfNext != null) { mTargets.AddLast(tfNext); } else { return; } GameShip script = ship.GetComponent <GameShip>(); if (script != null) { GameObject nextShip = script.NextShip; if (nextShip != null) { FillTargetPositions(nextShip); } else { tfNext = targets.Find("AttackPointT"); if (tfNext != null) { mTargets.AddLast(tfNext); } else { return; } } } else { Debug.Log("Ship " + ship.name + " doesn't have GameShip script"); return; } tfNext = targets.Find("AttackPointL"); if (tfNext != null) { mTargets.AddLast(tfNext); } return; } }
public bool CanPutShipOnBoard(BoardSquareState[,] board, int x, int y, GameShip gameShip, bool isHorizontal) { if (isHorizontal) { if (!(board.GetLength(0) >= x + gameShip.Size)) { return(false); } } else { if (!(board.GetLength(1) >= y + gameShip.Size)) { return(false); } } if (!NotOverlapOtherShip(board, x, y, gameShip, isHorizontal)) { return(false); } if (_shipsCanTouch == EShipsCanTouch.Corner) { return(!SidesNotTouching(board, x, y, gameShip, isHorizontal)); } return(_shipsCanTouch != EShipsCanTouch.No || (SidesNotTouching(board, x, y, gameShip, isHorizontal) && CornersNotTouching(board, x, y, gameShip, isHorizontal))); }
void Start() { if (!GetComponent <AudioSource>()) { gameObject.AddComponent <AudioSource>(); audioSource = GetComponent <AudioSource>(); } else { audioSource = GetComponent <AudioSource>(); } mTrans = transform; mStats = GameShip.Find(mTrans); initialVelocity = 60; maxPitch = 5; maxAimDeviationAngle = 1; // Calculate the cannon's maximum range mMaxRange = CalculateMaxRange(); if (mStats != null) { // Ship stats found -- use it as root node mColliders = mStats.GetComponentsInChildren <Collider>(); } else { // No ship stats present -- see if there is a rigidbody that can be used as root Rigidbody rb = mTrans.GetComponent <Rigidbody>(); mColliders = (rb != null) ? rb.GetComponentsInChildren <Collider>() : GetComponentsInChildren <Collider>(); } }
/// <summary> /// Helper function that finds the ship stats script that contains the specified child in its transform hierarchy. /// </summary> new static public GameShip Find(Transform trans) { while (trans != null) { GameShip stats = trans.GetComponent <GameShip>(); if (stats != null) { return(stats); } trans = trans.parent; } return(null); }
/// <summary> /// Cache the transform and the ship controlling this cannon. /// </summary> void Start () { mTrans = transform; mStats = GameShip.Find(mTrans); // Calculate the cannon's maximum range mMaxRange = CalculateMaxRange(); if (mStats != null) { // Ship stats found -- use it as root node mColliders = mStats.GetComponentsInChildren<Collider>(); } else { // No ship stats present -- see if there is a rigidbody that can be used as root Rigidbody rb = ToolCalculations.GetRigidbody(mTrans); mColliders = (rb != null) ? rb.GetComponentsInChildren<Collider>() : GetComponentsInChildren<Collider>(); } }
/// <summary> /// Cache the transform and the ship controlling this cannon. /// </summary> void Start() { mTrans = transform; mStats = GameShip.Find(mTrans); // Calculate the cannon's maximum range mMaxRange = CalculateMaxRange(); if (mStats != null) { // Ship stats found -- use it as root node mColliders = mStats.GetComponentsInChildren <Collider>(); } else { // No ship stats present -- see if there is a rigidbody that can be used as root Rigidbody rb = Tools.GetRigidbody(mTrans); mColliders = (rb != null) ? rb.GetComponentsInChildren <Collider>() : GetComponentsInChildren <Collider>(); } }
private void SelectAShip() { if (selectedShip != null) { return; } if (!Input.GetMouseButtonDown(0)) { return; } Ray mouseRay = cam.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(mouseRay.origin, mouseRay.direction * raycastMaxDistance, Color.cyan, 1); if (!Physics.Raycast(mouseRay, out RaycastHit hitInfo, raycastMaxDistance)) { return; } var gameShip = hitInfo.collider.GetComponent <GameShip>(); if (gameShip is null) { return; } if (gameShip.board != board) { return; } selectedShip = gameShip; dragOrientation = gameShip.GetShip().Orientation; justSelected = true; dragOrigin = gameShip.GetBoardCoordinateFromPosition(); Debug.DrawRay(board.CoordinateToWorld(dragOrigin), Vector3.up * 10, Color.red, 5); }
/// <summary> /// Cache the stats. /// </summary> void Start () { mStats = GameShip.Find(transform); }
/// <summary> /// Cache the transform /// </summary> void Start() { mTrans = transform; mStats = GetComponent <GameShip>(); mCannons = GetComponentsInChildren <Cannon>(); }
void XH() { UISprite xphud = NGUITools.Draw <UISprite>("xphud", delegate(UISprite xpa) { // sp.atlas = Resources.Load<UIAtlas>("UI/Atlas - Windward"); // sp.spriteName = "Flat"; // sp.type = UISprite.Type.Sliced; // sp.color = new Color(0.25f, 1f, 0f, 1f); // sp.alpha = 1f; xpa.pivot = UIWidget.Pivot.TopLeft; xpa.SetAnchor(0.05f, 0, 0.97f, -10, 0.05f, 300, 0.97f, 5); UILabel xplbl = xpa.gameObject.AddWidget <UILabel>(2); xplbl.name = "XP"; xplbl.pivot = UIWidget.Pivot.BottomLeft; xplbl.bitmapFont = Resources.Load <UIFont>("UI/Font - Qlassik22"); xplbl.fontSize = 14; xplbl.effectStyle = UILabel.Effect.Shadow; xplbl.gradientBottom = new Color(0.5f, 0.5f, 0.5f, 1f); xplbl.SetAnchor(0f, 5, 1f, 2, 0f, xpa.width - 10, 1f, 30); UILabel lblXP = xpa.gameObject.AddComponent <UILabel>(); }); GameShip ship = MyPlayer.ship; int xp = MyPlayer.xp; int num; int num2; int num3; GameConfig.GetPointsFromXP(xp, out num, out num2, out num3); if (ship != null && ship.isActive) { xphud.alpha = 1f; UILabel labelXP = xphud.GetComponent <UILabel>(); Transform childXP = labelXP.transform.FindChild("XP"); if (childXP != null) { UILabel lblXP = childXP.GetComponent <UILabel>(); if (lblXP != null) { lblXP.text = "(TP)" + MyPlayer.talentPoints.ToString() + " (XP) " + xp.ToString("N0") + " / " + num3.ToString("N0"); } if (GameWorld.region != null) { lblXP.text = lblXP.text + " | " + Localization.Get("Region") + " #" + GameWorld.region.id.ToString(); } } } else { xphud.alpha = 0f; } }
void SH() { UISprite fg = NGUITools.Draw <UISprite>("fg", delegate(UISprite sp) { sp.depth = -100000;; // sp.atlas = Resources.Load<UIAtlas>("UI/Atlas - Windward"); // sp.spriteName = "Flat"; // sp.type = UISprite.Type.Sliced; // sp.color = new Color(0.25f, 1f, 0f, 1f); // sp.alpha = 1f; sp.pivot = UIWidget.Pivot.TopLeft; sp.SetAnchor(0.52f, -100, 0.06f, 10, 0.52f, 100, 0.06f, 20); UISprite spa = sp.gameObject.AddWidget <UISprite>(0); spa.depth = -1; spa.atlas = Resources.Load <UIAtlas>("UI/Atlas - Windward"); spa.spriteName = "Flat"; spa.type = UISprite.Type.Sliced; spa.color = new Color(0.25f, 1f, 0f, 1f); spa.pivot = UIWidget.Pivot.TopLeft; spa.SetAnchor(0f, 0, 0f, 0, 0.65f, 0, 1f, 0); UISprite bg = sp.gameObject.AddWidget <UISprite>(0); bg.depth = -1; bg.atlas = spa.atlas; bg.spriteName = "Flat"; bg.type = UISprite.Type.Sliced; bg.color = new Color(0.2f, 0.2f, 0.2f, 1f); bg.pivot = UIWidget.Pivot.TopLeft; bg.SetAnchor(0f, 0, 0f, 0, 0.65f, 0, 1f, 0); UILabel lbl = sp.gameObject.AddWidget <UILabel>(2); lbl.name = "Speed"; lbl.pivot = UIWidget.Pivot.BottomLeft; lbl.bitmapFont = Resources.Load <UIFont>("UI/Font - Qlassik22"); lbl.fontSize = 14; lbl.effectStyle = UILabel.Effect.Shadow; lbl.gradientBottom = new Color(0.5f, 0.5f, 0.5f, 1f); lbl.SetAnchor(0f, 5, 1f, 2, 0f, sp.width - 10, 1f, 30); UILabel lbl2 = sp.gameObject.AddWidget <UILabel>(2); lbl2.name = "Hull"; lbl2.pivot = UIWidget.Pivot.BottomLeft; lbl2.bitmapFont = Resources.Load <UIFont>("UI/Font - Qlassik22"); lbl2.fontSize = 14; lbl2.effectStyle = UILabel.Effect.Shadow; lbl2.gradientBottom = new Color(0.5f, 0.5f, 0.5f, 1f); lbl2.SetAnchor(0f, -65, 0f, 3, 0f, sp.width - 10, 1f, 30); UILabel lbl3 = sp.gameObject.AddWidget <UILabel>(2); lbl3.name = "Sails"; lbl3.pivot = UIWidget.Pivot.BottomLeft; lbl3.bitmapFont = Resources.Load <UIFont>("UI/Font - Qlassik22"); lbl3.fontSize = 14; lbl3.effectStyle = UILabel.Effect.Shadow; lbl3.gradientBottom = new Color(0.5f, 0.5f, 0.5f, 1f); lbl3.SetAnchor(0f, 135, 0f, 3, 0f, sp.width - 10, 1f, 30); UISlider slider = sp.gameObject.AddComponent <UISlider>(); slider.backgroundWidget = bg; slider.foregroundWidget = spa; }); GameShip ship = MyPlayer.ship; if (ship != null && ship.isActive) { fg.alpha = 1f; UISlider slider = fg.GetComponent <UISlider>(); slider.value = Mathf.Abs(ship.relativeMovementSpeed); Transform child = slider.transform.FindChild("Speed"); if (child != null) { UILabel lbl = child.GetComponent <UILabel>(); if (lbl != null) { lbl.text = ship.movementVelocity.magnitude.ToString("F1"); } } Transform child2 = slider.transform.FindChild("Hull"); if (child != null) { UILabel lbl2 = child2.GetComponent <UILabel>(); if (lbl2 != null) { lbl2.text = (ship.health * ship.maxHealth).ToString("F0") + "/" + ship.maxHealth.ToString("F0"); } } Transform child3 = slider.transform.FindChild("Sails"); if (child != null) { UILabel lbl3 = child3.GetComponent <UILabel>(); if (lbl3 != null) { lbl3.text = (ship.secondaryHealth * ship.maxSailHealth).ToString("F0") + "/" + ship.maxSailHealth.ToString("F0"); } } } else { fg.alpha = 0f; } }
private static bool SidesNotTouching(BoardSquareState[,] board, int x, int y, GameShip gameShip, bool isHorizontal) { if (isHorizontal) { if (x > 0) { if (board[x - 1, y].GameShipOnBoardNr != 0) { //Console.WriteLine("board[x - 1, y].GameShipOnBoardNr != 0"); return(false); } } if (board.GetLength(0) - (x + gameShip.Size) > 0) { if (board[x + gameShip.Size, y].GameShipOnBoardNr != 0) { //Console.WriteLine("board[x + gameShip.Size, y].GameShipOnBoardNr != 0"); return(false); } } for (var col = x; col < gameShip.Size + x; col++) { if (y > 0) { if (board[col, y - 1].GameShipOnBoardNr != 0) { //Console.WriteLine("board[col, y - 1].GameShipOnBoardNr != 0"); return(false); } } if (board.GetLength(0) - 1 - (y + gameShip.Size) <= 0) { continue; } if (board[col, y + 1].GameShipOnBoardNr != 0) { //Console.WriteLine("board[col, y + 1].GameShipOnBoardNr != 0"); return(false); } // //???? // if (board.GetLength(1) - (y + gameShip.Size) > 0) // { // if (board[x, y + gameShip.Size].GameShipOnBoardNr != 0) // { // Console.WriteLine("board[x, y + gameShip.Size].GameShipOnBoardNr != 0"); // return false; // } // } } } else { // Vertical ship check if (y > 0) { if (board[x, y - 1].GameShipOnBoardNr != 0) { //Console.WriteLine("board[x, y - 1].GameShipOnBoardNr != 0"); return(false); } } if (board.GetLength(1) - (y + gameShip.Size) > 0) { if (board[x, y + gameShip.Size].GameShipOnBoardNr != 0) { //Console.WriteLine("board[x, y + gameShip.Size].GameShipOnBoardNr != 0"); return(false); } } for (var row = y; row < gameShip.Size + y; row++) { if (x > 0) { if (board[x - 1, row].GameShipOnBoardNr != 0) { //Console.WriteLine("board[x - 1, row].GameShipOnBoardNr != 0"); return(false); } } if (board.GetLength(1) - 1 - x <= 0) { continue; } if (board[x + 1, row].GameShipOnBoardNr != 0) { //Console.WriteLine("board[x + 1, row].GameShipOnBoardNr != 0"); return(false); } } } return(true); }
private static bool NotOverlapOtherShip(BoardSquareState[,] board, int x, int y, GameShip gameShip, bool isHorizontal) { if (isHorizontal) { for (var col = x; col < x + gameShip.Size; col++) { if (board[col, y].GameShipOnBoardNr != 0) { return(false); } } } else { for (var row = y; row < y + gameShip.Size; row++) { if (board[x, row].GameShipOnBoardNr != 0) { return(false); } } } return(true); }
private void PlaceTheShip() { if (selectedShip is null) { return; } Vector3 rayPosition = cam.ScreenToFlatWorldPoint(Input.mousePosition); Vector3 offset = selectedShip.GetPositionOffset(); Vector2Int coordinate = board.WorldToCoordinate(rayPosition - offset); Debug.DrawRay(rayPosition, Vector3.up * 5); Debug.DrawRay(rayPosition, offset * 15); selectedShip.SetPositionFromCoordinate(coordinate, dragOrientation, 10); // Is whole ship outside? int length = selectedShip.GetLength(); int xLength = dragOrientation == Orientation.East ? length : 1; int yLength = dragOrientation == Orientation.South ? length : 1; if (!justSelected && !Board.IsOnBoard(coordinate.x, coordinate.y) && !Board.IsOnBoard(coordinate.x + xLength - 1, coordinate.y + yLength - 1)) { if (Input.GetMouseButtonDown(0)) { dragOrientation = FlipOrientation(dragOrientation); } return; } // Continue if mouse release if (!Input.GetMouseButtonUp(0)) { return; } if (justSelected) { justSelected = false; // Dragged it long enough if ((coordinate - dragOrigin).magnitude < dragMinDistance) { return; } } try { board.protocolBoard.MoveShip(selectedShip.shipType, (coordinate.x, coordinate.y), dragOrientation); } catch { return; } // Move queue if (queueList.Remove(selectedShip)) { queueGapLeft = queueGap; if (queueList.Count == 0) { allShipsPlaced.Invoke(); } } selectedShip.SetPositionFromCoordinate(coordinate, dragOrientation); print($"moved {selectedShip.name} to {coordinate}, {dragOrientation}"); selectedShip = null; }
private static bool CornersNotTouching(BoardSquareState[,] board, int x, int y, GameShip gameShip, bool isHorizontal) { if (x > 0 && y > 0) { if (board[x - 1, y - 1].GameShipOnBoardNr != 0) { //Console.WriteLine("board[x - 1, y - 1].GameShipOnBoardNr != 0"); return(false); } } switch (isHorizontal) { case true: { if (x > 0 && board.GetLength(1) - 1 - y > 0) { if (board[x - 1, y + 1].GameShipOnBoardNr != 0) { //Console.WriteLine("board[x - 1, y + 1].GameShipOnBoardNr != 0"); return(false); } } if (board.GetLength(0) - (x + gameShip.Size) > 0 && y > 0) { if (board[x + gameShip.Size, y - 1].GameShipOnBoardNr != 0) { //Console.WriteLine("board[x + gameShip.Size, y - 1].GameShipOnBoardNr != 0"); return(false); } } //? if (board.GetLength(0) - (x + gameShip.Size) > 0 && board.GetLength(1) - 1 - y > 1) { if (board[x + gameShip.Size, y + 1].GameShipOnBoardNr != 0) { //Console.WriteLine("board[x + gameShip.Size, y + 1].GameShipOnBoardNr != 0"); return(false); } } break; } case false: { if (y > 0 && board.GetLength(0) - 1 - x > 0) { if (board[x + 1, y - 1].GameShipOnBoardNr != 0) { //Console.WriteLine("board[x + 1, y - 1].GameShipOnBoardNr != 0"); return(false); } } if (x > 0 && board.GetLength(1) - (y + gameShip.Size) > 0) { if (board[x - 1, y + gameShip.Size].GameShipOnBoardNr != 0) { //Console.WriteLine("board[x - 1, y + gameShip.Size].GameShipOnBoardNr != 0"); return(false); } } if (x + 1 <= board.GetLength(0) - 1 && board.GetLength(1) - (y + gameShip.Size) > 0) { Console.WriteLine(x); if (board[x + 1, y + gameShip.Size].GameShipOnBoardNr != 0) { //Console.WriteLine("board[x + 1, y + gameShip.Size].GameShipOnBoardNr != 0"); return(false); } } break; } } return(true); }
void Start() { mTrans = transform; mStats = GetComponent <GameShip>(); //mCannons = GetComponentsInChildren<Cannon>(); photonView = GetComponent <PhotonView>(); boxCollider = GetComponentInChildren <BoxCollider>(); ////onstart() //if (BattleManger.Instance) //{ // mStats.ShipHealth = PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].strength; // BattleManger.Instance.PlayerLevelText.text = PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].shipName; // photonView.RPC("InitPlayersUIOnStartBattle", PhotonTargets.Others, BattleManger.Instance.PlayerLevelText.text); // //shiphealth // BattleManger.Instance.PlayerHealthText.text = mStats.ShipHealth.ToString(); // BattleManger.Instance.PlayerHealthSlider.maxValue = (int) mStats.ShipHealth; // BattleManger.Instance.PlayerHealthSlider.value = (int)mStats.ShipHealth; // photonView.RPC("EnemyShipHealth", PhotonTargets.Others, mStats.ShipHealth); //} if (BattleManger.Instance) { //BattleManger.Instance.players = new List<PlayerInBattle>(2); //BattleManger.Instance.ships = new List<Ship>(2); //fill for player if (!PlayerInformation.Instance) { return; } //init shipvalues mStats.ShipHealth = PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].strength; mStats.Ship_singleCannonDmg = PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].singleCannonDmg; mStats.maxMovementSpeed = PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].speed; mStats.maxTurningSpeed = PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].turnSpeed; foreach (Cannon cannon in mCannonsLeft) { cannon.CannonBallDmg = mStats.Ship_singleCannonDmg; } foreach (Cannon cannon in mCannonsRight) { cannon.CannonBallDmg = mStats.Ship_singleCannonDmg; } // PlayerInBattle playerInBattle = new PlayerInBattle() { playerName = PlayerInformation.Instance.playerName, level = PlayerInformation.Instance.level, exp = PlayerInformation.Instance.experience, shipName = PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].shipName, strength = PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].strength, singleCannonDmg = PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].singleCannonDmg, speed = PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].speed, turnSpeed = PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].turnSpeed }; BattleManger.Instance.players.Insert(0, playerInBattle); ///BattleManger.Instance.ships.Add(PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected]); //fill for enemy photonView.RPC("InitBattleManagerProperties", PhotonTargets.Others, PlayerInformation.Instance.playerName, PlayerInformation.Instance.level, PlayerInformation.Instance.experience, PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].shipName, PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].strength, PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].singleCannonDmg, PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].speed, PlayerInformation.Instance.listOfShips[PlayerInformation.Instance.currentShipSelected].turnSpeed ); } }
/// <summary> /// Cache the transform /// </summary> void Start() { mTrans = transform; mStats = GetComponent<GameShip>(); mCannons = GetComponentsInChildren<Cannon>(); }
/// <summary> /// Cache the stats. /// </summary> void Start() { mStats = GameShip.Find(transform); }
public static GameShip DrawShipList(List <GameShip> ships, string?name) { var ship = new GameShip(); var shipIndex = 0; var userChoice = ""; var shipNotSelected = true; do { Console.Clear(); Console.WriteLine(); Console.WriteLine(); for (var i = 0; i < ships.Count; i++) { if (shipIndex == i) { Console.BackgroundColor = ConsoleColor.DarkCyan; } Console.WriteLine($"{i + 1}) " + ships[i].Name); Console.ResetColor(); } Console.WriteLine(); if (name != null) { Console.Write($"{name} select ship > "); } else { Console.Write("Select ship > "); } Console.Write(userChoice); var key = Console.ReadKey(); switch (key.Key) { case ConsoleKey.DownArrow: case ConsoleKey.Tab: { shipIndex++; if (shipIndex > ships.Count - 1) { shipIndex = 0; } userChoice = (shipIndex + 1).ToString(); break; } case ConsoleKey.UpArrow: { shipIndex--; if (shipIndex < 0) { shipIndex = ships.Count - 1; } userChoice = (shipIndex + 1).ToString(); break; } case ConsoleKey.Enter: { ship = ships[shipIndex]; shipNotSelected = false; Console.Clear(); break; } } } while (shipNotSelected); return(ship); }