Example #1
0
 public KeyboardController(GUIElement input, Dictionary<Keys, int> keyMapping)
 {
     input.KeyDown += new KeyEventHandler(input_KeyDown);
     input.KeyPressDown += new KeyEventHandler(input_KeyPressDown);
     input.KeyUp += new KeyEventHandler(input_KeyUp);
     KeyMapping = keyMapping;
 }
Example #2
0
 void input_KeyUp(GUIElement sender, KeyEventArgs e)
 {
     foreach (Keys key in e.InterestingKeys)
         if (KeyMapping.ContainsKey(key))
         {
             Fire(KeyControlDisengaged, KeyMapping[key]);
         }
 }
Example #3
0
 void frame_MouseDown(GUIElement sender, MouseEventArgs e)
 {
 }
Example #4
0
 void frame_MouseClick(GUIElement sender, MouseEventArgs e)
 {
     if(e.isClicked(MouseButtons.Left))
     {
         var rad = 25;
         PhysicsManager.AddParticleSystems(ParticleSystemFactory.GetDirtyBomb(e.CurrentPosition, rad));
         PhysicsManager.AddInstantaneousForceField(new InstantaneousForceField(e.CurrentPosition, rad, DefaultForces.GenerateExplosiveField(rad, 1)));
     }
     if (e.isClicked(MouseButtons.Right))
     {
     }
     if (e.isClicked(MouseButtons.Middle))
     {
     }
 }
Example #5
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;
            }
        }
Example #6
0
 void frame_MouseOver(GUIElement sender, MouseEventArgs e)
 {
     ((IRigidBody)ActiveMap.Player).Rotation = MathUtils.GetAngle(e.CurrentPosition - ((IRigidBody)ActiveMap.Player).Position);
 }
Example #7
0
        void frame_MouseClick(GUIElement sender, MouseEventArgs e)
        {
            var player = (Player)ActiveMap.Player;
            var mdir = Vector2.Normalize(e.CurrentPosition - player.Position);
            var launchPort = player.Position + mdir * (player.Radius + 5); //launch stuff from slightly in front of player
            float launchVel = 300f + player.Velocity.Length();

            var carrier = new DeviceTransporter(launchPort, 15);
            carrier.Velocity = launchVel * mdir;
            SpawnObject<Actor>(carrier);

            if (e.isClicked(MouseButtons.Left))
            {
                var c = new Charge(50, 15);
                ActiveMap.AddObject(c);
                carrier.AddDevice(c);
            }
            if (e.isClicked(MouseButtons.Right))
            {
                var s = new Sensor(60f);
                ActiveMap.AddObject(s);
                carrier.AddDevice(s);
            }
        }
Example #8
0
 void frame_KeyPressDown(GUIElement sender, KeyEventArgs e)
 {
     switch (e.InterestingKeys[0])
     {
         case Keys.Space:
             var objclone = new List<WorldObject>(ActiveMap.WorldObjects);
             foreach (var obj in objclone)
             {
                 if (obj is DeviceCarrierActor)
                 {
                     var devs = ((DeviceCarrierActor)obj).GetDevices();
                     foreach (var d in devs)
                     {
                         if (d is Charge) ((Charge)d).Detonate();
                     }
                 }
             }
             break;
     }
 }
Example #9
0
        void frame_MouseClick(GUIElement sender, MouseEventArgs e)
        {
            if (e.isClicked(MouseButtons.Right))
            {
                var pfire = new ParticleSystem(new Vector2(e.CurrentMouseState.X, e.CurrentMouseState.Y), 15, 100, 1, 10, 1, 3f, fire);
                pfire.InitVelocities(0, 110);
                PE.AddParticleSystem(pfire);

                var psmoke = new ParticleSystem(new Vector2(e.CurrentMouseState.X, e.CurrentMouseState.Y), 25, 100, 2f, 20, 1, 1f, smoke);
                psmoke.InitVelocities(0, 200);
                PE.AddParticleSystem(psmoke);
            }
            else if (e.isClicked(MouseButtons.Left))
            {
                PE.AddParticleSystems(ParticleSystemFactory.GetDirtyBomb(new Vector2(e.CurrentMouseState.X, e.CurrentMouseState.Y), 50));
            }
        }
Example #10
0
 void KeyUp(GUIElement sender, KeyEventArgs e)
 {
     if (e.InterestingKeys.Contains<Keys>(Keys.Escape))
         this.Exit();
 }
Example #11
0
 void frame_KeyPressDown(GUIElement sender, KeyEventArgs e)
 {
     if (e.InterestingKeys[0] == Keys.OemPeriod)
         draw = !draw;
 }
Example #12
0
 // Mouse Controls
 void mouseController_MouseOver(GUIElement sender, MouseEventArgs e)
 {
     ((IRigidBody)ActiveMap.Player).Rotation =
         MathUtils.GetAngle(((IRigidBody)ActiveMap.Player).Position - e.CurrentPosition);
 }
Example #13
0
        void game_MouseClick(GUIElement sender, MouseEventArgs e)
        {
            if (e.isClicked(MouseButtons.Left))
            {
                //// This code sets of a charge by clicking on the asteroid that contains it, so multiple chargs can be set
                //// Good for debugging
                //activeCharge = null;
                //var bodies =
                //    PhysicsManager.QTbodies.Query(
                //        new Region(e.CurrentPosition.X - Asteroid.MaxRadius, e.CurrentPosition.X + Asteroid.MaxRadius,
                //            e.CurrentPosition.Y - Asteroid.MaxRadius, e.CurrentPosition.Y + Asteroid.MaxRadius));
                //foreach (IRigidBody body in bodies)
                //    if (body is Asteroid)
                //    {
                //        var astr = (Asteroid)body;
                //        if (MathUtils.Distance(astr.Position, e.CurrentPosition) < astr.Radius)
                //        {
                //            activeCharge = (Charge)astr.GetDevices().FirstOrDefault<Device>(x => x is Charge);
                //            break;
                //        }
                //    }
                //// End of above code block

                if (activeCharge == null)
                {
                    activeCharge = PlayerProfile.ReleaseCharge(0);
                    if (activeCharge == null)
                        this.Write("No Charges Left!");
                    else
                    {
                        releaseItem(activeCharge);
                        this.Write("Charges Left: {0}", PlayerProfile.ChargesLeft);
                    }
                }
                else
                {
                    activeCharge.Detonate();
                    activeCharge = null;
                }
            }
            else if (e.isClicked(MouseButtons.Right))
            {
                var sensor = PlayerProfile.ReleaseSensor(0);
                if (sensor == null)
                    this.Write("No Sensors Left!");
                else
                {
                    releaseItem(sensor);
                    this.Write("Sensors Left: {0}", PlayerProfile.SensorsLeft);
                }
            }
        }
Example #14
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);
                    }

                }
            }
        }
Example #15
0
 /// <summary>
 /// Parent can only be set once!
 /// </summary>
 public void setParent(GUIElement parent)
 {
     if (Parent != null)
         throw new Exception("Control already has a parent!");
     Parent = parent;
 }
Example #16
0
 void frame_KeyUp(GUIElement sender, KeyEventArgs e)
 {
     if (e.InterestingKeys.Contains<Keys>(Keys.Escape))
         ((UIFrame)sender).Close();
         // or: UIManager.ActiveFrame.Close()
 }
Example #17
0
 void BlueFrame_KeyUp(GUIElement sender, KeyEventArgs e)
 {
     if (e.InterestingKeys.Contains<Keys>(Keys.Escape))
         this.Close();
 }