Ejemplo n.º 1
0
        private bool OnStart()
        {
            // Create layer that can hold our renderable elements.
            layer = Layers.CreateDynamic("base");

            var andy = ResourceManager.Load <Texture2D>("andy");

            var autoscales = new Sprite(300.0f, 300.0f, andy);

            layer.Add(autoscales);

            c      = new Circle(400.0f, 400.0f, 128.0f, Circle.RoughCircle);
            c.Fill = Color.White;
            //c.Texture = ResourceManager.Load<Texture2D>("andy");
            c.BorderThickness = 32.0f;
            layer.Add(c);

            // Create triangles.
            for (var i = 0; i < 2; i++)
            {
                var triangle = new Triangle(Vector2.Zero, new Vector2(128.0f));
                triangle.BorderThickness = 8.0f;
                triangle.BorderFill      = Color.Blue;
                triangle.Fill            = Color.White;
                triangle.Texture         = andy;

                var transform = triangle.Transform;
                transform.position.x = 200.0f + 128.0f * i;
                transform.position.y = 200.0f;
                triangle.Transform   = transform;

                layer.Add(triangle);
            }

            // Test sprite..
            var manscales = new Sprite(new Vector2(300.0f), new Vector2(128.0f), andy);

            layer.Add(manscales);

            // Create 3 rectangles.
            for (var i = 0; i < 3; i++)
            {
                layer.Add(new Rectangle(100 + 48.0f * i, 100, 32.0f, 32.0f)
                {
                    BorderThickness = 8.0f
                });
            }

            // Create particle emitter.
            ParticleGenerator gen = ParticleGenerator.Empty();

            gen.flags |= GeneratorFlags.VaryingVelocity;
            gen.flags |= GeneratorFlags.VaryingDecayTime;
            gen.flags |= GeneratorFlags.VaryingSpawnLocation;
            gen.flags |= GeneratorFlags.VaryingAngularVelocity;
            gen.flags |= GeneratorFlags.VaryingScale;
            gen.flags |= GeneratorFlags.UseScaleVelocity;

            gen.startVelocity    = new Vector2(-0.325f, -0.25f);
            gen.velocityVariance = new Vector2(0.625f, 0.25f);

            gen.baseDecayTime     = 550.0f;
            gen.decayTimeVariance = 350.0f;

            gen.spawnLocationMinOffset = new Vector2(-32.0f, 0.0f);
            gen.spawnLocationMaxOffset = new Vector2(32.0f, 0.0f);

            gen.baseAngularVelocity     = 0.001f;
            gen.angularVelocityVariance = 0.01f;

            gen.baseScale     = new Vector2(1.0f, 1.0f);
            gen.scaleVariance = new Vector2(0.5f, 0.5f);

            gen.baseScaleVelocity     = new Vector2(0.001f, 0.001f);
            gen.scaleVelocityVariance = new Vector2(0.005f, 0.005f);

            gen.framesToFade         = 16;
            gen.framesToFadeVariance = 4;

            // TODO: paska osuu tuulettimeen
            var x = 1280.0f / 2.0f;
            var y = 600.0f;

            ParticleEmitter emitter = new ParticleEmitter(gen, andy, new Vector2(x, y), 1024);

            layer.Add(emitter);

            var vars = CVars.GetCVars();

            Console.WriteLine("CVARS C: {0}", vars.Length);

            foreach (var cvar in vars)
            {
                Console.WriteLine(cvar.ToString() + "\n");
            }

            return(true);
        }
Ejemplo n.º 2
0
        private bool OnStart()
        {
            var backbufferWidth  = (float)GraphicsDevice.BackbufferWidth();
            var backbufferHeight = (float)GraphicsDevice.BackbufferHeight();

            // Init area.
            var borderThickness = 32.0f;

            var area = new Rectf(borderThickness,
                                 borderThickness,
                                 backbufferWidth - borderThickness * 2.0f,
                                 backbufferHeight - borderThickness);

            // Create player.
            var playerSize = new Vector2(128.0f, 32.0f);

            var playerPosition = new Vector2(area.Right - area.width / 2.0f,
                                             area.Bottom - borderThickness * 4.0f);

            player           = new Player(playerPosition, playerSize, area);
            player.Rect.Fill = Color.Green;

            // Create borders.
            var borderElements = new Rectangle[4];

            // Right.
            borderElements[0] = new Rectangle(new Vector2(backbufferWidth - borderThickness / 2.0f, backbufferHeight / 2.0f),
                                              new Vector2(borderThickness, backbufferHeight));

            // Left.
            borderElements[1] = new Rectangle(new Vector2(borderThickness / 2.0f, backbufferHeight / 2.0f),
                                              new Vector2(borderThickness, backbufferHeight));

            // Top.
            borderElements[2] = new Rectangle(new Vector2(backbufferWidth / 2.0f, borderThickness / 2.0f),
                                              new Vector2(backbufferWidth - borderThickness, borderThickness));

            // Bottom.
            borderElements[3] = new Rectangle(new Vector2(backbufferWidth / 2.0f, backbufferHeight - borderThickness / 2.0f),
                                              new Vector2(backbufferWidth - borderThickness, borderThickness));

            // Create ball.
            const float radius = 32.0f;

            var playerTransform = player.Rect.Transform;

            ball = new Ball(new Vector2(playerTransform.position.x + player.Rect.LocalBounds.width / 2.0f,
                                        playerTransform.position.y - player.Rect.LocalBounds.height * 2.0f), radius,
                            new Rectf[] { borderElements[0].GlobalBounds, borderElements[1].GlobalBounds, borderElements[2].GlobalBounds, borderElements[3].GlobalBounds });

            ball.Circle.Fill       = Color.Green;
            ball.Circle.BorderFill = new Color(125, 125, 0, 255);

            // Create 8x8 grid of bricks.
            bricks = new List <Rectangle>();

            // Offset.
            const float rows    = 8.0f;
            const float columns = 8.0f;
            const float boff    = 64.0f;

            // Start x and y.
            var bsx = area.Left + boff;
            var bsy = area.Top + boff;

            // Width and height.
            var bw = (area.width - boff * 2.0f) / columns;
            var bh = (area.height / 2.0f) / rows;

            for (var h = 0; h < 8; h++)
            {
                for (var w = 0; w < 8; w++)
                {
                    var x = bsx + w * bw;
                    var y = bsy + h * bh;

                    var brick = new Rectangle(x, y, bw, bh);

                    var color = new Color((float)rand.NextDouble(),
                                          (float)rand.NextDouble(),
                                          (float)rand.NextDouble(),
                                          (float)rand.NextDouble());

                    var transform = brick.Transform;

                    transform.origin = Vector3.Zero;

                    brick.Transform = transform;
                    brick.Fill      = color;

                    bricks.Add(brick);
                }
            }

            // Create layer and add elements.
            var layer = Layers.CreateDynamic("bottom");

            layer.Add(player.Rect);
            layer.Add(ball.Circle);

            foreach (var element in borderElements)
            {
                layer.Add(element);
            }
            foreach (var element in bricks)
            {
                layer.Add(element);
            }

            return(true);
        }