public void Update(TouchCollection touchPlaces) { if (!isPlayMainSound) { MediaPlayer.Play(songs.Find(o => o.myName.Equals("mainSound")).song); isPlayMainSound = true; } if (canMove) { time++; timeSec = time / 60; timeLeft = roundTime - timeSec; if (timeLeft >= 0) { findByName("digitOfTens").texture = findByName((timeLeft / 10).ToString()).texture; findByName("digitOfUnity").texture = findByName((timeLeft % 10).ToString()).texture; } //else //{ // canMove = false; // fail = true; // findByName("buttonAgain").isDraw = true; // findByName("buttonMenu").isDraw = true; //} if (!isButtonOn) { findByName("switchOff").isDraw = true; findByName("switchOn").isDraw = false; groundList.Find(g => g.myName.Equals("longBorder")).isDraw = false; groundList.Find(g => g.myName.Equals("longBorder")).canTouch = false; } else { findByName("switchOff").isDraw = false; findByName("switchOn").isDraw = true; groundList.Find(g => g.myName.Equals("longBorder")).isDraw = true; groundList.Find(g => g.myName.Equals("longBorder")).canTouch = true; } foreach (TouchLocation touch in touchPlaces) { Vector2 touchPosition = touch.Position; if (touch.State == TouchLocationState.Moved) { if (isTouchButton(touchPosition, findByName("buttonR"))) { moveCounter++; right = true; if (help.X <= maxHenX) { help.X += dx; foreach (Ground ground in groundList) { ground.rectangle.X -= dx; } foreach (MyObject o in myObjects) { if (!o.myName.Contains("button") && !o.myName.Contains("smallChicken") && o.isMove) { o.rectangle.X -= dx; } } foreach (Board b in boardList) { b.rectangle.X -= dx; } foreach (Ghost ghost in ghostList) { ghost.rectangle.X -= dx; } } } if (isTouchButton(touchPosition, findByName("buttonLeft"))) { moveCounter++; right = false; if (help.X >= 3) { bool stop = false; foreach (Ground g in groundList) { if (g.rectangle.Intersects(hen.rectangle) && (g.rectangle.Y + g.rectangle.Height) > hen.rectangle.Y) { foreach (Ground gr in groundList) { if (gr.rectangle.Intersects(hen.rectangle)) { if (gr.rectangle.X != g.rectangle.X && gr.rectangle.Y != g.rectangle.Y) { stop = true; } } } } } if (!stop) { help.X -= dx; foreach (Ground ground in groundList) { ground.rectangle.X += dx; } foreach (MyObject o in myObjects) { if (!o.myName.Contains("button") && !o.myName.Contains("smallChicken") && o.isMove) { o.rectangle.X += dx; } } foreach (Board b in boardList) { b.rectangle.X += dx; } foreach (Ghost ghost in ghostList) { ghost.rectangle.X += dx; } } } } } if (touch.State == TouchLocationState.Pressed) { if (isTouchButton(touchPosition, findByName("buttonUp"))) { jump = true; } if (isTouchButton(touchPosition, findByName("buttonMenu"))) { myName = "Menu"; } } } hen.position(hen.rectangle.Y - jumpCounter); moveBoard(); jumping(); if (right) { int texNum; if (!jump) { if (moveCounter < (maxMoveCounter / 2)) { texNum = myObjects.FindIndex(c => c.myName.Equals("henR1")); } else { texNum = myObjects.FindIndex(c => c.myName.Equals("henR2")); } hen.texture = myObjects[texNum].texture; } else { texNum = myObjects.FindIndex(c => c.myName.Equals("henRU")); hen.texture = myObjects[texNum].texture; } } else { int texNum; if (!jump) { if (moveCounter < (maxMoveCounter / 2)) { texNum = myObjects.FindIndex(c => c.myName.Equals("henL1")); } else { texNum = myObjects.FindIndex(c => c.myName.Equals("henL2")); } hen.texture = myObjects[texNum].texture; } else { texNum = myObjects.FindIndex(c => c.myName.Equals("henLU")); hen.texture = myObjects[texNum].texture; } } foreach (Ground g in groundList) { if (!g.canTouch) { if (hen.legsRectangle.X > g.rectangle.X && hen.legsRectangle.X < g.rectangle.X + g.rectangle.Width) { canMove = false; fail = true; findByName("buttonAgain").isDraw = true; findByName("buttonMenu").isDraw = true; } } } } ghostMoveCounter++; if (ghostMoveCounter > ghostMoveCounterMax) { ghostMoveCounter = 0; } if (changeMoveRight) { if (changeMove < this.height / 100) { if (ghostMoveCounter % 2 == 0) { changeMove++; } } else { changeMoveRight = false; } } else { if (changeMove > -this.height / 100) { if (ghostMoveCounter % 2 == 0) { changeMove--; } } else { changeMoveRight = true; } } foreach (Ghost ghost in ghostList) { ghost.rectangle.X += changeMove; if (ghost.rectangle.Y > -ghost.rectangle.Height) { ghost.rectangle.Y -= 2; } else { ghost.rectangle.Y = this.height + ghost.rectangle.Height; } if (ghostMoveCounter < ghostMoveCounterMax / 2) { //ghost.texture = findByName("ghostTex1").texture; ghost.texture = ghost.texture1; } else { //ghost.texture = findByName("ghostTex2").texture; ghost.texture = ghost.texture2; } } }
public void Update(TouchCollection touchPlaces) { if (!isSoundPlay) { MediaPlayer.Play(songs.Find(o => o.myName.Equals("mainSound")).song); isSoundPlay = true; } if (moveCounter > maxMoveCounter) { moveCounter = 0; } int num = myObjects.FindIndex(c => c.myName.Equals("cloud")); myObjects[num].rectangle.X++; num = myObjects.FindIndex(c => c.myName.Equals("cloud2")); myObjects[num].rectangle.X--; num = myObjects.FindIndex(c => c.myName.Equals("cloud3")); myObjects[num].rectangle.X++; num = myObjects.FindIndex(c => c.myName.Equals("buttonR")); int numUp = myObjects.FindIndex(c => c.myName.Equals("buttonUp")); int numL = myObjects.FindIndex(c => c.myName.Equals("buttonLeft")); int buttonNo = myObjects.FindIndex(c => c.myName.Equals("butRed")); int numAgain = myObjects.FindIndex(c => c.myName.Equals("buttonAgain")); int numMenu = myObjects.FindIndex(c => c.myName.Equals("buttonMenu")); int numNextRound = myObjects.FindIndex(c => c.myName.Equals("buttonNextRound")); int numCaptionLose = myObjects.FindIndex(c => c.myName.Equals("captionLose")); int numCaptionEndRound = myObjects.FindIndex(c => c.myName.Equals("captionEndRound")); if (canMove) { time++; timeSec = time / 60; timeLeft = roundTime - timeSec; if (timeLeft >= 0) { findByName("digitOfTens").texture = findByName((timeLeft / 10).ToString()).texture; findByName("digitOfUnity").texture = findByName((timeLeft % 10).ToString()).texture; } else { canMove = false; dotknelaIgly = true; findByName("buttonAgain").isDraw = true; findByName("buttonMenu").isDraw = true; } foreach (TouchLocation touch in touchPlaces) { Vector2 touchPosition = touch.Position; if (touch.State == TouchLocationState.Moved) { if (touchPosition.X > myObjects[num].rectangle.X && touchPosition.X <myObjects[num].rectangle.X + myObjects[num].rectangle.Width && touchPosition.Y> myObjects[num].rectangle.Y && touchPosition.Y < myObjects[num].rectangle.Y + myObjects[num].rectangle.Height) { moveCounter++; right = true; if (help.X <= (width * 2)) { help.X += dx; foreach (Ground ground in groundList) { ground.rectangle.X -= dx; } foreach (MyObject o in myObjects) { if (!o.myName.Contains("button") && !o.myName.Contains("smallChicken") && o.isMove) { o.rectangle.X -= dx; } } } } if (touchPosition.X > myObjects[numL].rectangle.X && touchPosition.X <myObjects[numL].rectangle.X + myObjects[numL].rectangle.Width && touchPosition.Y> myObjects[numL].rectangle.Y && touchPosition.Y < myObjects[numL].rectangle.Y + myObjects[numL].rectangle.Height) { moveCounter++; right = false; if (help.X >= 3) { bool stop = false; foreach (Ground g in groundList) { if (g.rectangle.Intersects(hen.rectangle) && (g.rectangle.Y + g.rectangle.Height) > hen.rectangle.Y) { foreach (Ground gr in groundList) { if (gr.rectangle.Intersects(hen.rectangle)) { if (gr.rectangle.X != g.rectangle.X && gr.rectangle.Y != g.rectangle.Y) { stop = true; } } } } } if (!stop) { help.X -= dx; foreach (Ground ground in groundList) { ground.rectangle.X += dx; } foreach (MyObject o in myObjects) { if (!o.myName.Contains("button") && !o.myName.Contains("smallChicken") && o.isMove) { o.rectangle.X += dx; } } } } } } if (touch.State == TouchLocationState.Pressed) { if (touchPosition.X > myObjects[numUp].rectangle.X && touchPosition.X <myObjects[numUp].rectangle.X + myObjects[numUp].rectangle.Width && touchPosition.Y> myObjects[numUp].rectangle.Y && touchPosition.Y < myObjects[numUp].rectangle.Y + myObjects[numUp].rectangle.Height) { jump = true; soundEffects.Find(o => o.myName.Equals("jumpSound")).soundEffect.CreateInstance().Volume = 1.0f; soundEffects.Find(o => o.myName.Equals("jumpSound")).soundEffect.Play(); } if (isTouchButton(touchPosition, myObjects[numMenu]) && myObjects[numMenu].isDraw) { myName = "Menu"; } } } // hen.rectangle.Y = hen.rectangle.Y - jumpCounter; hen.position(hen.rectangle.Y - jumpCounter); if (jump) { if (jumpUp) { jumpCounter++; if (jumpCounter > 2.1 * (height / 100)) //if (jumpCounter > (hen.rectangle.Height)) { jumpUp = false; jumpDown = true; } } if (jumpDown) { jumpCounter--; if (hen.rectangle.Y >= henY) { jumpDown = false; jumpUp = true; jump = false; jumpCounter = 0; hen.rectangle.Y = henY; } if (hen.legsRectangle.Intersects(myObjects[buttonNo].rectangle)) { if (!podnoszenie) { podnoszenie = true; } henY = myObjects[buttonNo].rectangle.Y - hen.rectangle.Height; } foreach (Ground g in groundList) { if (!g.isFloor) { //zmieniono if (hen.legsRectangle.Intersects(g.rectangle)) { henY = g.rectangle.Y - hen.rectangle.Height; break; } } } } } else { if (henY != henYStart) { bool toDown = true; foreach (Ground g in groundList) { if (!g.isFloor) { //zmieniono if (g.rectangle.Intersects(hen.legsRectangle)) { toDown = false; break; } } } if (hen.legsRectangle.Intersects(myObjects[buttonNo].rectangle)) { toDown = false; } if (toDown) { if (henY != henYStart) { int dy = (height * 9) / 720; if (dy < 1) { dy = 1; } henY += dy; if (henY == henYStart) { toDown = false; } else if (henY > henYStart) { henY = henYStart; toDown = false; } hen.rectangle.Y = henY; } } } } if (right) { int texNum; if (!jump) { //texNum = myObjects.FindIndex(c => c.myName.Equals("henR")); if (moveCounter < (maxMoveCounter / 2)) { texNum = myObjects.FindIndex(c => c.myName.Equals("henR1")); } else { texNum = myObjects.FindIndex(c => c.myName.Equals("henR2")); } hen.texture = myObjects[texNum].texture; } else { texNum = myObjects.FindIndex(c => c.myName.Equals("henRU")); hen.texture = myObjects[texNum].texture; } } else { int texNum; if (!jump) { //texNum = myObjects.FindIndex(c => c.myName.Equals("henL")); if (moveCounter < (maxMoveCounter / 2)) { texNum = myObjects.FindIndex(c => c.myName.Equals("henL1")); } else { texNum = myObjects.FindIndex(c => c.myName.Equals("henL2")); } hen.texture = myObjects[texNum].texture; } else { texNum = myObjects.FindIndex(c => c.myName.Equals("henLU")); hen.texture = myObjects[texNum].texture; } } if (podnoszenie) { podnoszenieLicznik++; if (podnoszenieLicznik % 20 == 0) { iglyIndeks++; foreach (Ground g in groundList) { if (g.textureFile.Contains("igly")) { g.texture = myObjects[myObjects.FindIndex(c => c.myName.Equals("igly" + iglyIndeks))].texture; if (iglyIndeks == 2) { g.canTouch = true; } } } if (myObjects[myObjects.FindIndex(c => c.myName.Equals("signallerRed"))].isDraw) { myObjects[myObjects.FindIndex(c => c.myName.Equals("signallerRed"))].isDraw = false; myObjects[myObjects.FindIndex(c => c.myName.Equals("signallerYellow"))].isDraw = true; } else if (myObjects[myObjects.FindIndex(c => c.myName.Equals("signallerYellow"))].isDraw) { myObjects[myObjects.FindIndex(c => c.myName.Equals("signallerYellow"))].isDraw = false; myObjects[myObjects.FindIndex(c => c.myName.Equals("signallerGreen"))].isDraw = true; } } if (iglyIndeks == 2) { podnoszenie = false; podnoszenieLicznik = 0; iglyIndeks = 0; } } foreach (Ground g in groundList) { if (!g.canTouch) { if (hen.legsRectangle.X > g.rectangle.X && hen.legsRectangle.X < g.rectangle.X + g.rectangle.Width) { canMove = false; dotknelaIgly = true; myObjects[numAgain].isDraw = true; myObjects[numMenu].isDraw = true; } } } } else { findByName("dimness").rectangle.X = 0; findByName("dimness").rectangle.Y = 0; findByName("dimness").isDraw = true; if (dotknelaIgly) { hen.texture = findByName("spiritTexture").texture; hen.rectangle.Y--; findByName("captionLose").isDraw = true; if (!isPlayChoirVoice) { MediaPlayer.Play(songs.Find(o => o.myName.Equals("choir")).song); isPlayChoirVoice = true; } } else { findByName("buttonNextRound").isDraw = true; findByName("captionEndRound").isDraw = true; if (timeLeft >= roundTime - 20) { findByName("firstStar").texture = findByName("goldenStar").texture; findByName("secondStar").texture = findByName("goldenStar").texture; findByName("thirdStar").texture = findByName("goldenStar").texture; } else if (timeLeft >= roundTime - 25) { findByName("firstStar").texture = findByName("goldenStar").texture; findByName("secondStar").texture = findByName("goldenStar").texture; findByName("thirdStar").texture = findByName("greyStar").texture; } else { findByName("firstStar").texture = findByName("goldenStar").texture; findByName("secondStar").texture = findByName("greyStar").texture; findByName("thirdStar").texture = findByName("greyStar").texture; } findByName("firstStar").isDraw = true; findByName("secondStar").isDraw = true; findByName("thirdStar").isDraw = true; } findByName("buttonR").isDraw = false; findByName("buttonLeft").isDraw = false; findByName("buttonUp").isDraw = false; findByName("buttonMenu").isDraw = true; foreach (TouchLocation touch in touchPlaces) { Vector2 touchPosition = touch.Position; if (touch.State == TouchLocationState.Pressed) { if (isTouchButton(touchPosition, myObjects[numAgain]) && myObjects[numAgain].isDraw) { myName = "ReloadRound2"; } if (isTouchButton(touchPosition, myObjects[numMenu]) && myObjects[numMenu].isDraw) { myName = "Menu"; } if (isTouchButton(touchPosition, myObjects[numNextRound]) && myObjects[numNextRound].isDraw) { myName = "Menu"; } } } } catchChicken(); isEndOfRound(); }