コード例 #1
0
        public Ball(WorldSpacePosition position, float startingSpeed = 0.05f, float size = 0.25f, SpawnDirectionPreference spawnDirectionPreference = SpawnDirectionPreference.None)
        {
            Transform.Position = position;

            var ballShape = new Rectangle(new Vector2(-size, -size), new Vector2(size, size));

            physicsObject = new Physics.PhysicsObject(Transform, @static: false, ballShape);
            sprite        = new Rendering.TextSprite(Transform);

            var   rng       = new Random();
            float direction = (float)spawnDirectionPreference;

            if (spawnDirectionPreference is SpawnDirectionPreference.None)
            {
                float randomInfluance = (float)rng.NextDouble();
                if (randomInfluance < 0.5)
                {
                    direction = -1f;
                }
                else
                {
                    direction = 1f;
                }
            }

            physicsObject.Velocity           = new Vector2(direction * startingSpeed, (float)rng.NextDouble() * (startingSpeed / 3f));
            physicsObject.CollisionDetected += OnCollision;
        }
コード例 #2
0
        public Wall(WorldSpacePosition position, uint width, uint height)
        {
            if (width == 0 || height == 0)
            {
                throw new ArgumentException("Walls cannot have 0 thickness!");
            }

            Transform.Position = position;
            Width  = width;
            Height = height;

            var wallShape = new Rectangle(new Vector2(position.X, position.Y - height), new Vector2(width, height));

            physicsObject = new Physics.PhysicsObject(Transform, @static: true, wallShape);

            sprite = new Rendering.TextSprite(Transform);
            RefreshSprite();
        }