예제 #1
0
        /// <summary>
        /// Mouse handler of picture box.
        /// Moves the player ship to the new mouse position.
        /// </summary>
        private void GameMouseMove(object sender, MouseEventArgs args)
        {
            int x = args.X;

            if (x >= 0 && x + _ship.Width <= _pictureBox.Width)
            {
                _ship.Move(args.X);
            }
        }
예제 #2
0
        /// <summary>
        /// Move the object. Last call to move was deltaT seconds ago.
        /// </summary>
        /// <param name="deltaT">Time ellapsed since last move.</param>
        public void Move(double deltaT)
        {
            if ((Position.x >= 0 && (Position.x + Size.Width) < Game.game.gameSize.Width))
            {
                foreach (SpaceShip ship in Ships)
                {
                    ship.Move(deltaT, SpeedX.x);
                }

                Position.x += SpeedX.x * deltaT;

                if ((Position.x + Size.Width) >= Game.game.gameSize.Width)
                {
                    for (int i = 0; i < deltaT * 2000; ++i)
                    {
                        foreach (SpaceShip Ship in Ships)
                        {
                            Ship.Position.y += SpeedY.y * deltaT;
                        }

                        Position.y += SpeedY.y * deltaT;
                    }
                    SpeedX = -SpeedX * 1.1;
                }
            }

            else if (Position.x > 1)
            {
                foreach (SpaceShip Ship in Ships)
                {
                    Ship.Move(deltaT, SpeedX.x);
                }

                Position.x += SpeedX.x * deltaT;
            }

            else if (Position.x < 1)
            {
                for (int i = 0; i < deltaT * 2000; ++i)
                {
                    foreach (SpaceShip Ship in Ships)
                    {
                        Ship.Position.y += SpeedY.y * deltaT;
                    }

                    Position.y += SpeedY.y * deltaT;
                }
                SpeedX = -SpeedX * 1.1;

                foreach (SpaceShip Ship in Ships)
                {
                    Ship.Position.x += SpeedX.x / 10;
                }

                Position.x += SpeedX.x / 10;
            }
        }