protected override void Initialize() { //graphics.ToggleFullScreen(); //graphics.ApplyChanges(); #region ("3D Init") WVP = new Matrix[3]; aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio; angle = 0; distance = 30; cameraPosition = distance * Vector3.UnitZ; cameraRotation = new Vector3(0, 1, 1); WVP[0] = Matrix.Identity; WVP[1] = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.UnitY); WVP[2] = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(55), aspectRatio, 0.1f, 100f); #endregion () #region ("HUD Init") hud = new Rectangle[4]; hud[0] = new Rectangle(0, 0, 150, GraphicsDevice.Viewport.Height); hud[1] = new Rectangle(150, 0, GraphicsDevice.Viewport.Width - 300, 100); hud[2] = new Rectangle(GraphicsDevice.Viewport.Width - 150, 0, 150, GraphicsDevice.Viewport.Height); hud[3] = new Rectangle(150, GraphicsDevice.Viewport.Height - 100, GraphicsDevice.Viewport.Width - 300, 100); #endregion () #region ("MarbleInit") a = new Marble[9][]; b = new Marble[9][]; for (int i = 0; i < 4; i++) { a[i] = new Marble[i + 5]; b[i] = new Marble[i + 5]; a[8 - i] = new Marble[i + 5]; b[8 - i] = new Marble[i + 5]; } a[4] = new Marble[9]; b[4] = a[4]; for (int i = 0; i < 4; i++) { for (int z = 0; z < i + 5; z++) { a[i][z] = new Marble(true, i, z); a[8 - i][z] = new Marble(true, 8 - i, z); b[i][z] = new Marble(false, i, z); b[8 - i][z] = new Marble(false, 8 - i, z); } } for (int z = 0; z < 9; z++) { a[4][z] = new Marble(true, 4, z); } changeMarbles(1); #endregion () screen = Vector4.Zero; newState = new GamePadState[GameConstants.numPlayers]; oldState = new GamePadState[GameConstants.numPlayers]; numOff = new int[GameConstants.numPlayers]; base.Initialize(); }
public SplashScreen(GraphicsDevice device, ContentManager theContent, EventHandler theScreenEvent) : base(device, theScreenEvent) { font = theContent.Load <SpriteFont>("Font"); text = "Press Start"; Vector2 textSize = font.MeasureString(text); textCenter = new Vector2(device.Viewport.Width / 2, device.Viewport.Height / 2); textCenter -= textSize / 2; WVP = new Matrix[3]; aspectRatio = device.Viewport.AspectRatio; distance = 30; cameraPosition = distance * Vector3.UnitZ; cameraRotation = new Vector3(0, 1, 1); WVP[0] = Matrix.Identity; WVP[1] = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.UnitY); WVP[2] = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(55), aspectRatio, 0.1f, 100f); op = new Options(); a = new Marble[9][]; b = new Marble[9][]; for (int i = 0; i < 4; i++) { a[i] = new Marble[i + 5]; b[i] = new Marble[i + 5]; a[8 - i] = new Marble[i + 5]; b[8 - i] = new Marble[i + 5]; } a[4] = new Marble[9]; b[4] = a[4]; for (int i = 0; i < 4; i++) { for (int z = 0; z < i + 5; z++) { a[i][z] = new Marble(true, i, z); a[8 - i][z] = new Marble(true, 8 - i, z); b[i][z] = new Marble(false, i, z); b[8 - i][z] = new Marble(false, 8 - i, z); } } for (int z = 0; z < 9; z++) { a[4][z] = new Marble(true, 4, z); } Board.SetUp(op.boardType, a, b, op.noPlayers); }
internal static void marbleInit(ref Marble[][] a, ref Marble[][] b) { for (int i = 0; i < 4; i++) { for (int z = 0; z < i + 5; z++) { a[i][z] = new Marble(true, i, z); a[8 - i][z] = new Marble(true, 8 - i, z); b[i][z] = new Marble(false, i, z); b[8 - i][z] = new Marble(false, 8 - i, z); } } for (int z = 0; z < 9; z++) { a[4][z] = new Marble(true, 4, z); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { a = new Marble[9][]; b = new Marble[9][]; op = new Options(); for (int i = 0; i < 4; i++) { a[i] = new Marble[i + 5]; b[i] = new Marble[i + 5]; a[8 - i] = new Marble[i + 5]; b[8 - i] = new Marble[i + 5]; } a[4] = new Marble[9]; b[4] = a[4]; base.Initialize(); }
public MenuScreen(GraphicsDevice device, ref Marble[][] a, ref Marble[][] b, ref Options op, ref Model MarbleModel) : base(device, "Menu", a, b) { marbleModel = MarbleModel; for (int i = 0; i < 4; i++) { for (int z = 0; z < i + 5; z++) { _a[i][z] = new Marble(true, i, z, ref op); _a[8 - i][z] = new Marble(true, 8 - i, z, ref op); _b[i][z] = new Marble(false, i, z, ref op); _b[8 - i][z] = new Marble(false, 8 - i, z, ref op); } } for (int z = 0; z < 9; z++) { _a[4][z] = new Marble(true, 4, z, ref op); } foreach (Marble[] i in a) { foreach (Marble z in i) { z.changeType(0); } } foreach (Marble[] i in b) { foreach (Marble z in i) { z.changeType(0); } } if (op.currentBoardType == 0) { Board1(); } else if (op.currentBoardType == 1) { Board2(); } }
private void HandleMarbleMove() { var currentMousePosition = MouseUtil.GetWorld(mainCamera); if (Input.GetKeyDown(KeyCode.Escape) && context.playerContext == "Move") { SelectCancel(); } if (!dragStarted && Input.GetMouseButtonDown(0)) { if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out var hit)) { var marble = hit.transform.GetComponent <Marble>(); if (marble != null) { switch (context.playerContext) { case "Choose": if (context.currentPlayerIndex == marble.playerIndex && !marble.fallen) { marble.PaintSelectColor(); draggingMarble = marble; dragStarted = true; dragStartMousePosition = marble.visiblePosition.ToWorld(); dragStartMarblePosition = marble.visiblePosition; } break; case "Move": if (WasChosen(marble.visiblePosition - chosenMarbleStart, chooseDirection, howManyIsChosen)) { dragStarted = true; dragStartMousePosition = marble.visiblePosition.ToWorld(); } else { SelectCancel(); } break; default: break; } if (marble.fallen) { draggingMarble = marble; dragStarted = true; dragStartMousePosition = marble.visiblePosition.ToWorld(); dragStartMarblePosition = marble.visiblePosition; } } } else if (context.playerContext == "Move") { SelectCancel(); } } if (Input.GetMouseButtonUp(0)) { switch (context.playerContext) { case "Choose": if (draggingMarble != null) { if (!draggingMarble.fallen) { chosenMarbleStart = dragStartMarblePosition; chooseDirection = dragDirection; context.playerContext = "Move"; draggingMarble = null; } } break; case "Move": if (wasValidMove) { for (int i = 0; i < howManyIsChosen; i++) { var chosenPosition = chosenMarbleStart + chooseDirection.ToCoord() * i; var worldChosenPosition = chosenPosition.ToWorld(); var worldMovePosition = (chosenPosition + dragDirection.ToCoord()).ToWorld(); var marbles = FindWithCoord((AxialCoord)chosenPosition - board.settings.placementOffset); marbles.transform.localPosition = worldMovePosition; marbles.SetArrayPosition((AxialCoord)chosenPosition - board.settings.placementOffset + (AxialCoord)(dragDirection.ToCoord())); marbles.PaintOrigin(true); } if (opponentPush) { for (int i = 0; i < howManyWillPush; i++) { CubeCoord chosenPosition = new CubeCoord(0, 0, 0); if (chooseDirection.ToCoord() == dragDirection.ToCoord()) { chosenPosition = chosenMarbleStart + chooseDirection.ToCoord() * (howManyIsChosen + i); } if (chooseDirection.ToCoord() == dragDirection.ToCoord() * (-1)) { chosenPosition = chosenMarbleStart - chooseDirection.ToCoord() + dragDirection.ToCoord() * i; } var movePosition = chosenPosition + dragDirection.ToCoord(); var worldChosenPosition = chosenPosition.ToWorld(); var worldMovePosition = (movePosition).ToWorld(); var marbles = FindWithCoord((AxialCoord)chosenPosition - board.settings.placementOffset); marbles.transform.localPosition = worldMovePosition; marbles.SetArrayPosition((AxialCoord)chosenPosition - board.settings.placementOffset + (AxialCoord)dragDirection.ToCoord()); } for (int j = 0; j < howManyWillPush; j++) { int i; if (chooseDirection.ToCoord() == dragDirection.ToCoord() || chooseDirection.ToCoord() == dragDirection.ToCoord() * (-1)) { i = howManyWillPush - j - 1; } else { i = j; } CubeCoord chosenPosition = new CubeCoord(0, 0, 0); if (chooseDirection.ToCoord() == dragDirection.ToCoord()) { chosenPosition = chosenMarbleStart + chooseDirection.ToCoord() * (howManyIsChosen + i); } if (chooseDirection.ToCoord() == dragDirection.ToCoord() * (-1)) { chosenPosition = chosenMarbleStart - chooseDirection.ToCoord() + dragDirection.ToCoord() * i; } var beforePosition = (AxialCoord)chosenPosition - board.settings.placementOffset; var afterPosition = beforePosition + (AxialCoord)(dragDirection.ToCoord()); gamedata.SetAt(beforePosition, 0); if (afterPosition.x < 0 || afterPosition.x >= board.settings.arraySize) { FindWithCoord(beforePosition).FallAnimation(dragDirection.ToCoord().ToWorld()); context.marbles[beforePosition.x, beforePosition.z] = null; continue; } if (afterPosition.z < 0 || afterPosition.z >= board.settings.arraySize) { FindWithCoord(beforePosition).FallAnimation(dragDirection.ToCoord().ToWorld()); context.marbles[beforePosition.x, beforePosition.z] = null; continue; } if (Mathf.Abs(afterPosition.x + board.settings.placementOffset.x + afterPosition.z + board.settings.placementOffset.z) > board.settings.cutThreshold) { FindWithCoord(beforePosition).FallAnimation(dragDirection.ToCoord().ToWorld()); context.marbles[beforePosition.x, beforePosition.z] = null; continue; } gamedata.SetAt(afterPosition, FindWithCoord(beforePosition).playerIndex); context.MoveData(beforePosition, afterPosition); } } for (int j = 0; j < howManyIsChosen; j++) { int i; if (chooseDirection.ToCoord() == dragDirection.ToCoord()) { i = howManyIsChosen - j - 1; } else { i = j; } var chosenPosition = chosenMarbleStart + chooseDirection.ToCoord() * i; var beforePosition = (AxialCoord)chosenPosition - board.settings.placementOffset; var afterPosition = beforePosition + (AxialCoord)(dragDirection.ToCoord()); gamedata.SetAt(beforePosition, 0); gamedata.SetAt(afterPosition, context.currentPlayerIndex); context.MoveData(beforePosition, afterPosition); } //AI if (context.currentPlayerIndex == 1) { var targetCase = GetComponent <AI>().Thinking(gamedata.placement, board, 2); StartCoroutine(FindWithCoord(targetCase.target).HelloWorld()); } //broadCast ON string[] lines = new string[9]; string[] emoji = new string[5] { "🔵", "⚫", "⚪", "🎱", "🍥" }; for (var x = 0; x < board.settings.arraySize; x++) { for (var z = 0; z < board.settings.arraySize; z++) { var zAlpha = board.settings.arraySize - 1 - z; if (Mathf.Abs(x + board.settings.placementOffset.x + zAlpha + board.settings.placementOffset.z) > board.settings.cutThreshold) { continue; } var isFirstMarble = FindWithCoord(new AxialCoord(x, zAlpha)) == FindWithCoord((AxialCoord)(chosenMarbleStart + dragDirection.ToCoord()) - board.settings.placementOffset); var isSecondMarble = howManyIsChosen >= 2 && FindWithCoord(new AxialCoord(x, zAlpha)) == FindWithCoord((AxialCoord)(chosenMarbleStart + chooseDirection.ToCoord() + dragDirection.ToCoord()) - board.settings.placementOffset); var isThirdMarble = howManyIsChosen >= 3 && FindWithCoord(new AxialCoord(x, zAlpha)) == FindWithCoord((AxialCoord)(chosenMarbleStart + chooseDirection.ToCoord() * 2 + dragDirection.ToCoord()) - board.settings.placementOffset); if (isFirstMarble || isSecondMarble || isThirdMarble) { lines[x] += emoji[gamedata.placement[x, zAlpha] + context.playerCount]; } else { lines[x] += emoji[gamedata.placement[x, zAlpha]]; } } if (x == 0) { lines[x] += " ◼ : " + context.fallenMarbles[1]; } if (x == 1) { lines[x] += " ◻ : " + context.fallenMarbles[0]; } } using (StreamWriter outputFile = new StreamWriter("Assets/Bot/bot.txt")) { foreach (string line in lines) { outputFile.WriteLine(line); } } //broadCast OFF if (context.fallenMarbles[0] == 6 || context.fallenMarbles[1] == 6) { GameOver(); } context.NextTurn(); context.playerContext = "Choose"; wasValidMove = false; } else { for (int i = 0; i < howManyIsChosen; i++) { var chosenPosition = chosenMarbleStart + chooseDirection.ToCoord() * i; var worldChosenPosition = chosenPosition.ToWorld(); var marbles = FindWithCoord((AxialCoord)chosenPosition - board.settings.placementOffset); marbles.transform.localPosition = worldChosenPosition; marbles.transform.localRotation = Quaternion.identity; } if (opponentPush) { for (int i = 0; i < howManyWillPush; i++) { CubeCoord chosenPosition = new CubeCoord(0, 0, 0); if (chooseDirection.ToCoord() == dragDirection.ToCoord()) { chosenPosition = chosenMarbleStart + chooseDirection.ToCoord() * (howManyIsChosen + i); } if (chooseDirection.ToCoord() == dragDirection.ToCoord() * (-1)) { chosenPosition = chosenMarbleStart - chooseDirection.ToCoord() + dragDirection.ToCoord() * i; } var worldChosenPosition = chosenPosition.ToWorld(); var marbles = FindWithCoord((AxialCoord)chosenPosition - board.settings.placementOffset); marbles.transform.localPosition = worldChosenPosition; marbles.transform.localRotation = Quaternion.identity; } } } break; default: break; } if (draggingMarble != null) { if (draggingMarble.fallen) { draggingMarble.GetComponent <Rigidbody>().isKinematic = false; } } dragDirectionFixed = false; dragStarted = false; } if (dragStarted) { var angle = Mathf.Atan2(dragStartMousePosition.z - currentMousePosition.z, dragStartMousePosition.x - currentMousePosition.x) * Mathf.Rad2Deg; if (!dragDirectionFixed) { dragDirection = (CubeDirection)Mathf.Round((angle + 150) / 60); } var directionCoord = dragDirection.ToCoord(); var startPosition = dragStartMarblePosition; var endPosition = startPosition + directionCoord; var worldStartPosition = startPosition.ToWorld(); var worldEndPosition = endPosition.ToWorld(); const float dragThreshold = 6f; var dragLength = Vector3.Dot(currentMousePosition - dragStartMousePosition, directionCoord.ToWorld().normalized); var t = dragLength / dragThreshold; dragDirectionFixed = (t > 0.15); switch (context.playerContext) { case "Choose": var secondMarble = FindWithCoord((AxialCoord)(startPosition + directionCoord) - board.settings.placementOffset); var thirdMarble = FindWithCoord((AxialCoord)(startPosition + directionCoord * 2) - board.settings.placementOffset); if (draggingMarble.fallen) { secondMarble = null; thirdMarble = null; } if (t <= 0.15) { if (secondMarble != null) { secondMarble.PaintOrigin(false); } howManyIsChosen = 1; } if (t > 0.15 && secondMarble != null && secondMarble.playerIndex == context.currentPlayerIndex) { secondMarble.PaintSelectColor(); if (thirdMarble != null) { thirdMarble.PaintOrigin(false); } howManyIsChosen = 2; } if (t > 0.43 && thirdMarble != null && thirdMarble.playerIndex == context.currentPlayerIndex) { thirdMarble.PaintSelectColor(); howManyIsChosen = 3; } break; case "Move": if (!CanPushMarble(chosenMarbleStart, chooseDirection, howManyIsChosen, directionCoord)) { t = 0.05f; } for (int i = 0; i < howManyIsChosen; i++) { var chosenPosition = chosenMarbleStart + chooseDirection.ToCoord() * i; var worldChosenPosition = chosenPosition.ToWorld(); var worldMovePosition = (chosenPosition + directionCoord).ToWorld(); var marbles = FindWithCoord((AxialCoord)chosenPosition - board.settings.placementOffset); Motion(worldChosenPosition, worldMovePosition, t, directionCoord, marbles); } if (opponentPush) { for (int i = 0; i < howManyWillPush; i++) { CubeCoord chosenPosition = new CubeCoord(0, 0, 0); if (chooseDirection.ToCoord() == directionCoord) { chosenPosition = chosenMarbleStart + chooseDirection.ToCoord() * (howManyIsChosen + i); } if (chooseDirection.ToCoord() == directionCoord * (-1)) { chosenPosition = chosenMarbleStart - chooseDirection.ToCoord() + directionCoord * i; } var worldChosenPosition = chosenPosition.ToWorld(); var worldMovePosition = (chosenPosition + directionCoord).ToWorld(); var marbles = FindWithCoord((AxialCoord)chosenPosition - board.settings.placementOffset); Motion(worldChosenPosition, worldMovePosition, t, directionCoord, marbles); } } wasValidMove = (t >= 1); break; default: break; } if (draggingMarble != null) { if (draggingMarble.fallen) { draggingMarble.transform.localPosition = draggingMarble.DragLimit(draggingMarble.transform.localPosition, currentMousePosition); } } } }
private void Motion(Vector3 worldChosenPosition, Vector3 worldMovePosition, float t, CubeCoord directionCoord, Marble marble) { var marbleY = marble.yCurve.Evaluate(t); var moveRotation = new Vector3(directionCoord.ToWorld().z, directionCoord.ToWorld().y, -directionCoord.ToWorld().x); marble.transform.localPosition = Vector3.Lerp(worldChosenPosition, worldMovePosition, t) + new Vector3(0, marbleY, 0); marble.transform.localRotation = Quaternion.identity; marble.transform.Rotate(moveRotation, 360 * Mathf.Min(t, 1)); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { WVP = new Matrix[3]; aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio; angle = 0; distance = 30; cameraPosition = distance * Vector3.UnitZ; cameraRotation = new Vector3(0, 1, 1); WVP[0] = Matrix.Identity; WVP[1] = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.UnitY); WVP[2] = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(55), aspectRatio, 0.1f, 100f); a = new Marble[9][]; b = new Marble[9][]; for (int i = 0; i < 4; i++) { a[i] = new Marble[i + 5]; b[i] = new Marble[i + 5]; a[8 - i] = new Marble[i + 5]; b[8 - i] = new Marble[i + 5]; } a[4] = new Marble[9]; b[4] = a[4]; for (int i = 0; i < 4; i++) { for (int z = 0; z < i + 5; z++) { a[i][z] = new Marble(true, i, z); a[8 - i][z] = new Marble(true, 8 - i, z); b[i][z] = new Marble(false, i, z); b[8 - i][z] = new Marble(false, 8 - i, z); } } for (int z = 0; z < 9; z++) { a[4][z] = new Marble(true, 4, z); } foreach (Marble[] i in a) { foreach (Marble z in i) { z.changeType(0); } } foreach (Marble[] i in b) { foreach (Marble z in i) { z.changeType(0); } } foreach (Marble i in a[0]) { i.changeType(1); } foreach (Marble i in a[1]) { i.changeType(1); } a[2][2].changeType(1); a[2][3].changeType(1); a[2][4].changeType(1); foreach (Marble i in a[8]) { i.changeType(2); } foreach (Marble i in a[7]) { i.changeType(2); } a[6][2].changeType(2); a[6][3].changeType(2); a[6][4].changeType(2); foreach (Marble i in b[0]) { i.changeType(3); } foreach (Marble i in b[1]) { i.changeType(3); } b[2][2].changeType(3); b[2][3].changeType(3); b[2][4].changeType(3); foreach (Marble i in b[8]) { i.changeType(4); } foreach (Marble i in b[7]) { i.changeType(4); } b[6][2].changeType(4); b[6][3].changeType(4); b[6][4].changeType(4); base.Initialize(); }