private static void SetupInput(InputManager inputManager) { var exitAction = new KeyboardInput(Keys.Escape); inputManager.AddAction(exitAction, "Exit"); var up = new KeyboardInput(Keys.Up); var down = new KeyboardInput(Keys.Down, -1); inputManager.AddAxis(up, "Up"); inputManager.AddAxis(down, "Up"); }
public Paddle(Texture2D texture, ESide side, int screenWidth, int screenHeight, KeyboardInput keyboardInput = null, GamePadInput gamePadInput = null) { _screenWidth = screenWidth; _screenHeight = screenHeight; Vector2 position = new Vector2(); if (side == ESide.Left) { position.X = 0 + texture.Width; position.Y = screenHeight / 2; } else if (side == ESide.Right) { position.X = screenWidth - (texture.Width * 2); position.Y = screenHeight / 2; } _sprite = new Sprite("", texture, position, keyboardInput, gamePadInput); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here Contents.LoadAll(Content, graphics.GraphicsDevice); paddleOne = new Paddle(Contents.paddle, ESide.Left, screenWidth, screenHeight, KeyboardInput.Default()); paddleTwo = new Paddle(Contents.paddle, ESide.Right, screenWidth, screenHeight, gamePadInput: GamePadInput.Default()); ball = new Ball(Contents.ball, new Vector2(screenWidth / 2, screenHeight / 2), screenWidth, screenHeight); ball.Sprite.CollisionHandler = partner => { ball.Forward = !ball.Forward; }; collisionManager = new CollisionManager(paddleOne.Sprite, paddleTwo.Sprite, ball.Sprite); }