示例#1
0
        //: base(game.width, game.height)
        public Level(string filename, NeonArkanoidGame game)
        {
            width = game.width;
            _height = game.height;

            SetBackground();
            SetPolyField();
            SetTextBoxSettings();
            BoundaryCreator();
            SetSounds();

            _gameEnded = false;
            _levelName = filename.Remove(filename.Length - 4);
            Console.WriteLine(_levelName);
            _game = game;

            var tmxParser = new TMXParser();
            _map = tmxParser.Parse(filename);

            for (var i = 0; i < _map.ObjectGroup.Length; i++)
            {
                if (_map.ObjectGroup[i].Name.ToLower() == "polygons" || _map.ObjectGroup[i].Name.ToLower() == "polygon")
                {
                    _polyList = new List<Polygon>();
                    CreatePolygons(_map.ObjectGroup[i]);
                }
            }
            foreach (var polygon in _polyList)
            {
                AddChild(polygon);
            }

            AddBouncerBalls();
            AddBumpers();

            _ball = new Ball(30, new AnimationSprite(UtilStrings.SpritesPlayer + "ball.png", 5, 1), new Vec2(200, 200));
            AddChild(_ball);
            _stuckToPaddle = true;

            _paddle = new Paddle(this, new Vec2(game.width/2, game.height - 100));
            AddChild(_paddle);
            Redraw();
        }
示例#2
0
 /// <summary>
 ///     Handles Collisions and reflection between the ball and a given ball.
 /// </summary>
 /// <param name="ball">
 ///     Is a ball that the ball will be checked against.
 /// </param>
 /// <param name="reflectionStrength">
 ///     Is the amount of reflection that will be given to the ball,
 ///     1f is a perfect bounce, 0f makes the ball not bounce at all.
 /// </param>
 /// <returns>Returns true when a collision was actually detected</returns>
 private bool BallCollisionTest(Ball ball, float reflectionStrength)
 {
     if (_ball.Position.Clone().Subtract(ball.Position).Length() <= _ball.radius + ball.radius)
     {
         var delta = _ball.Position.Clone().Subtract(ball.Position);
         var distToCap = delta.Clone().Length();
         var deltaNormalized = delta.Clone().Normalize();
         _ball.Position.SetVec(
             _ball.Position.Add(deltaNormalized.Clone().Scale(-distToCap + _ball.radius + ball.radius)));
         _ball.Velocity.Reflect(deltaNormalized, reflectionStrength);
         _ball.Step();
         return true;
     }
     return false;
 }