public virtual int Update(GameTime gameTime) { HandleInput(gameTime); if (p != null) { p.Update(gameTime); if (p.destroySig == 1 || ConvertUnits.ToDisplayUnits(p.body.Position.X) < 0 || ConvertUnits.ToDisplayUnits(p.body.Position.X) > 800) { p.Dispose(); p = null; nextWind(); return (turn + 1); } } return turn; }
private void HandleShooting(KeyboardState keyState, KeyboardState oldState, GameTime gameTime) { if (keyState.IsKeyUp(Keys.Enter) && oldState.IsKeyDown(Keys.Enter)) { if (p == null) { p = new Projectile(world, new Vector2(ConvertUnits.ToDisplayUnits(cannon.Body.Position.X) + (float)Math.Cos(cannon.Body.Rotation - (float)Math.PI / 2) * 50, ConvertUnits.ToDisplayUnits(cannon.Body.Position.Y) + (float)Math.Sin(cannon.Body.Rotation - (float)Math.PI / 2) * 50), 16, 16, 1, cannon.Body.Rotation - (float)Math.PI / 2, texture); } } }
private void HandleShooting(int state, int oldState, GameTime gameTime) { if (getKeyState(state,false,Keys.Enter) && getKeyState(oldState,true,Keys.Enter) && p == null) { shootPower = 0f; increasePower = true; activity = Activity.Shooting; } if (getKeyState(state,false,Keys.Enter) && getKeyState(oldState,false,Keys.Enter) && p == null) { if (increasePower == true) { if (shootPower < 40f) { shootPower += 0.2f; } if (shootPower >= 40f) { increasePower = false; } } else if (increasePower == false) { if (shootPower > 0f) { shootPower -= 0.2f; } if (shootPower <= 0f) { increasePower = true; } } } if (getKeyState(state,true,Keys.Enter) && getKeyState(oldState,false,Keys.Enter) && p == null) { p = new Projectile(world, new Vector2(ConvertUnits.ToDisplayUnits(cannon.Body.Position.X) + (float)Math.Cos(cannon.Body.Rotation - (float)Math.PI / 2) * 50, ConvertUnits.ToDisplayUnits(cannon.Body.Position.Y) + (float)Math.Sin(cannon.Body.Rotation - (float)Math.PI / 2) * 50), 16, 16, 1, cannon.Body.Rotation - (float)Math.PI / 2, shootPower, wind, chTexture.projectile); activity = Activity.Idle; shootPower = 0f; } }