예제 #1
0
        public void UpdatePosition(Planet planet, GameTime gameTime)
        {
            double factor = gameTime.ElapsedGameTime.TotalMilliseconds / 5;

            var newValue = planet.X + planet.XVelocity*factor;
            if (newValue > PlanetaryWidth - planet.Width || newValue < 0)
            {
                planet.XVelocity = -planet.XVelocity;
            } else
            {
                planet.X = newValue;
            }

            newValue = planet.Y + planet.YVelocity * factor;
            if (newValue > PlanetaryHeight - planet.Height || newValue < 0)
            {
                planet.YVelocity = -planet.YVelocity;
            }
            else
            {
                planet.Y = newValue;
            }
        }
예제 #2
0
        /// <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);
            //spriteBatch.GraphicsDevice.Clear(Color.Black);

            planets = new Planet[planetCount];
            _planetarySystem = new PlanetarySystem(planets, _rnd, tracedSize.Width, tracedSize.Height);

            for (int i = 0; i < planetCount; i++)
            {
                int ballWidth = _rnd.Next(GameConfig.MinWidth, GameConfig.MaxWidth);
                int ballHeight = ballWidth;
                planets[i] = new Planet(_rnd, GraphicsDevice, ballWidth, ballHeight);
            }
            _planetarySystem.Initialize();

            //spriteBatch

            // TODO: use this.Content to load your game content here
        }
예제 #3
0
 public PlanetarySystem(Planet[] planets, Random rnd, int planetaryWidth, int planetaryHeight)
 {
     PlanetaryWidth = planetaryWidth;
     PlanetaryHeight = planetaryHeight;
     _rnd = rnd;
     Planets = planets;
 }