Beispiel #1
0
        public override void Load()
        {
            // Extract Global Data
            Game        currentGame = Globals.Data["Game"];
            SpriteBatch spriteBatch = Globals.Data["SpriteBatch"];
            Size        winSize     = DefaultSettings.Settings["WindowSize"];

            // Initialize
            currentGame.IsMouseVisible = true;

            PE = new PhysicsEngine(new Region(0, (float)winSize.Width, 0, (float)winSize.Height), 10);

            var w0 = new VertWallBody(new Vector2(0, winSize.Height / 2), winSize.Height);
            var w1 = new VertWallBody(new Vector2(winSize.Width, winSize.Height / 2), winSize.Height);

            var w2 = new HorizWallBody(new Vector2(winSize.Width / 2, 0), winSize.Width);
            var w3 = new HorizWallBody(new Vector2(winSize.Width / 2, winSize.Height), winSize.Width);

            PE.MapBodies.Add(w0);
            PE.MapBodies.Add(w1);
            PE.MapBodies.Add(w2);
            PE.MapBodies.Add(w3);


            var c0 = new CircleBody(30, 300, new Vector2(600, winSize.Height / 2));

            c0.Velocity = -1000 * Vector2.UnitX;
            PE.ActiveBodies.Add(c0);


            Random rand = new Random();

            int nx  = 40;
            int ny  = 40;
            var rad = 4f;
            var buf = 0f;
            var pos = new Vector2(winSize.Width / 2 - nx * (2f * rad + buf) / 2f, winSize.Height / 2 - ny * (2f * rad + buf) / 2f);

            for (int xi = 0; xi < nx; xi++)
            {
                for (int yi = 0; yi < ny; yi++)
                {
                    var cent = pos + new Vector2((2f * rad + buf) * xi, (2f * rad + buf) * yi);
                    var ball = new CircleBody(rad, rad, cent);
                    PE.ActiveBodies.Add(ball);
                }
            }

            // Load Content
            GraphicsUtils.Load(spriteBatch,
                               (Texture2D)ContentRepository.Repository["Pixel"],
                               (Texture2D)ContentRepository.Repository["Ball"]);

            // Setup UI
            _uiEngine = new UIEngine();
            _uiEngine.AddAndLoad(new UIFrames.BasicFrame());
        }
Beispiel #2
0
        public override void Load()
        {
            // Extract Global Data
            Game        currentGame = Globals.Data["Game"];
            SpriteBatch spriteBatch = Globals.Data["SpriteBatch"];


            // Initialize
            currentGame.IsMouseVisible = true;


            PE = new PhysicsEngine(new Region(0, (float)winSize.Width, 0, (float)winSize.Height), 10);
            //PE.AddUniversalForce(DefaultForces.Gravity);
            //PE.AddUniversalForce(DefaultForces.Drag);


            var w0 = new VertWallBody(new Vector2(0, winSize.Height / 2), winSize.Height);
            var w1 = new VertWallBody(new Vector2(winSize.Width, winSize.Height / 2), winSize.Height);

            var w2 = new HorizWallBody(new Vector2(winSize.Width / 2, 0), winSize.Width);
            var w3 = new HorizWallBody(new Vector2(winSize.Width / 2, winSize.Height), winSize.Width);

            PE.MapBodies.Add(w0);
            PE.MapBodies.Add(w1);
            PE.MapBodies.Add(w2);
            PE.MapBodies.Add(w3);


            //var c0 = new CircleBody(30, 300, new Vector2(600, winSize.Height / 2));
            //c0.Velocity = -1000 * Vector2.UnitX;
            //PE.ActiveBodies.Add(c0);

            //PE.AddBoundForceField(new BoundForceField(c0, 50, DefaultForces.StrongAttractor));


            int nx  = 40;
            int ny  = 20;
            var rad = 4f;
            var buf = 0f;
            var pos = new Vector2(winSize.Width / 2 - nx * (2f * rad + buf) / 2f, winSize.Height / 2 - ny * (2f * rad + buf) / 2f);

            for (int xi = 0; xi < nx; xi++)
            {
                for (int yi = 0; yi < ny; yi++)
                {
                    var cent = pos + new Vector2((2f * rad + buf) * xi, (2f * rad + buf) * yi);
                    var ball = new CircleBody(rad, rad, cent);
                    PE.ActiveBodies.Add(ball);
                }
            }

            printInstr();
            printStat();

            // Load Content
            GraphicsUtils.Load(spriteBatch,
                               ContentRepository.Repository["Pixel"],
                               ContentRepository.Repository["Ball"]);

            // Setup UI
            _uiEngine = new UIEngine();
            var frame = new UIFrames.BasicFrame();

            frame.MouseDown    += new MouseEventHandler(frame_MouseDown);
            frame.MouseClick   += new MouseEventHandler(frame_MouseClick);
            frame.MouseOver    += new MouseEventHandler(frame_MouseOver);
            frame.KeyPressDown += new KeyEventHandler(frame_KeyPressDown);
            _uiEngine.AddAndLoad(frame);
        }
Beispiel #3
0
        void frame_KeyPressDown(Element sender, KeyEventArgs e)
        {
            switch (e.InterestingKeys[0])
            {
            case Keys.F:
                factive = !factive;

                if (factive)
                {
                    foreach (var ball in PE.ActiveBodies)
                    {
                        if (rand.Next(5) == 0)
                        {
                            PE.AddBoundForceField(new BoundForceField(ball, 20, DefaultForces.StrongAttractor));
                            //PE.AddBoundForceField(new BoundForceField(ball, 20, DefaultForces.WeakAttractor));
                        }
                        if (rand.Next(50) == 0)
                        {
                            //PE.AddBoundForceField(new BoundForceField(ball, 100, DefaultForces.StrongAttractor));
                            //PE.AddBoundForceField(new BoundForceField(ball, 20, DefaultForces.WeakAttractor));
                        }
                    }
                }
                else
                {
                    PE.bffields.Clear();
                }
                break;

            case Keys.L:
                var c0 = new CircleBody(30, 300, new Vector2((new System.Random()).Next(0, (int)winSize.Width - 60), winSize.Height));
                c0.Velocity = -1000 * Vector2.UnitY;
                PE.ActiveBodies.Add(c0);
                break;


            case Keys.D:
                dactive = !dactive;
                if (dactive)
                {
                    PE.AddUniversalForce(DefaultForces.LinearDrag);
                }
                else
                {
                    PE.RemoveUniversalForce(DefaultForces.LinearDrag);
                }
                break;

            case Keys.G:
                gactive = !gactive;
                if (gactive)
                {
                    PE.AddUniversalForce(DefaultForces.Gravity);
                }
                else
                {
                    PE.RemoveUniversalForce(DefaultForces.Gravity);
                }
                break;

            default:
                break;
            }

            printStat();
        }