protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { Exit(); } if (GamePad.ButtonAClicked()) { mPatrols.Add(new PatrolObject()); } if (GamePad.ButtonBClicked()) { if (mPatrols.Count > 0) { PatrolObject p = mPatrols[0]; p.RemoveFromAutoDrawSet(); mPatrols.RemoveAt(0); } } foreach (PatrolObject p in mPatrols) { p.Update(); } EchoToTopStatus("A to add a new patrol, B to remove a patrol"); EchoToBottomStatus("Currently NumPatrol=" + mPatrols.Count); }
protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { Exit(); } if (GamePad.ButtonAClicked()) { mConstantSpeed = !mConstantSpeed; } #region Update the "mTravel" object position according to the sine curve if (!mConstantSpeed) { mTravel.CenterX += 0.5f; mTravel.CenterY = mInitPos.Y + GetYValue(mTravel.CenterX); // this is the sine function!! } else { Vector2 next = new Vector2(mTravel.CenterX + 0.5f, mInitPos.Y + GetYValue(mTravel.CenterX)); Vector2 dir = next - mTravel.Center; dir.Normalize(); mTravel.Center += dir; } #endregion if (mTravel.CenterX > World.WorldDimension.X) { mTravel.Center = mInitPos; } #region Changing the Sine curve bool once = false; if (GamePad.ThumbSticks.Left.Y != 0f) { mPeriods += (GamePad.ThumbSticks.Left.Y * 0.1f); once = true; } if (GamePad.ThumbSticks.Left.X != 0f) { mAmplitude += GamePad.ThumbSticks.Left.X; once = true; } if (once) { PlotSineCurve(); } #endregion EchoToTopStatus("LeftThumb.Y adjust Period; LeftThumb.X adjust Amplitude"); EchoToBottomStatus("Period=" + mPeriods + " Amplitude=" + mAmplitude + " ConstantSpeed=" + mConstantSpeed); }
protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { Exit(); } #region change speed by inc/dec time for travelling mSecondsToTravel += GamePad.ThumbSticks.Right.Y; if (mSecondsToTravel <= 0f) { mSecondsToTravel = 0.1f; } #endregion #region recompute new speed for ball if (GamePad.ButtonAClicked()) { ComputeBallSpeed(); mBall.AddToAutoDrawSet(); ResetBallShootInfo(); } #endregion #region recompute new velocity direction for ball if (GamePad.ButtonBClicked()) { GenerateRandomBallVelocityDirection(); ResetBallShootInfo(); mBall.TopOfAutoDrawSet(); } #endregion #region determine if should contiune to draw the ball if (mBall.IsInAutoDrawSet()) { Vector2 delta = mBall.Center - kInitPosition; mDistanceTravelled = delta.Length(); if (mDistanceTravelled > kDistanceCovered) { mBall.RemoveFromAutoDrawSet(); } else { mUpdatesSinceShoot++; } } #endregion EchoToTopStatus("Ball velocity:" + mBall.Velocity + " position:" + mBall.Center); EchoToBottomStatus("Travel across " + kDistanceCovered + " units in: " + mSecondsToTravel + " seconds" + " UpdatesSinceShoot(" + mUpdatesSinceShoot + ")"); }
/// <summary> /// You should update the state of your world here! /// </summary> protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { Exit(); } if (GamePad.ButtonAClicked()) { SetRandomBallVelocityDir(); } }
protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { Exit(); } #region add a new ViewVector if (GamePad.ButtonAClicked()) { if (null != mCurrentVec) { mCurrentVec.FinalizeVector(); mCurrentPos = mCurrentVec.EndPos(); } mCurrentVec = new ShowVector(mCurrentPos, mDir, mVectorSize); } #endregion #region Update vectorDir by right thumbStick mDir += GamePad.ThumbSticks.Right; mDir.Normalize(); #endregion #region Update vectorSize by left thumbStick y mVectorSize += GamePad.ThumbSticks.Left.Y; #endregion #region show another Vector addition if (null != mCurrentVec) { mCurrentVec.SetVectorDir(mDir); mCurrentVec.SetVectorSize(mVectorSize); } #endregion #region restart ... if (GamePad.ButtonBClicked()) { World.RemoveAllFromDrawSet(); mCurrentVec = null; mAlreadyShown = 0; mCurrentPos = kInitPosition; DrawGrid(); } #endregion EchoToTopStatus("Segments shown:" + mAlreadyShown + "CurrentPos=" + mCurrentPos); EchoToBottomStatus("Vector Direction" + mDir + " Size: " + mVectorSize); }
/// <summary> /// You should update the state of your world here! /// </summary> protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { Exit(); } if (GamePad.ButtonAClicked()) { SetRandomBallVelocityDir(); } UpdateBallSpeed(GamePad.ThumbSticks.Right.Y * 0.01f); }
protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { this.Exit(); } if (GamePad.ButtonAClicked()) { if (mBall.IsInAutoDrawSet()) { mMissed++; } mBall.InitializeNewBall(); } if (GamePad.ButtonBClicked()) { mBall.RemoveFromAutoDrawSet(); mMissed++; } float userLeft = GamePad.Triggers.Left; float userRight = GamePad.Triggers.Right; for (int i = 0; i < kNumPaddlesPerSide; i++) { if ((mLeftPaddles[i].Update(userLeft, mBall)) || (mRightPaddles[i].Update(userRight, mBall))) { mHit++; } } if (mBall.IsInAutoDrawSet()) { mBall.Update(); EchoToBottomStatus("Ball position: " + mBall.Center); } else { EchoToBottomStatus("No Ball in the world"); } EchoToTopStatus("Hit: " + mHit + " Missed:" + mMissed); }
protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { Exit(); } if (GamePad.ButtonAClicked()) { mPatrols.Add(new PatrolObject()); } if (GamePad.ButtonBClicked()) { if (mPatrols.Count > 0) { PatrolObject p = mPatrols[0]; p.RemoveFromAutoDrawSet(); mPatrols.RemoveAt(0); } } int numChase = 0; for (int i = 0; i < mPatrols.Count; i++) { PatrolObject p = mPatrols[i]; if (p.ChasingHero()) { numChase++; } if (p.Update(mHero)) { mPatrols.Remove(p); p.RemoveFromAutoDrawSet(); } } mHero.Update(GamePad.ThumbSticks.Right); EchoToTopStatus("A to add a new patrol, B to remove a patrol"); EchoToBottomStatus("Currently NumPatrol=" + mPatrols.Count + " NumChasing=" + numChase + " Hero caught=" + mHero.NumTimesCaught); }
protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { Exit(); } #region Pause everything if (GamePad.ButtonXClicked()) { World.Paused = !World.Paused; } if (World.Paused) { return; } #endregion #region shoot the ball if (GamePad.ButtonAClicked()) { Vector2 velocity = mVBlock.VelocityDirection * mVBlock.Speed; mBall.ShootSoccer(kInitPosition, velocity); } #endregion #region Update Velocity Dir and size by thumbSticks mVBlock.UpdateVelocityBlock(GamePad.ThumbSticks.Right, GamePad.ThumbSticks.Left.Y); #endregion #region tell the Ball to update itself mBall.Update(); #endregion #region Rotate the Block mBlock.UpdateBlock(Vector2.Zero, GamePad.Triggers.Right); #endregion EchoToTopStatus("Block rotated angle=" + mBlock.RotateAngle); EchoToBottomStatus("Vector Direction" + mVBlock.VelocityDirection + " Size: " + mVBlock.Speed); }
protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { Exit(); } #region Elasticity and Friction by Left ThumbStick mElasticiy += 0.02f * GamePad.ThumbSticks.Left.X; mFriction += 0.02f * GamePad.ThumbSticks.Left.Y; #endregion if (GamePad.ButtonXClicked()) { World.Paused = !World.Paused; } if (!World.Paused) { #region shoot the ball if (GamePad.ButtonAClicked()) { Vector2 velocity = mVBlock.VelocityDirection * mVBlock.Speed; mBall.ShootSoccer(kInitPosition, velocity); } #endregion #region Update Velocity Dir and size by Right thumbStick mVBlock.UpdateVelocityBlock(GamePad.ThumbSticks.Right); #endregion #region tell the Ball to update itself mBall.Update(mElasticiy, mFriction); #endregion #region Rotate the Block mBlock.UpdateBlock(Vector2.Zero, GamePad.Triggers.Right); #endregion } EchoToTopStatus("Elasticity[LeftThumb.X]=" + mElasticiy + " Friction[LeftThumb.Y]=" + mFriction); EchoToBottomStatus("Vector Direction" + mVBlock.VelocityDirection + " Size: " + mVBlock.Speed); }
/// <summary> /// This is the "Controller" in the MVC software architecture. /// In this function, we accept user input and forward appropriate user actions /// to our model. /// </summary> protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { Exit(); } /// Forward user input to our model if (GamePad.ButtonAClicked()) { mMyTarget.CreateTarget(); } if (GamePad.ButtonBClicked()) { mMyTarget.DestroyTarget(); } mMyTarget.UpdateTarget(GamePad.ThumbSticks.Right); }
protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { Exit(); } #region add a new road segment if (GamePad.ButtonAClicked()) { mRoad.FinalizeRoadSegment(mDir, mLength); } #endregion #region Update vectorDir and size by thumbSticks mDir += GamePad.ThumbSticks.Right; mLength += GamePad.ThumbSticks.Left.Y; mTicksToTravel += GamePad.ThumbSticks.Left.X; mRoad.UpdateRoadSegment(mDir, mLength); mBall.TopOfAutoDrawSet(); #endregion #region tell the Ball to update itself mTicksHasPassed++; if (mBall.Update(mTicksToTravel)) { mTicksHasPassed = 0; } #endregion #region restart ... if (GamePad.ButtonBClicked()) { mRoad.ResetRoad(); mBall.ResetBallPosition(); } #endregion EchoToTopStatus("Number of updates to travel each segment:" + mTicksToTravel + " NumHasPassed(" + mTicksHasPassed + ")"); EchoToBottomStatus("Vector Direction" + mDir + " Size: " + mLength); }
protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { Exit(); } #region change speed by inc/dec time for travelling mSecondsToTravel += GamePad.ThumbSticks.Right.Y; if (mSecondsToTravel <= 0f) { mSecondsToTravel = 0.1f; } #endregion #region re-compute ball speed if (GamePad.ButtonAClicked()) { ComputeBallSpeed(); mUpdatesSinceShoot = 0; mBall.CenterX = 0f; mBall.AddToAutoDrawSet(); } #endregion #region continue to draw the ball? if (mBall.CenterX > kDistanceCovered) { mBall.RemoveFromAutoDrawSet(); } else { mUpdatesSinceShoot++; } #endregion EchoToTopStatus("Ball position: " + mBall.CenterX); EchoToBottomStatus("Travel across 100 units in: " + mSecondsToTravel + " seconds" + " UpdatesSinceShoot(" + mUpdatesSinceShoot + ")"); }
protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { Exit(); } #region add a new road segment if (GamePad.ButtonAClicked()) { mRoad.FinalizeRoadSegment(mDir, mLength); } #endregion #region Update vectorDir and size by thumbSticks mDir += GamePad.ThumbSticks.Right; mLength += GamePad.ThumbSticks.Left.Y; mRoad.UpdateRoadSegment(mDir, mLength); mCar.TopOfAutoDrawSet(); #endregion #region tell the car to update itself mTurnRate += 0.02f * GamePad.ThumbSticks.Left.X; mTurnRate = MathHelper.Clamp(mTurnRate, 0f, 1f); mCar.Update(mTurnRate); #endregion #region restart ... if (GamePad.ButtonBClicked()) { mRoad.ResetRoad(); mCar.ResetCarPosition(); } #endregion EchoToTopStatus("Turn rate: " + mTurnRate); }
protected override void UpdateWorld() { #region game is going on if (gameStarted && !gameOver && !win) { int roomX = (int)theLevel.currentRoom.X; int roomY = (int)theLevel.currentRoom.Y; #region removing while testing new pause screen //if (pauseScreen == null) { //we are creating the pause screen every update! // float x = theLevel.currentOrigin.X + 50f; // float y = theLevel.currentOrigin.Y + (9f/16f)*50f; // pauseScreen = new XNACS1Rectangle(new Vector2(x, y), 100f, (9f / 16f)*100f); // pauseScreen.Color = Color.Black; // map = new Map(new Vector2(x, y));// betania added this // map.Visible = false; // map.RemoveFromAutoDrawSet();// betania added this //} #endregion if (GamePad.ButtonStartClicked() && !exiting) { paused = paused ? false : true; //toggle the pause button } if (theLevel.paused) { World.Paused = true; } if (!theLevel.paused && lostLifeScreen != null) { lostLifeScreen.RemoveFromAutoDrawSet(); lostLifeScreen = null; } if (!theLevel.paused && !paused) { World.Paused = false; } if (!paused && !theLevel.paused) { //if (theLevel.paused) // World.Paused = true; if (GamePad.ButtonBackClicked() || exiting) { exiting = true; World.Paused = true; float x = theLevel.rooms[roomX, roomY].roomOrigin.X + 50f; float y = theLevel.rooms[roomX, roomY].roomOrigin.Y + 27f; if (areYouSure == null) { areYouSure = new XNACS1Rectangle(new Vector2(x, y), 50, 27f); areYouSure.Color = Color.Black; areYouSure.Label = "Are you sure you want to quit? All progress will be lost.\n" + "Press A to exit or B or cancel and return to the game"; areYouSure.LabelColor = Color.White; areYouSure.AddToAutoDrawSet(); } if (GamePad.ButtonAClicked()) { Exit(); } else if (GamePad.ButtonBClicked()) { areYouSure.RemoveFromAutoDrawSet(); areYouSure = null; World.Paused = false; exiting = false; } } else { if (!loading) { newLevel = false; newLevel = theLevel.updateLevel(GamePad.Buttons, GamePad.ThumbSticks, hero); if (newLevel) { loading = true; currentLevel++; } } if (loading) { if (currentLevel <= totalLevels) { float x = theLevel.rooms[roomX, roomY].roomOrigin.X + 50f; float y = theLevel.rooms[roomX, roomY].roomOrigin.Y + 28.2f; if (levelScreen == null) { levelScreen = new XNACS1Rectangle(new Vector2(x, y), 100f, 56f); levelScreen.Color = Color.Black; levelScreen.Label = "Level " + currentLevel; levelScreen.LabelColor = Color.White; levelScreen.AddToAutoDrawSet(); } World.Paused = true; if (tick > 0) { tick--; } else { tick = 120; levelScreen.RemoveFromAutoDrawSet(); levelScreen = null; theLevel.unloadLevel(); // delete all rooms //map.removeRoom(); switch (currentLevel) { case 1: path = @"level1.txt"; break; case 2: path = @"level2.txt"; break; case 3: path = @"level3.txt"; break; case 4: path = @"level4.txt"; break; default: win = true; break; } s = new StreamReader(path); XmlDocument xml = new XmlDocument(); theLevel = new Level(ref s, xml); theLevel.loadInitialRoom(difficulty, hero); World.Paused = false; loading = false; } } else { win = true; } } if (pauseScreen.IsInAutoDrawSet()) { pauseScreen.RemoveFromAutoDrawSet(); pauseScreen = null; if (map.IsInAutoDrawSet()) { map.RemoveFromAutoDrawSet(); map.removeRoom(); map.Visible = false; // map = null; } } } } else if (paused && !theLevel.paused) { pauseScreen.AddToAutoDrawSet(); if (!map.Visible) { map.AddToAutoDrawSet(); // betania added this map.drawRoom(map.LowerLeft); // betania added this map.displayMap(theLevel); // betania added map.Visible = true; } } else { if (lostLifeScreen == null) { lostLifeScreen = new XNACS1Rectangle( new Vector2(theLevel.currentOrigin.X + 50f, theLevel.currentOrigin.Y + ((9f / 16f) * 100) / 2), 100f, 56f); lostLifeScreen.Label = "Princess Lives Left " + hero.NumTimesCaught; lostLifeScreen.Color = Color.Black; lostLifeScreen.LabelColor = Color.White; lostLifeScreen.AddToAutoDrawSet(); } theLevel.updateLevel(GamePad.Buttons, GamePad.ThumbSticks, hero); } gameOver = hero.lives < 0; //String message = "Number of Lives: " + hero.lives + " Level Number: " + currentLevel; //SetTopEchoColor(Color.White); //EchoToTopStatus(message); theLevel.rooms[(int)theLevel.currentRoom.X, (int)theLevel.currentRoom.Y].wand.UpdateWand(currentLevel); //if (w == null) // w = new Wizard(Vector2.One); //w.Update(hero, theLevel.rooms[(int)theLevel.currentRoom.X, (int)theLevel.currentRoom.Y].wand); } #endregion #region game is won or lost else if (gameOver || win) { World.SetWorldCoordinate(new Vector2(0, 0), 100f); if (gameOver) { #region duplicate check //if (gameOverText == null) //{ // cover = new XNACS1Rectangle( // new Vector2(50f, ((9f / 16f) * 100f) / 2f), 100, (9f / 16f) * 100f); // cover.Color = Color.Black; //} #endregion if (gameOverText == null) { gameOverText = new XNACS1Rectangle(new Vector2(50, 40), 40, 10); gameOverText.Label = "GAME OVER \n A TO RESTART \n B TO EXIT"; gameOverText.Color = Color.Black; gameOverText.LabelColor = Color.White; } } else { if (winScreen == null) { winScreen = new XNACS1Rectangle( new Vector2(50f, ((9f / 16f) * 100f) / 2f), 100, (9f / 16f) * 100f); winScreen.Color = Color.Black; winScreen.Label = "You've escaped the evil wizard's castle!\n You're free at last!"; winScreen.LabelColor = Color.White; } } //unload everything if (theLevel != null) { theLevel.unloadLevel(); } theLevel = null; if (hero != null) { hero.RemoveFromAutoDrawSet(); } hero = null; if (GamePad.ButtonAClicked()) { gameOverText.RemoveFromAutoDrawSet(); gameOverText = null; cover.RemoveFromAutoDrawSet(); cover = null; setupGame(); } if (GamePad.ButtonBClicked()) { Exit(); } } #endregion #region game hasn't been started yet else if (!gameStarted) { if (GamePad.ButtonAClicked()) { if (selected.Center == easy.Center) { difficulty = 1; } else if (selected.Center == medium.Center) { difficulty = 2; } else { difficulty = 3; } hero = new Hero(new Vector2(0f, 0f), difficulty); theLevel.loadInitialRoom(difficulty, hero); //EchoToTopStatus(difficulty.ToString()); gameStarted = true; selected.RemoveFromAutoDrawSet(); } if (tick > 0) { tick--; } else { if (GamePad.ThumbSticks.Left.Y > 0) { if (selected.Center != easy.Center) { if (selected.Center != medium.Center) { selected.Center = medium.Center; } else { selected.Center = easy.Center; } } tick = 8; } else if (GamePad.ThumbSticks.Left.Y < 0) { if (selected.Center != hard.Center) { if (selected.Center != medium.Center) { selected.Center = medium.Center; } else { selected.Center = hard.Center; } } tick = 8; } } } #endregion }
protected override void UpdateWorld() { if (GamePad.ButtonBackClicked()) { Exit(); } // Update all of them!! for (int i = 0; i < kTotalPlots; i++) { if (i != mCurrentPlot) { mPlotPath[i].Update(Vector2.Zero, 0f, 0f, 0f, Vector2.Zero); } } if (GamePad.ButtonXClicked()) { mCurrentPlot++; if (mCurrentPlot >= kTotalPlots) { mCurrentPlot = 0; } } if (GamePad.ButtonBClicked()) { mPlotPath[mCurrentPlot].ShowPlots = !mPlotPath[mCurrentPlot].ShowPlots; } if (GamePad.ButtonAClicked()) { mPlotPath[mCurrentPlot].ConstantSpeed = !mPlotPath[mCurrentPlot].ConstantSpeed; } float deltaW = GamePad.Triggers.Left; if (GamePad.Buttons.LeftShoulder == ButtonState.Pressed) { deltaW -= 0.2f; } float deltaH = GamePad.Triggers.Right; if (GamePad.Buttons.RightShoulder == ButtonState.Pressed) { deltaH -= 0.2f; } float deltaR = 0f; if (GamePad.Dpad.Up == ButtonState.Pressed) { deltaR += 2f; } else if (GamePad.Dpad.Down == ButtonState.Pressed) { deltaR -= 2f; } mPlotPath[mCurrentPlot].Update(GamePad.ThumbSticks.Right, deltaW, deltaH, deltaR, GamePad.ThumbSticks.Left); EchoToTopStatus("LeftThumb.X/Y adjust Amplitude/Period; Box: Pos-RightStick Size:Left/Right Trigger/Button; Rotate-Dpad Up/Down"); EchoToBottomStatus("XButton=NextPlot BButton=PlotAreaVisibility ... XCovearge=" + mPlotPath[mCurrentPlot].XCoverage + " YCoverage=" + mPlotPath[mCurrentPlot].YCoverage + " ConstantSpeed=" + mPlotPath[mCurrentPlot].ConstantSpeed); }
protected override void UpdateWorld() { if (GamePad.Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (GamePad.ButtonAClicked() && mMyBall == null) { PlayACue("powerup"); mMyBall = new Ball((World.WorldMax + World.WorldMin) / 2f, RandomFloat(0.5f, 2f)); } if (mMyPaddle != null) { mMyPaddle.updatePaddle( GamePad.ButtonXClicked(), GamePad.ButtonBClicked(), GamePad.ThumbSticks.Right); World.ClampAtWorldBound(mMyPaddle.mPaddle); } if (mMyBall != null) { mMyBall.updateBall( GamePad.Buttons.LeftShoulder, GamePad.Buttons.RightShoulder); bool collided = mMyBall.mBall.Collided(mMyPaddle.mPaddle); if (collided) { Score++; mMyBall.PaddleCollide(mMyPaddle); } BoundCollideStatus collideStatus = World.CollideWorldBound(mMyBall.mBall); switch (collideStatus) { case BoundCollideStatus.CollideBottom: Score = 0; mMyBall.DestroyBall(); mMyBall = null; break; case BoundCollideStatus.CollideTop: World.ClampAtWorldBound(mMyBall.mBall); mMyBall.WallCollide(true); EchoToTopStatus(collideStatus.ToString()); break; case BoundCollideStatus.CollideLeft: case BoundCollideStatus.CollideRight: World.ClampAtWorldBound(mMyBall.mBall); mMyBall.WallCollide(false); EchoToTopStatus(collideStatus.ToString()); break; } } EchoToBottomStatus("Score: " + Score.ToString()); }