/// <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() { // Initialize camera camera = new Camera(this, new Vector3(0, 0, 5), Vector3.Zero, Vector3.Up); Components.Add(camera); base.Initialize(); }
protected override void Initialize() { // Initialize camera camera = new Camera(this, Vector3.Zero, Vector3.Zero, Vector3.Up); // ustawienie pozycji poczatkowej swiata worldTranslation = Matrix.Add(worldTranslation, Matrix.CreateTranslation(new Vector3(-20, -20, -50))); Components.Add(camera); base.Initialize(); }
public void MapMouseAndRandNewBlock(GraphicsDevice g, BasicEffect effect, Camera camera) { Vector3 nearSource = new Vector3(Mouse.GetState().X, Mouse.GetState().Y, 0f); Vector3 farSource = new Vector3(Mouse.GetState().X, Mouse.GetState().Y, 1f); Vector3 nearPoint = g.Viewport.Unproject(nearSource, camera.projection, camera.view, Matrix.Identity); Vector3 farPoint = g.Viewport.Unproject(farSource, camera.projection, camera.view, Matrix.Identity); Vector3 direction = farPoint - nearPoint; direction.Normalize(); Ray xRay = new Ray(nearPoint, direction); if (mainGameClass.CheckStone) { Point cursorPos = new Point(this.X, this.Y); Player activePlayer = Game1.listOfPlayers[Round.NumberOfActivePlayer - 1]; int playerColor = activePlayer.PlayerColor; Element thisBoard = _board[this.X][this.Y]; try { // LEFT EDGE if (intersects(xRay, X, Y + 0.25f, 0, X + 0.25f, Y + 0.75f, 0)) { if (!CanIPutStone(this.X, this.Y, 0)) throw new Edge2PawnCollisionException(); if (CheckIfModel(cursorPos, thisBoard.leftEdge)) throw new Edge2PawnCollisionException(); if (thisBoard.leftEdge == GRASS) // pawn cannot be placed on grass throw new PawnCannotBePlacedHereException(); model.Add(new Model3D(mainGameClass, X, Y + 0.5f, playerColor)); activePlayer.NumberOfLittlePowns--; // decrease number of pawns activePlayer.Pawns.Add(new Pawn(X, Y, Element.Direction.Left,thisBoard.leftEdge)); // save Pawn position thisBoard.stoneLeftEdge = 1; Round.PuttingPowl(); thisBoard.player = Round.NumberOfActivePlayer; mainGameClass.CanStone = false; mainGameClass.CheckStone = false; } // RIGHT EDGE else if (intersects(xRay, X + 0.75f, Y + 0.25f, 0, X + 1, Y + 0.75f, 0)) { if (!CanIPutStone(this.X, this.Y, 2)) throw new Pawn2PawnCollisionException(); if (CheckIfModel(cursorPos, thisBoard.rightEdge)) throw new Pawn2PawnCollisionException(); if (thisBoard.rightEdge == GRASS) throw new PawnCannotBePlacedHereException(); model.Add(new Model3D(mainGameClass, X + 0.55f, Y + 0.5f, playerColor)); activePlayer.Pawns.Add(new Pawn(X, Y, Element.Direction.Right, thisBoard.rightEdge)); // save Pawn position activePlayer.NumberOfLittlePowns--; thisBoard.stoneRightEdge = 1; Round.PuttingPowl(); thisBoard.player = Round.NumberOfActivePlayer; mainGameClass.CanStone = false; mainGameClass.CheckStone = false; } // TOP (UP) EDGE else if (intersects(xRay, X + 0.25f, Y + 0.75f, 0, X + 0.75f, Y + 1, 0)) { if (!CanIPutStone(this.X, this.Y, 1)) throw new Pawn2PawnCollisionException(); if (CheckIfModel(cursorPos, thisBoard.upEdge)) throw new Pawn2PawnCollisionException(); if (thisBoard.upEdge == GRASS) throw new PawnCannotBePlacedHereException(); model.Add(new Model3D(mainGameClass, X + 0.30f, Y + 0.9f, playerColor)); activePlayer.Pawns.Add(new Pawn(X, Y, Element.Direction.Up, thisBoard.upEdge)); // save Pawn position activePlayer.NumberOfLittlePowns--; thisBoard.stoneUpEdge = 1; Round.PuttingPowl(); thisBoard.player = Round.NumberOfActivePlayer; mainGameClass.CanStone = false; mainGameClass.CheckStone = false; } // BOTTOM (DOWN) EDGE else if (intersects(xRay, X + 0.25f, Y, 0, X + 0.75f, Y + 0.25f, 0)) { if (!CanIPutStone(this.X, this.Y, 3)) throw new Pawn2PawnCollisionException(); if (CheckIfModel(cursorPos, thisBoard.bottomEdge)) throw new Pawn2PawnCollisionException(); if (thisBoard.bottomEdge == GRASS) throw new PawnCannotBePlacedHereException(); model.Add(new Model3D(mainGameClass, X + 0.30f, Y + 0.2f, playerColor)); activePlayer.Pawns.Add(new Pawn(X, Y, Element.Direction.Down, thisBoard.bottomEdge)); // save Pawn position activePlayer.NumberOfLittlePowns--; thisBoard.stoneBottomEdge = 1; Round.PuttingPowl(); thisBoard.player = Round.NumberOfActivePlayer; mainGameClass.CanStone = false; mainGameClass.CheckStone = false; } //SRODEK else if (intersects(xRay, X + 0.25f, Y + 0.25f, 0, X + 0.75f, Y + 0.75f, 0)) { if (!CanIPutStone(this.X, this.Y, 4)) throw new Pawn2PawnCollisionException(); if (thisBoard.additional == 1) { model.Add(new Model3D(mainGameClass, X + 0.30f, Y + 0.5f, playerColor)); activePlayer.NumberOfLittlePowns--; activePlayer.Pawns.Add(new Pawn(X, Y, Element.Direction.Down, thisBoard.bottomEdge)); // save Pawn position thisBoard.stoneCenter = 1; thisBoard.player = Round.NumberOfActivePlayer; Round.PuttingPowl(); mainGameClass.CanStone = false; mainGameClass.CheckStone = false; } } else { MessageBox.Show("Pionek nie może zostać postawiony we wskazane miejsce."); } } catch (Pawn2PawnCollisionException e) { MessageBox.Show("Kolizja z innym pionkiem."); } catch (Edge2PawnCollisionException e) { MessageBox.Show("Kolizja pionka z krawędzią."); } catch (PawnCannotBePlacedHereException e) { return; // do nothing. Pawn cannot be placed on grass } } else { if (!mainGameClass.infoBar.wholeBar.Contains(Mouse.GetState().X, Mouse.GetState().Y)) { for (int i = 0; i < sizeX; i++) { for (int j = 0; j < sizeY; j++) { Element thisBoard = _board[i][j]; if (thisBoard.Texture == txt1) { if(intersects(xRay, i, j, 0, i+1, j+1, 0)) { if (elements.Count >= 1) { if (CheckBounds(i, j, textureIndex)) { mainGameClass.CanStone = false; this.X = i; this.Y = j; thisBoard.Texture = elements[textureIndex].Texture; thisBoard.leftEdge = elements[textureIndex].leftEdge; thisBoard.rightEdge = elements[textureIndex].rightEdge; thisBoard.upEdge = elements[textureIndex].upEdge; thisBoard.bottomEdge = elements[textureIndex].bottomEdge; thisBoard.additional = elements[textureIndex].additional; // ROTACJA TEKSTURY KLOCKA RYSOWANEGO NA PLANSZY if (numberOfRotation % 4 == 1) { rotateTexture( i, j, new Point(1,0), new Point(1,1), new Point(0,0), new Point(0,1) ); } if (numberOfRotation % 4 == 2) { rotateTexture(i, j, new Point(1, 1), new Point(0, 1), new Point(1, 0), new Point(0, 0) ); } if (numberOfRotation % 4 == 3) { rotateTexture(i, j, new Point(0, 1), new Point(0, 0), new Point(1, 1), new Point(1, 0) ); } elements.RemoveAt(textureIndex); textureIndex = rand.Next(0, elements.Count-1); NextBlock = elements[textureIndex].Texture; numberOfRotation = 0; mainGameClass.putElement = true; mainGameClass.CanStone = true; Round.PuttingElement(); if (elements.Count < 1) { string wyniki = "Game Over\n"; string wyniki1 =""; for (int z = 0; z < Round.NumberOfPlayers; z++) { foreach (Pawn pionek in Game1.listOfPlayers[z].Pawns) { Game1.listOfPlayers[z].PlayerPoints += FloodFill(new Point(pionek.x, pionek.y), pionek.krawedz, pionek.wartosc); } wyniki += Game1.listOfPlayers[z].PlayerName + ":" + Game1.listOfPlayers[z].PlayerPoints + " " + "pkt\n"; wyniki1 += Game1.listOfPlayers[z].PlayerName + ":" + Game1.listOfPlayers[z].PlayerPoints + " "; } if (DialogResult.OK == MessageBox.Show(wyniki)) { //Zapis wyników System.IO.StreamWriter file = new System.IO.StreamWriter("wyniki.txt", true); file.WriteLine(DateTime.Now.ToString() + " " + wyniki1); file.Close(); for (int z = 0; z < Round.NumberOfPlayers; z++) { Game1.listOfPlayers[z].PlayerPoints = 0; } if (MessageBox.Show("Czy chcesz zacząć nową grę?", "Carcassonne", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //mainGameClass.board.Dispose(); //mainGameClass.Components.Remove(mainGameClass.board); //mainGameClass.Components.Add(mainGameClass.menu); // Game1 // Application.Restart(); } else { Application.Exit(); } } } //mainGameClass.CheckStone = true; } } else { NextBlock = txt1; } } } } } } else { for (int i = 0; i < mainGameClass.infoBar.stoneArea.Length; i++) { if (mainGameClass.infoBar.stoneArea[i].Contains(Mouse.GetState().X, Mouse.GetState().Y)) { mainGameClass.CheckStone = false; mainGameClass.infoBar.numberOfStone[i] -= 1; break; } } } } }