public void Update(GameTime gameTime, KeyboardState teclado, KeyboardState tecladoanterior) { contEscudo++; if (contEscudo > maxCont) { contEscudo = maxCont; } #region Mover Nave if (angulo > 360) { angulo -= 360; } if (angulo < 0) { angulo += 360; } if (teclado.IsKeyDown(Keys.Left) || teclado.IsKeyDown(Keys.A)) { this.angulo -= 5; } if (teclado.IsKeyDown(Keys.Right) || teclado.IsKeyDown(Keys.D)) { this.angulo += 5; } if (teclado.IsKeyDown(Keys.Up) || teclado.IsKeyDown(Keys.W)) { this.velocidade.X += (float)Math.Cos(Math.PI * this.angulo / 180) * 0.1f; this.velocidade.Y += (float)Math.Sin(Math.PI * this.angulo / 180) * 0.1f; if (velocidade.X > 7) { velocidade.X = 7; } if (velocidade.X < -7) { velocidade.X = -7; } if (velocidade.Y > 7) { velocidade.Y = 7; } if (velocidade.Y < -7) { velocidade.Y = -7; } } posicao += velocidade; #endregion #region Limites da tela if (posicao.X > Stage.ClientBounds.Width + textura.Width / 2) { posicao.X = -textura.Width / 2 + 10; Fase7.Objetivo++; } if (posicao.X < -textura.Width / 2 + 10) { if (Fase7.Objetivo > 0) { Fase7.Objetivo--; } posicao.X = Stage.ClientBounds.Width + textura.Width / 2; } if (posicao.Y > Stage.ClientBounds.Height + textura.Height / 2) { posicao.Y = 0 - textura.Height / 2; } if (posicao.Y < 0 - textura.Height / 2) { posicao.Y = Stage.ClientBounds.Height + textura.Height / 2; } #endregion #region Escudo e Barra if (teclado.IsKeyDown(Keys.E) && !ativar_escudo && contEscudo >= maxCont) { contEscudo = 0; ativar_escudo = true; } if (teclado.IsKeyDown(Keys.E) && ativar_escudo && contEscudo >= maxCont) { contEscudo = 0; ativar_escudo = false; } if (ativar_escudo) { escudo.Update(posicao); } barra.Update(ativar_escudo); if (!barra.permicao) { ativar_escudo = false; } #endregion }
public void Update(GameTime _gameTime, KeyboardState _teclado, KeyboardState _tecladoAnterior, GamePadState _controle, GamePadState _controleanterior) { if (isGameOver()) { vidas = 7; velocidade.X = 0; velocidade.Y = 0; posicao.X = (gw.ClientBounds.Width / 2) - textura.Width / 2 - 150; posicao.Y = (gw.ClientBounds.Height / 2) - textura.Height / 2; angulo = 0; doGameOver(); } if (jogador == 1) { movePlayerOne(ref _teclado, ref _tecladoAnterior, ref _controle, ref _controleanterior); } #region Criar escudo cont_escudo++; if (cont_escudo >= cont_max) { cont_escudo = cont_max; } barra.Update(_escudo); if ((_teclado.IsKeyDown(Keys.E) && _tecladoAnterior.IsKeyUp(Keys.E)) || (_controle.IsButtonDown(Buttons.B) && _controleanterior.IsButtonUp(Buttons.B)) && cont_escudo == cont_max) { if (!_escudo) { _escudo = true; } else { _escudo = false; } cont_escudo = 0; } if (!barra.permicao) { _escudo = false; } if (_escudo) { escudo.Update(posicao); } #endregion #region Jogador 2 (Não implementado) if (jogador == 2) { if (_teclado.IsKeyDown(Keys.A)) { } if (_teclado.IsKeyDown(Keys.D)) { } if (_teclado.IsKeyDown(Keys.W)) { } } #endregion #region Verificar os limites de velocidade int maxSpeed = Status.VelNave * 4; if (isMaxSpeed(maxSpeed)) { if (velocidade.X < 0) { velocidade.X = -maxSpeed; } else { velocidade.X = maxSpeed; } } #endregion posicao += velocidade; #region Verifica nave nos limites da tela if (posicao.X < 0) { posicao.X = gw.ClientBounds.Width; } else if (posicao.X > gw.ClientBounds.Width) { posicao.X = 0; } if (posicao.Y < 0) { posicao.Y = gw.ClientBounds.Height; } else if (posicao.Y > gw.ClientBounds.Height) { posicao.Y = 0; } #endregion Shot.Update(_gameTime); }