public Vector2 GetControl(float playerMoveSpeed, Vector2 position, List<GameObject> gameObjects) { _position = position; previousKbState = currentKbState; currentKbState = Keyboard.GetState(); Bullet bullet = new Bullet(); if (currentKbState.IsKeyDown(Keys.D)) { _position.X += playerMoveSpeed; _frame = 0; _bulletDirection = "R"; } else if (currentKbState.IsKeyDown(Keys.A)) { _position.X -= playerMoveSpeed; _frame = 1; _bulletDirection = "L"; } else if (currentKbState.IsKeyDown(Keys.W)) { _position.Y -= playerMoveSpeed; _frame = 3; _bulletDirection = "U"; } else if (currentKbState.IsKeyDown(Keys.S)) { _position.Y += playerMoveSpeed; _frame = 2; _bulletDirection = "D"; } if (currentKbState.IsKeyDown(Keys.Z)) { _timeSpan = _stopWatch.Elapsed; foreach (GameObject obj in gameObjects) { if (obj.Id >= 1000 && obj.Id < 2000 && obj.IsActive == false && _timeSpan.TotalSeconds > 0.5) { bullet = (Bullet)obj; bullet.Shoot(_bulletDirection, _position); _stopWatch.Reset(); _stopWatch.Start(); break; } } } _position.X = (int)MathHelper.Clamp(_position.X, 0, Game1.screenWidth - _width); _position.Y = (int)MathHelper.Clamp(_position.Y, 0, Game1.screenHeight - _height); return _position; }
public Vector2 GetControl(float playerMoveSpeed, Vector2 position, List<GameObject> gameObjects) { _position = position; Bullet bullet = new Bullet(); if (_frame == 0) //right { _position.X += playerMoveSpeed; _bulletDirection = "R"; } else if (_frame == 1) //left { _position.X -= playerMoveSpeed; _bulletDirection = "L"; } else if (_frame == 3) //up { _position.Y -= playerMoveSpeed; _bulletDirection = "U"; } else if (_frame == 2) //down { _position.Y += playerMoveSpeed; _bulletDirection = "D"; } _timeSpan = _stopWatch.Elapsed; //choose directin every few seconds if (_timeSpan.TotalSeconds > 1 && _timeSpan.TotalSeconds < 7) { ChooseDirection(); _stopWatch.Reset(); _stopWatch.Start(); } foreach (GameObject obj in gameObjects) { if (obj.Id >= 1000 && obj.Id < 2000 && obj.IsActive == false && _timeSpan.TotalSeconds > 0.6) { bullet = (Bullet)obj; bullet.Shoot(_bulletDirection, _position); break; } } _position.X = (int)MathHelper.Clamp(_position.X, 0, Game1.screenWidth - _width); _position.Y = (int)MathHelper.Clamp(_position.Y, 0, Game1.screenHeight - _height); return _position; }