示例#1
0
文件: Program.cs 项目: dcf417/Pong
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (PongGame game = new PongGame())
     {
         game.Run();
     }
 }
 private void _kinect_UserCreated(object sender, KinectUserEventArgs e)
 {
     DispatcherHelper.CheckBeginInvokeOnUI(() =>
     {
         lock (_syncRoot)
         {
             User kuser = _kinect.GetUser(e.User.Id);
             if (kuser != null)
             {
                 _player = kuser;
                 AccelerationGesture AccelerationGesture =
                     _player.AddAccelerationGesture();
                 AccelerationGesture.AccelerationCalculated +=
                     AccelerationGesture_AccelerationCalculated;
                 if (_players.Count % 2 == 0)
                 {
                     PongGame.Paddles.Add(new Paddle(
                                              Paddle.Side.Right, false,
                                              kuser.Id));
                 }
                 else
                 {
                     PongGame.Paddles.Add(new Paddle(Paddle.Side.Left,
                                                     false, kuser.Id));
                 }
                 _players.Add(_player);
                 if (PongGame.Paddles.Count == 2)
                 {
                     PongGame.AddBall();
                 }
             }
             DebugInformation = "User Created";
         }
     });
 }
示例#3
0
 public void Reset()
 {
     xPos      = (PongGame.GetScreenWidth() - this.width) / 2;
     yPos      = (PongGame.GetScreenHeight() - this.height) / 2;
     xVelocity = (rand.NextDouble() < 0.5 ? 1 : -1) * 4;
     yVelocity = (rand.NextDouble() < 0.5 ? 1 : -1) * 8;
 }
 public Racket(PongGame pongGame, bool isTop)
 {
     this._pongGame = pongGame;
     this.texture   = pongGame.texture;
     this.isTop     = isTop;
     y = (isTop ? pongGame.height * 0.05f : pongGame.height * 0.95f);
 }
示例#5
0
    void Awake()
    {
        PongGame game = FindObjectOfType <PongGame>();

        if (game != null)
        {
            game.SubscribeUI(this);
        }
    }
 public MainViewModel()
 {
     SetCommands();
     _players         = new ObservableCollection <User>();
     PongGame         = PongGame.Instance;
     PongGame.Boundry = new Rectangle(0, 0, 0, 0);
     PongGame.Scored += PongGame_Scored;
     PongGame.Start();
 }
示例#7
0
 private void EnsureInstanceExists()
 {
     if (instance == null)
     {
         DontDestroyOnLoad(gameObject);
         instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
示例#8
0
 public void Move(bool left)
 {
     if (left && xPos < movementAmount)
     {
         return;
     }
     if (!left && xPos > PongGame.GetScreenWidth() - width - movementAmount)
     {
         return;
     }
     xPos += (left ? -1 : 1) * movementAmount;
 }
示例#9
0
        public static void InicializarDatos(PongGame contexto)
        {
            limitesDePantalla.X = contexto.GraphicsDevice.DisplayMode.Width;
            limitesDePantalla.Y = contexto.GraphicsDevice.DisplayMode.Height;

            limitesDeVentana.X = contexto.Window.ClientBounds.Width;
            limitesDeVentana.Y = contexto.Window.ClientBounds.Height;

            centroDeVentana.X = limitesDeVentana.X / 2;
            centroDeVentana.Y = limitesDeVentana.Y / 2;

            centroDePantalla.X = limitesDePantalla.X / 2;
            centroDePantalla.Y = limitesDePantalla.Y / 2;
        }
示例#10
0
        private Orientation SetPosition()
        {
            Orientation orientation;

            switch (side)
            {
            case Side.LEFT:
                xPos   = -10;
                yPos   = 0;
                width  = 10;
                height = PongGame.GetScreenHeight();

                orientation = Orientation.VERTICAL;
                break;

            case Side.RIGHT:

                xPos   = GetScreenWidth();
                yPos   = 0;
                width  = 10;
                height = PongGame.GetScreenHeight();

                orientation = Orientation.VERTICAL;
                break;

            case Side.TOP:

                xPos   = 0;
                yPos   = -10;
                width  = PongGame.GetScreenWidth();
                height = 10;

                orientation = Orientation.HORIZONTAL;
                break;

            default:
            case Side.BOTTOM:

                xPos   = 0;
                yPos   = PongGame.GetScreenHeight();
                width  = PongGame.GetScreenWidth();
                height = 10;

                orientation = Orientation.HORIZONTAL;
                break;
            }
            return(orientation);
        }
示例#11
0
        static void Main(string[] args)
        {
            RenderWindow rw = new RenderWindow(new VideoMode(800, 600), "SFML works!", Styles.Default);

            rw.SetFramerateLimit(60);
            rw.Closed += (sender, arg) => rw.Close();
            PongGame pong = new PongGame(rw);

            while (rw.IsOpen)
            {
                rw.DispatchEvents();


                rw.Clear(Color.Black);
                rw.Draw(pong);
                pong.update();


                rw.Display();
            }
        }
        public override void Update(GameTime gameTime, GameState gameState)
        {
            var Width  = gameState.Width;
            var Height = gameState.Height;

            Result.Update(Players);

            var viewPort = gameState.ViewPort.Size.ToVector2();

            UpdatePlayers(gameTime, gameState, viewPort, Players, Balls);

            UpdateBalls(gameTime, gameState, viewPort, Balls);
            Engine.Update();


            if (Result.Winner != null)
            {
                ResetGame(Width, Height);
                PongGame.ShowMainMenu();
            }
            base.Update(gameTime, gameState);
        }
示例#13
0
 public void Setup()
 {
     p1   = Substitute.For <ICounter>();
     p2   = Substitute.For <ICounter>();
     game = new PongGame(p1, p2);
 }
        private void SetCommands()
        {
            KeyPress = new RelayCommand <KeyEventArgs>(e =>
            {
                if (e.Key == Key.S)
                {
                    DebugInformation = "Kinect starting...";
                    SetupKinect();
                }
                else if (e.Key == Key.Q)
                {
                    CloseKinect();
                }
                else if (e.Key == Key.Y)
                {
                    PongGame.AddPaddle(Paddle.Side.Left, true, -1);
                }
                else if (e.Key == Key.U)
                {
                    PongGame.AddPaddle(Paddle.Side.Right, true, -1);
                }
                else if (e.Key == Key.I)
                {
                    PongGame.Reset();
                }
                else if (e.Key == Key.K)
                {
                    CloseKinect();
                }
                else if (e.Key == Key.B)
                {
                    PongGame.AddBall();
                }
                else if (e.Key == Key.P)
                {
                    PongGame.AddBall();
                    PongGame.Start();
                }
                else if (e.Key == Key.C)
                {
                    SetCameraView();
                    switch (_imageType)
                    {
                    case Core.CameraView.None:
                        _imageType       = Core.CameraView.ColoredDepth;
                        DebugInformation = "Colored Depth";
                        break;

                    case Core.CameraView.ColoredDepth:
                        _imageType       = Core.CameraView.Color;
                        DebugInformation = "Color";
                        break;

                    case Core.CameraView.Color:
                        _imageType       = Core.CameraView.Depth;
                        DebugInformation = "Depth";
                        break;

                    case Core.CameraView.Depth:
                        _imageType       = Core.CameraView.None;
                        DebugInformation = "";
                        break;

                    default:
                        break;
                    }
                }
            });

            Closing = new RelayCommand <CancelEventArgs>(e =>
            {
                CloseKinect();
                Application.Current.Shutdown();
            });

            SizeChanged =
                new RelayCommand <SizeChangedEventArgs>(
                    e =>
            {
                PongGame.Boundry = new Rectangle(0, 0, Convert.ToInt32(e.NewSize.Width),
                                                 Convert.ToInt32(e.NewSize.Height));
            });
        }
示例#15
0
 public Pantallas(PongGame contexto)
 {
     this.contexto   = contexto;
     escenasCargadas = new Dictionary <string, EscenaBase>();
     InicializarComponentes();
 }
示例#16
0
 public Ball(PongGame pongGame)
 {
     this._pongGame = pongGame;
     this.texture   = pongGame.texture;
 }
示例#17
0
 private void ResetPos()
 {
     xPos = (PongGame.GetScreenWidth() - this.width) / 2;
     yPos = isPlayerControlled ? PongGame.GetScreenHeight() - this.height : 0;
 }