public override void Update(GameTime theTime) { newState[0] = GamePad.GetState(LogicalGamer.GetPlayerIndex(LogicalGamerIndex.One)); newState[1] = GamePad.GetState(LogicalGamer.GetPlayerIndex(LogicalGamerIndex.Two)); if (op.noPlayers == 4) { newState[2] = GamePad.GetState(LogicalGamer.GetPlayerIndex(LogicalGamerIndex.Three)); newState[3] = GamePad.GetState(LogicalGamer.GetPlayerIndex(LogicalGamerIndex.Four)); } if (screen.X == 0 || screen.Y == 0) { angle += 0.001f; cameraPosition = distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)); WVP[1] = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.UnitY); } if (screen.W != 0) { if (newState[currentPlayer].Buttons.B == ButtonState.Pressed) { screen.W = 0; } } else if (screen.X == 1) { if (screen.Z == 1) { bool error = false; if (screen.Y == 1 && a[(int)(p[currentPlayer][(int)(screen.Y - 1)][0].X)][(int)(p[currentPlayer][(int)(screen.Y - 1)][0].Y)].getType() != currentPlayer + 1) { error = true; } else if (screen.Y == 2 && b[(int)(p[currentPlayer][(int)(screen.Y - 1)][0].X)][(int)(p[currentPlayer][(int)(screen.Y - 1)][0].Y)].getType() != currentPlayer + 1) { error = true; } if (error == true) { screen.W = 1; screen.Z = 0; } else { screen.Z = 2; } } else if (screen.Z == 2) { angleMove(newState[currentPlayer], oldState[currentPlayer]); if (newState[currentPlayer].Buttons.A == ButtonState.Pressed && oldState[currentPlayer].Buttons.A == ButtonState.Released) { screen.Z = 3; } if (newState[currentPlayer].Buttons.B == ButtonState.Pressed && oldState[currentPlayer].Buttons.B == ButtonState.Released) { screen.Z = 0; p[currentPlayer][(int)(screen.Y - 1)][1] = Vector2.Zero; } } else if (screen.Z == 3) { bool legalMove; Vector2[] marbles; if (p[currentPlayer][(int)(screen.Y - 1)][1].Y > 0) { marbles = new Vector2[(int)(p[currentPlayer][(int)(screen.Y - 1)][1].Y) + 1]; } else { marbles = new Vector2[1]; } marbles[0] = p[currentPlayer][(int)(screen.Y - 1)][0]; if (p[currentPlayer][(int)(screen.Y - 1)][1].Y >= 1) { marbles[1] = angleChangePoint(p[currentPlayer][(int)(screen.Y - 1)][0], (int)(p[currentPlayer][(int)(screen.Y - 1)][1].X)); } if (p[currentPlayer][(int)(screen.Y - 1)][1].Y == 2) { marbles[2] = angleChangePoint(marbles[1], (int)(p[currentPlayer][(int)(screen.Y - 1)][1].X)); } if (p[currentPlayer][(int)(screen.Y - 1)][1].Y >= 1) { marbles[1] = angleChangePoint(p[currentPlayer][(int)(screen.Y - 1)][0], (int)(p[currentPlayer][(int)(screen.Y - 1)][1].X)); legalMove = CheckMarblePos(marbles[1]); if (legalMove == false) { p[currentPlayer][(int)(screen.Y - 1)][1] = Vector2.Zero; } if (p[currentPlayer][(int)(screen.Y - 1)][1].Y == 2) { legalMove = CheckMarblePos(marbles[1]); if (legalMove == false) { p[currentPlayer][(int)(screen.Y - 1)][1].Y--; } } } legalMove = true; if (p[currentPlayer][(int)(screen.Y - 1)][1].Y >= 1) { if (CheckMarbleType(marbles[1], currentPlayer) == false) { legalMove = false; } if (p[currentPlayer][(int)(screen.Y - 1)][1].Y == 2) { if (CheckMarbleType(marbles[2], currentPlayer) == false) { legalMove = false; } } } if (legalMove == false) { screen.W = 5; screen.Z = 2; } else { screen.Z = 4; angle2 = 0; } } else if (screen.Z == 4) { } else { if (screen.Y != 0) { playersMove(newState[currentPlayer], oldState[currentPlayer]); if (newState[currentPlayer].Buttons.A == ButtonState.Pressed && oldState[currentPlayer].Buttons.A == ButtonState.Released) { screen.Z = 1; } } if (newState[currentPlayer].Triggers.Left != 0 && screen.Y != 1) { screen.Y = 1; angle = 0; cameraPosition = distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)); WVP[1] = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.UnitY); } else if (newState[currentPlayer].Triggers.Right != 0 && screen.Y != 2) { screen.Y = 2; angle = 0; cameraPosition = distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)); WVP[1] = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.UnitY); } } } oldState = newState.ToArray(); base.Update(theTime); }
public override void Draw(GameTime gameTime) { device.Clear(op.getColor(currentPlayer + 1) * 0.7f); device.BlendState = BlendState.AlphaBlend; device.DepthStencilState = DepthStencilState.Default; if (screen.Y == 0 && screen.W == 0) { foreach (Marble[] i in a) { foreach (Marble z in i) { DrawModel(marbleModel, WVP, z.position, op.getColorV(z.getType()), false); } } foreach (Marble[] i in b) { foreach (Marble z in i) { if (!(z.getPosition().Y == 0)) { DrawModel(marbleModel, WVP, z.position, op.getColorV(z.getType()), false); } } } } if (screen.Y != 0 && screen.W == 0) { if (screen.Y == 1) { foreach (Marble[] i in a) { foreach (Marble z in i) { DrawModel(marbleModel, WVP, z.position, op.getColorV(z.getType()), z.isSelected(p[currentPlayer][0])); } } } else if (screen.Y == 2) { foreach (Marble[] i in b) { foreach (Marble z in i) { DrawModel(marbleModel, WVP, new Vector3(z.getPosition(), 0), op.getColorV(z.getType()), z.isSelected(p[currentPlayer][1])); } } } } sprBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); if (screen.W != 0) { //ErrorScreen } else { String myText = ""; if (screen.Y == 0 || screen.Y == 2) { myText += "Press the Left Trigger to switch to Board 1."; } if (screen.Y == 0) { myText += "\n"; } if (screen.Y == 0 || screen.Y == 1) { myText += "Press the Right Trigger to switch to Board 2."; } Vector2 textSize = Font.MeasureString(myText); Vector2 textCenter = new Vector2(device.Viewport.Width / 2, 100 / 2); sprBatch.DrawString(Font, myText, textCenter - (textSize / 2), Color.Black); string status = ""; if (screen.Y == 1) { status = "Board1"; } if (screen.Y == 2) { status = "Board2"; } if (screen.Y != 0) { status += "\n" + p[currentPlayer][(int)(screen.Y - 1)][0]; status += "\n" + p[currentPlayer][(int)(screen.Y - 1)][1]; } status += "\n Screen States=" + screen + "\n CurrentPlayer=" + currentPlayer + "\n CurrentController=" + LogicalGamer.GetPlayerIndex((LogicalGamerIndex)currentPlayer); status += "\n" + numOff[0] + "\n" + numOff[1]; if (op.noPlayers == 4) { status += "\n" + numOff[2] + "\n" + numOff[3]; } sprBatch.DrawString(Font, status, Vector2.Zero, Color.Red); } sprBatch.End(); base.Draw(gameTime); }
public override void Update(GameTime theTime) { newState = GamePad.GetState(LogicalGamer.GetPlayerIndex(LogicalGamerIndex.One)); angle += 0.001f; cameraPosition = distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)); WVP[1] = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.UnitY); if (screen.X == 0) { if (newState.DPad.Up == ButtonState.Pressed && oldState.DPad.Up == ButtonState.Released) { screen.Y--; } if (newState.DPad.Down == ButtonState.Pressed && oldState.DPad.Down == ButtonState.Released) { screen.Y++; } if (screen.Y == -1) { screen.Y = 3; } else if (screen.Y == 4) { screen.Y = 0; } if (newState.Buttons.A == ButtonState.Pressed && oldState.Buttons.A == ButtonState.Released) { if (screen.Y == 0) { screen.X = 1; playGameCheck[0] = "Review the options below\n\n"; playGameCheck[0] += "Number of Players: " + op.noPlayers + "\n"; playGameCheck[0] += "Player 1: Controller " + LogicalGamer.GetPlayerIndex(LogicalGamerIndex.One) + "\n"; playGameCheck[0] += "Player 2: Controller " + LogicalGamer.GetPlayerIndex(LogicalGamerIndex.Two) + "\n"; if (op.noPlayers == 4) { playGameCheck[0] += "Player 3: Controller " + LogicalGamer.GetPlayerIndex(LogicalGamerIndex.Three) + "\n"; playGameCheck[0] += "Player 4: Controller " + LogicalGamer.GetPlayerIndex(LogicalGamerIndex.Four) + "\n"; } playGameCheck[0] += "\nBoard Setup: " + op.boardTypeName(); playGameCheckCenter[0] = font.MeasureString(playGameCheck[0]) / 2; float scaleX; float scaleY; scaleY = (button.Height * 3) / (playGameCheckCenter[0].Y * 2.5f); scaleX = (button.Width) / (playGameCheckCenter[0].X * 2.5f); if (scaleY < scaleX) { scale1 = scaleY; } else { scale1 = scaleX; } scaleY = button.Height / (playGameCheckCenter[1].Y * 2.5f); scaleY = button.Width / (playGameCheckCenter[1].X * 2.5f); if (scaleY < scaleX) { scale2 = scaleY; } else { scale2 = scaleX; } } else if (screen.Y == 1) { //Options } else if (screen.Y == 2) { //Instructions } else if (screen.Y == 3) { ScreenEvent.Invoke(0, new EventArgs()); } } ; } else if (screen.X == 1) { if (newState.Buttons.A == ButtonState.Pressed && oldState.Buttons.A == ButtonState.Released) { ScreenEvent.Invoke(2, new EventArgs()); //start game } else if (newState.Buttons.B == ButtonState.Pressed && oldState.Buttons.B == ButtonState.Released) { screen.X = 0; } else if (newState.Buttons.Y == ButtonState.Pressed && oldState.Buttons.Y == ButtonState.Released) { ; //options } playGameCheck[1] = "Press A to start the game.\nPress B to go back to the Main Menu.\nPress Y to go to the Options Menu."; } oldState = newState; base.Update(theTime); }