Exemplo n.º 1
0
        void frame_MouseOver(GUIElement sender, MouseEventArgs e)
        {
            ((IRigidBody)ActiveMap.Player).Rotation = MathUtils.GetAngle(e.CurrentPosition - ((IRigidBody)ActiveMap.Player).Position);

            if (e.isDown(MouseButtons.Right))
            {
                var rad = PhysicsManager.QTbodies.Query(Region.FromCircle(e.CurrentPosition, 10));
                foreach (var gr in rad)
                {
                    if (gr is InertRoid)
                    {
                        KillObject((Actor)gr);

                        var gra = (InertRoid)gr;
                        var br = new BombRoid(gra.Position, gra.Radius);
                        ActiveMap.AddObject(br);
                        PhysicsManager.ActiveBodies.Add(br);
                    }

                }
            }
        }
Exemplo n.º 2
0
        public override void Update(GameTime time)
        {
            if (!UIManager.Update(time))
                base.Exit();
            ActiveMap.UpdateDynamicObjects(time);
            PhysicsManager.Update(time.ElapsedGameTime.Milliseconds / 1000f);

            if (!time.IsRunningSlowly)
            {
                dint -= time.ElapsedGameTime.Milliseconds / 1000f;
                if (dint <= 0.0f)
                {
                    dynamic obj;
                    if (MathUtils.Rand.Next(0, 2) == 0)
                    {
                        obj = new BombRoid(new Vector2((float)MathUtils.Rand.Next(60, (int)winSize.Width - 60), (float)MathUtils.Rand.Next(60, (int)winSize.Height - 60)), MathUtils.Rand.Next(2, 10));
                    }
                    else
                    {
                        obj = new InertRoid(new Vector2((float)MathUtils.Rand.Next(60, (int)winSize.Width - 60), (float)MathUtils.Rand.Next(60, (int)winSize.Height - 60)), MathUtils.Rand.Next(2, 10));
                    }
                    obj.Velocity = 1000 * (float)MathUtils.Rand.NextDouble() * MathUtils.RandDirection();
                    PhysicsManager.ActiveBodies.Add(obj);
                    ActiveMap.AddObject(obj);

                    Console.WriteLine(PhysicsManager.ActiveBodies.Count.ToString() + " bodies");
                    dint = delay;
                }
            }
            else
            {
                Console.Write(PhysicsManager.ActiveBodies.Count.ToString() + " bodies     ");
                Console.WriteLine("SLOW - HIT PERIOD TO DISABLE GRFX");
                dint = 0.0f;
            }
        }
Exemplo n.º 3
0
        void frame_KeyPressDown(GUIElement sender, KeyEventArgs e)
        {
            switch (e.InterestingKeys[0])
            {
                case Keys.G:
                    gactive = !gactive;
                    if (gactive)
                        PhysicsManager.AddUniversalForce(DefaultForces.Gravity);
                    else
                        PhysicsManager.RemoveUniversalForce(DefaultForces.Gravity);
                    break;
                case Keys.X:
                    var br = new BombRoid(new Vector2((float)MathUtils.Rand.Next(60, (int)winSize.Width - 60), winSize.Height), 25);
                    br.Mass = 100;
                    br.Velocity = -1000 * Vector2.UnitY;
                    br.FuseTime = .1f;
                    ActiveMap.AddObject(br);
                    PhysicsManager.ActiveBodies.Add(br);
                    break;
                case Keys.C:
                    var gr = new InertRoid(new Vector2((float)MathUtils.Rand.Next(60, (int)winSize.Width - 60), winSize.Height), 25);
                    gr.Mass = 100;
                    gr.Velocity = -1000 * Vector2.UnitY;
                    ActiveMap.AddObject(gr);
                    PhysicsManager.ActiveBodies.Add(gr);
                    break;
                case Keys.OemPeriod:
                    draw = !draw;
                    break;

                case Keys.Space:

                    break;
            }
        }
Exemplo n.º 4
0
        public override void Reload()
        {
            var winSize = DefaultSettings.Settings["WindowSize"];
            PhysicsManager = new PhysicsEngine(new Region(0, (float)winSize.Width, 0, (float)winSize.Height), 10);

            PhysicsManager.AddUniversalForce(DefaultForces.LinearDrag);

            var world = new List<WorldObject>();
            ActiveMap = new Map(world);

            /*
             * Setup Map
             */

            int goodRoidNumber = 10;
            int badRoidNumber = 5;
            int bombRoidNumber = 5;

            int chargesAllowed = 5;
            int sensorsAllowed = 5;

            PlayerProfile = new PlayerProfile(1000, // Health
                badRoidNumber, goodRoidNumber); // Roids

            Random rand = new Random();

            var player = new Player(
                new Vector2((float)rand.NextDouble() * (winSize.Width - 50), (float)rand.NextDouble() * (winSize.Height - 50)),
                0f);
            player.GotHurt += new PlayerEventHandler(player_GotHurt);
            SpawnObject<Actor>(player);

            for (int i = 0; i < chargesAllowed; i++)
                PlayerProfile.AddCharge(new Charge(50, 15));

            for (int i = 0; i < sensorsAllowed; i++)
                PlayerProfile.AddSensor(new Sensor(60f));

            for (int i = 0; i < goodRoidNumber; i++)
            {
                var pos = new Vector2((float)MathUtils.Rand.Next(50, (int)winSize.Width - 50), (float)MathUtils.Rand.Next(50, (int)winSize.Height - 50));
                var rad = 15f + (float)MathUtils.Rand.NextDouble() * Asteroid.MaxRadius;
                var gr = new GoodRoid(pos, rad, 1000f, .1f, new Vector2((float)MathUtils.Rand.NextDouble() * 300, (float)MathUtils.Rand.NextDouble() * 300));
                gr.Destroyed += new WorldObjectEventHandler(goodRoid_Destroyed);
                SpawnObject<Actor>(gr);
            }

            for (int i = 0; i < badRoidNumber; i++)
            {
                var pos = new Vector2((float)MathUtils.Rand.Next(50, (int)winSize.Width - 50), (float)MathUtils.Rand.Next(50, (int)winSize.Height - 50));
                var rad = 15f + (float)MathUtils.Rand.NextDouble() * Asteroid.MaxRadius;
                var br = new BadRoid(pos, rad, 1000f, .1f, new Vector2((float)MathUtils.Rand.NextDouble()*300,(float)MathUtils.Rand.NextDouble()*300));
                br.Destroyed += new WorldObjectEventHandler(badRoid_Destroyed);
                SpawnObject<Actor>(br);
            }
            for (int i = 0; i < bombRoidNumber; i++)
            {
                var pos = new Vector2((float)MathUtils.Rand.Next(50, (int)winSize.Width - 50), (float)MathUtils.Rand.Next(50, (int)winSize.Height - 50));
                var rad = 15f + (float)MathUtils.Rand.NextDouble() * Asteroid.MaxRadius;
                var br = new BombRoid(pos, rad);
                SpawnObject<Actor>(br);

            }

            //
            //
            //

            // Walls -- invisible
            var w0 = new ROIDS.Sandbox.VertWallBody(new Vector2(0, winSize.Height / 2), winSize.Height);
            var w1 = new ROIDS.Sandbox.VertWallBody(new Vector2(winSize.Width, winSize.Height / 2), winSize.Height);

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

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

            this.Write("Health: {0}\nCharges: {1}\nSensors: {2}\nRoids to Blast: {3}",
                PlayerProfile.Health,
                PlayerProfile.ChargesLeft,
                PlayerProfile.SensorsLeft,
                PlayerProfile.RoidsToBlast);
        }