void Update() { if (!_GM.GameOver) { Movement(); if (Input.GetButton("Space")) { if (_turno) { _balaVelP1 += 10 * Time.deltaTime; } else { _balaVelP2 += 10 * Time.deltaTime; } } if (Input.GetButtonUp("Space")) { Shoot(); _balaVelP1 = _balaVelP2 = 0; } if (_colManager.CheckCollisions(1, ref _cBox)) { _vida.Life = -5; } _turno = _GM.SetTurn; } }
public static void Update(GameTime gameTime) { if (state == State.Game) { playingTime.TotalGameTime += gameTime.ElapsedGameTime; playingTime.ElapsedGameTime = gameTime.ElapsedGameTime; playingTime.TotalGameTime = TimeSpan.FromTicks((long)(playingTime.TotalGameTime.Ticks * playingTimeScale)); playingTime.ElapsedGameTime = TimeSpan.FromTicks((long)(playingTime.ElapsedGameTime.Ticks * playingTimeScale)); currentState.Update(playingTime); collisionManager.CheckCollisions(); if (Input.KeyDown("pause") && !gamePaused) { gamePaused = true; Instantiate(GetPrefab("Pause")); } } else { currentState.Update(gameTime); } }
void Update() { Move(); if (collisionManager.CheckCollisions(transform.ToRectangle())) { transform.position = prevPosition; } }
void CheckCollisions() { if (_colManager.CheckCollisions(1, ref _collisionBox)) { if (_i == false) { Instantiate(_explosion, transform.position, transform.rotation); _i = true; } Time.timeScale = 0.0f; } }
// Update is called once per frame void Update() { var previousPosition = Move(); LineSegment collisionLine; if (collisionManager.CheckCollisions(ToCircle(), out collisionLine)) { transform.position = previousPosition; velocity = Force.SpecularReflection(velocity, collisionLine); } }
void Update() { Movement(); if (_colManager.CheckCollisions(0, ref _cBox)) { Invoke("Destroid", 0.05f); } else if (this.transform.position.y < -3.42f) { _GM.SetTurn = _GM.SetTurn; Destroy(gameObject); } }
void FixedUpdate() { GlobalPlayerInputs(); if (mGameMode == GameMode.GameOver) { foreach (Player p in CrewManager.instance.players) { if (p != null) { if (p.Input.playerButtonInput[(int)ButtonInput.Pause] && !p.Input.previousButtonInput[(int)ButtonInput.Pause]) { StartNewGame(); GameOverScreen.instance.DisplayScreen(false); } } } return; } //The game doesnt run in editor mode if (mGameMode == GameMode.Paused) { foreach (Player p in CrewManager.instance.players) { if (p != null) { if ((p.Input.playerButtonInput[(int)ButtonInput.Pause] && !p.Input.previousButtonInput[(int)ButtonInput.Pause]) || p.Input.playerButtonInput[(int)ButtonInput.Menu_Back]) { UnpauseGame(); } } } return; } /* * if (players != null && players[0] != null && players[0].Input.playerButtonInput[(int)ButtonInput.Pause]) * { * StartNewGame(); * GameOverScreen.instance.DisplayScreen(false); * } */ //Right now, this update loop is nice and generic, I hope to keep it that way //Update all the entities for (int i = 0; i < mEntities.Count; ++i) { if (!mMapChangeFlag) { mEntities[i].EntityUpdate(); } } //Check for entities flagged for removal for (int i = mEntities.Count - 1; i >= 0; i--) { if (mEntities[i].mToRemove) { //Debug.Log(mEntities[i].Renderer.name + " Is being removed"); mEntities[i].ActuallyDie(); } } //Update the collisions of all objects CollisionManager.CheckCollisions(); //Second handles everything that needs to be done AFTER physics and collisions have been checked for (int i = 0; i < mEntities.Count; ++i) { //if(!mObjects[i].mToRemove) mEntities[i].SecondUpdate(); } //Check for game over bool allPlayersDead = true; bool playersExist = false; foreach (Player player in CrewManager.instance.players) { if (player == null) { continue; } playersExist = true; if (!player.IsDead) { allPlayersDead = false; } } //Debug.Log("APD: " + allPlayersDead + ", PE: " + playersExist); if (allPlayersDead && playersExist) { GameOver(); return; } /*If we want to change the map, we have to either abort everything or wait until we're finished updating * to perform the change. This method waits until everything is updated. */ if (mMapChangeFlag) { if (targetMap != null) { LoadMap(targetMap); targetMap = null; } mMapChangeFlag = false; } /* * if(warpToHubFlag) * { * LoadMap(MapType.Hub); * * warpToHubFlag = false; * } */ }
public override void Update(GameTime gameTime) { var scaleX = (float)graphicsDevice.PresentationParameters.BackBufferWidth / 1920; var scaleY = (float)graphicsDevice.PresentationParameters.BackBufferHeight / 1080; var matrix = Matrix.CreateScale(scaleX, scaleY, 1.0f); var pMousePosition = new Vector2(pmState.X, pmState.Y); var psmPosition = Vector2.Transform(pMousePosition, Matrix.Invert(matrix)); mState = Mouse.GetState(); var mousePosition = new Vector2(mState.X, mState.Y); var smPosition = Vector2.Transform(mousePosition, Matrix.Invert(matrix)); CollisionManager cm = new CollisionManager(mState, pmState, smPosition); playAgainDist = Vector2.Distance(Layout.PlayAgain, new Vector2(smPosition.X, smPosition.Y)); exitDist = Vector2.Distance(Layout.Exit, new Vector2(smPosition.X, smPosition.Y)); if (!mcm.MovingCard.IsMoving && !msm.StackIsMoving) { if (playAgainDist < Layout.ButtonRadius || exitDist < Layout.ButtonRadius) { if (!smiPlayed) { PlaySoundEffect(selectMenuItem, 0.2f, 0.3f); smiPlayed = true; } } if (MouseInput.CheckForSingleClick(pmState)) { if (playAgainDist < Layout.ButtonRadius) { game.ChangeToGameState(); } if (exitDist < Layout.ButtonRadius) { game.Exit(); } } if (!canWin) { deckManager.SendDoubleClicksToFoundation(mState, pmState, gameTime, clickTimer, smPosition); deckManager.ClickToFlipTableauCard(mState, pmState, smPosition); if (cm.DeckPileClick(deckManager)) { if (deckManager.CardsInPlay["Deck"].Length <= 0) { deckManager.ReturnWasteToDeck(); PlaySoundEffect(returnToDeck, 0.2f, -0.5f); } else { if (deckManager.CardWasAlreadyDrawn) { deckManager.AddCardToPile(deckManager.CardsInPlay["Deck"][deckManager.CardsInPlay["Deck"].Length - 1], "Waste"); deckManager.CardsInPlay["Deck"] = deckManager.DownsizePile(deckManager.CardsInPlay["Deck"]); } if (deckManager.CardsInPlay["Deck"].Length > 0) { deckManager.DrawACard(); } else { deckManager.CardWasAlreadyDrawn = false; } PlaySoundEffect(draw, 0.3f, 0.8f); } } } else { deckManager.WinGame(); if (deckManager.CardsInPlay["Hearts"].Length > 13 && deckManager.CardsInPlay["Spades"].Length > 13 && deckManager.CardsInPlay["Diamonds"].Length > 13 && deckManager.CardsInPlay["Clubs"].Length > 13) { canWin = false; } } } if (mcm.CheckIfMovementStopped(mState) || msm.CheckIfMovementStopped(mState)) { if (mcm.MovingCard.IsMoving) { mcm.MovingCard.IsMoving = false; if (cm.CheckCollisions(mcm.MovingCard, deckManager)) { mcm.MovingCard = new Card(); } else { mcm.ReturnCardToPile(deckManager); } } else { msm.StackIsMoving = false; if (cm.CheckStackCollisions(msm.MovingStack, deckManager)) { msm.MovingStack = new Card[0]; } else { msm.ReturnStackToPile(deckManager); } } PlaySoundEffect(placeCard, 0.1f, 0.6f); } if (!mcm.MovingCard.IsMoving && msm.CheckForMovement(deckManager, mState, pmState, smPosition)) { msm.MoveStack(mState, pmState, smPosition, psmPosition); } if (!msm.StackIsMoving && mcm.CheckForMovement(deckManager, mState, pmState, smPosition)) { mcm.MoveCard(mState, pmState, smPosition, psmPosition); } CheckCardsForAnimations(gameTime); if (!canWin) { canWin = deckManager.CheckForWin(mcm, msm); } }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } switch (gameState) { case GameStates.TitleScreen: titleScreenTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (titleScreenTimer >= titleScreenDelayTime) { if ((Keyboard.GetState().IsKeyDown(Keys.Space)) || (GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed)) { playerManager.LivesRemaining = playerStartingLives; playerManager.PlayerScore = 0; ResetGame(); gameState = GameStates.Playing; } } break; case GameStates.Playing: starField.Update(gameTime); asteroidManager.Update(gameTime); playerManager.Update(gameTime); enemyManager.Update(gameTime); explosionManager.Update(gameTime); collisionManager.CheckCollisions(); if (playerManager.Destroyed) { playerDeathTimer = 0f; enemyManager.Active = false; playerManager.LivesRemaining--; if (playerManager.LivesRemaining < 0) { gameState = GameStates.GameOver; } else { gameState = GameStates.PlayerDead; } } break; case GameStates.PlayerDead: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; starField.Update(gameTime); asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { ResetGame(); gameState = GameStates.Playing; } break; case GameStates.GameOver: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; starField.Update(gameTime); asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { gameState = GameStates.TitleScreen; } break; } base.Update(gameTime); }