/// <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() { #region screenInit graphics.PreferredBackBufferWidth = 1000; graphics.PreferredBackBufferHeight = 640; graphics.IsFullScreen = false; graphics.ApplyChanges(); Window.Title = "UltimateFrizibi"; #endregion // TODO: Add your initialization logic here this.IsMouseVisible = true; graphics.PreferredBackBufferHeight = 600; graphics.PreferredBackBufferWidth = 1200; graphics.ApplyChanges(); bluePlayer = new Player(); redPlayer = new Player(); frizbi = new Frizbi(); playerTurn = 1; base.Initialize(); }
private void throwFrizbi(Frizbi frizbi) { Vector2 newFrizbiPos = frizbi.getPosition; int i; pivots[currentPivot].hasFrizbi = false; newFrizbiPos.X -= (float)Math.Sin(pivots[currentPivot].angle) * pivots[currentPivot].power; if (newFrizbiPos.X > screenWidth - 69) newFrizbiPos.X = screenWidth - 69; if (newFrizbiPos.X < 42) newFrizbiPos.X = 42; newFrizbiPos.Y += (float)Math.Cos(pivots[currentPivot].angle) * pivots[currentPivot].power; if (newFrizbiPos.Y > screenHeight - 50) newFrizbiPos.Y = screenHeight - 50; if (newFrizbiPos.Y < 20) newFrizbiPos.Y = 20; frizbi.setPosition(newFrizbiPos); i = checkGoodPass(newFrizbiPos); if (i != -1) { currentPivot = i; moveChosenToFrizbi(frizbi); checkIfGoal(frizbi); } else frizbi.frizbeLandedOnTheGround(); }
public int Update(Frizbi frizbi) { KeyboardState keybState = Keyboard.GetState(); int chosen = 1; if (lastKbs != null) { if (!pivotChosen) { #region switch between pivots if (keybState.IsKeyDown(Keys.Left) && lastKbs.IsKeyUp(Keys.Left)) { currentPivot = (currentPivot - 1) % numberOfPivots; currentPivot += (currentPivot == -1 ? numberOfPivots : 0); } if (keybState.IsKeyDown(Keys.Right) && lastKbs.IsKeyUp(Keys.Right)) currentPivot = (currentPivot + 1) % numberOfPivots; //choose player if (!lastKbs.IsKeyDown(Keys.Enter) && keybState.IsKeyDown(Keys.Enter)) { pivotChosen = true; } #endregion } else //pivot is chosen { //Angle if (keybState.IsKeyDown(Keys.Left)) pivots[currentPivot].angle = (pivots[currentPivot].angle - 0.05f); if (keybState.IsKeyDown(Keys.Right)) pivots[currentPivot].angle = (pivots[currentPivot].angle + 0.05f); if (pivots[currentPivot].angle < 0) pivots[currentPivot].angle += (2 * MathHelper.Pi); //power if (keybState.IsKeyDown(Keys.Down)) pivots[currentPivot].power -= 1; if (keybState.IsKeyDown(Keys.Up)) pivots[currentPivot].power += 1; //fix power if (pivots[currentPivot].power > 300) pivots[currentPivot].power = 300; if (pivots[currentPivot].power < 0) pivots[currentPivot].power = 0; //move pivot if (!lastKbs.IsKeyDown(Keys.Enter) && keybState.IsKeyDown(Keys.Enter)) { if (pivots[currentPivot].hasFrizbi) throwFrizbi(frizbi); else calcPivotPosition(); pivotChosen = false; chosen = -1; } } } lastKbs = keybState; return chosen; }
private void checkIfGoal(Frizbi frizbi) { if (pivots[currentPivot].rec.Intersects(goal)) { playerScore++; pivots[currentPivot].hasFrizbi = false; frizbi.frizbeLandedOnTheGround(); } }
public void moveChosenToFrizbi(Frizbi frizbi) { pivots[currentPivot].Position = frizbi.getPosition; pivots[currentPivot].rec.X = (int)pivots[currentPivot].Position.X; pivots[currentPivot].rec.Y = (int)pivots[currentPivot].Position.Y; pivots[currentPivot].hasFrizbi = true; frizbi.atPlayerHand = true; }