예제 #1
0
        public void TestCollisionWithWallBounce()
        {
            //float YPosition1 = LetCharacterFall(StartPosition: new Vector2(200, 200), FallingSteps: 5, FPSCount: 50);

            _gameTime = NewGameTime(144);

            _wall = new Sprite();
            _wall.Position = new Vector2(10, 100 + 80);
            _wall.Rect = new Rectangle((int)_wall.Position.X, (int)_wall.Position.Y, 100, 20);
            _wall.Color = Color.White;
            _wall.Update(_gameTime);

            _jucko = new Character();
            _jucko.Position = new Vector2(20, 0);
            _jucko.Rect = new Rectangle((int)_jucko.Position.X, (int)_jucko.Position.Y, 30, 90);
            _jucko.Color = Color.Red;
            for (int updateGravity = 0; updateGravity < 50; updateGravity++) {
                _jucko.Update(_gameTime);
            }

            Rectangle overlap = Rectangle.Intersect(_jucko.Rect, _wall.Rect);
            if (!overlap.IsEmpty) {
                _jucko.CollisionWith(_wall, overlap);
            }

            for (int updateBounce = 0; updateBounce < 50; updateBounce++) {
                _jucko.Update(_gameTime);
            }

            Assert.AreEqual(18, _jucko.Position.Y);
        }
예제 #2
0
        public ParticleBehaviourNormal(string Texture, Vector2 Position, int HowMany, float Radius, float LifeTime, Color Color)
        {
            _particles = new List<ParticleData>();

            Vector2 _tmpPosition;

            ISprite p;
            _randomizer = new Random();

            for (int i = 0; i < HowMany; i++) {
                double radius = Math.Sqrt(_randomizer.NextDouble()) * Radius;
                double angle = _randomizer.NextDouble() * Math.PI * 2;

                _tmpPosition.X = Position.X + (float)(radius * Math.Cos(angle));
                _tmpPosition.Y = Position.Y + (float)(radius * Math.Sin(angle));

                p = new Sprite();
                p.Position = _tmpPosition;
                p.Texture = Texture;
                //p.RotationOrigin = new Vector2(allTextures[Texture].Width / 2, allTextures[Texture].Height / 2);
                //p.Rect = new Rectangle((int)p.Position.X, (int)p.Position.Y, allTextures[Texture].Width, allTextures[Texture].Height);

                p.RotationOrigin = new Vector2(0, 0);
                p.Rect = new Rectangle(0, 0, 30, 30);

                p.Color = Color;
                _particles.Add(new ParticleData(p, (float)(LifeTime * _randomizer.NextDouble())));

            }
        }
예제 #3
0
        public void TestCollisionWithWall()
        {
            _gameTime = NewGameTime(144);

            _wall = new Sprite();
            _wall.Position = new Vector2(10, 100+80);
            _wall.Rect = new Rectangle((int)_wall.Position.X, (int)_wall.Position.Y, 100, 20);

            _jucko = new Character();
            _jucko.Position = new Vector2(20, 100);
            _jucko.Rect = new Rectangle((int)_jucko.Position.X, (int)_jucko.Position.Y, 30, 90);

            _jucko.Update(_gameTime);
            _wall.Update(_gameTime);

            for (int updateGravity = 0; updateGravity < 50; updateGravity++) {
                _jucko.Update(_gameTime);

                Rectangle overlap = Rectangle.Intersect(_jucko.Rect, _wall.Rect);
                if (!overlap.IsEmpty) {
                    _jucko.CollisionWith(_wall, overlap);
                }
            }

            Assert.AreEqual(90, _jucko.Position.Y);
        }