public BallThrowBullet(IWorld mundo, GraphicFactory factory)
        {            
            this.factory = factory;
            _mundo = mundo;            
            {
                ///Register a function to be called when the the mouse is pressed
                InputPlaybleMouseBottom ip1 = new SimpleConcreteMouseBottomInputPlayable(StateKey.PRESS, EntityType.IOBJECT, MouseButtons.LeftButton, mousebuttonteste);
                mm0 = new BindMouseCommand(ip1, BindAction.ADD);
                CommandProcessor.getCommandProcessor().SendCommandAssyncronous(mm0);
            }            

        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Picking"/> class.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="pickingRayDistance">The picking ray distance.</param>
        public Picking(IScene owner, float pickingRayDistance = 500)
            : base(owner)
        {            
            leftButtonIntercept = rightButtonIntercept = noneButtonIntercept = CullNothing;
            this.pickingRayDistance = pickingRayDistance;
            world = owner.World;
            info = owner.GraphicInfo;

            {
                SimpleConcreteMouseBottomInputPlayable pbLeft = new SimpleConcreteMouseBottomInputPlayable(StateKey.PRESS, EntityType.COMPONENT, MouseButtons.LeftButton, MouseBottomLeft, InputMask.GPICKING);
                bmc1 = new BindMouseCommand(pbLeft, BindAction.ADD);
                CommandProcessor.getCommandProcessor().SendCommandAssyncronous(bmc1);
            }

            {
                SimpleConcreteMouseBottomInputPlayable pbRight = new SimpleConcreteMouseBottomInputPlayable(StateKey.PRESS, EntityType.COMPONENT, MouseButtons.RightButton, MouseBottomRight, InputMask.GPICKING);
                bmc2 = new BindMouseCommand(pbRight, BindAction.ADD);
                CommandProcessor.getCommandProcessor().SendCommandAssyncronous(bmc2);
            }
        }
        /// <summary>
        /// Called once to load content
        /// </summary>
        /// <param name="GraphicInfo"></param>
        /// <param name="factory"></param>
        /// <param name="contentManager"></param>
        protected override void LoadContent(PloobsEngine.Engine.GraphicInfo GraphicInfo, PloobsEngine.Engine.GraphicFactory factory, PloobsEngine.SceneControl.IContentManager contentManager)
        {
            ///load background texture
            tile = factory.GetTexture2D("Textures/tile");

            ///recover the physic world reference
            FarseerWorld fworld = this.World.PhysicWorld as FarseerWorld;
            
            ///Ground 1
            Vertices verts = PolygonTools.CreateRectangle(GraphicInfo.BackBufferWidth, 100);
            {
                IModelo2D model = new SpriteFarseer(factory, verts, Color.Red);
                Basic2DTextureMaterial mat = new Basic2DTextureMaterial();
                FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Static);
                I2DObject o = new I2DObject(fs, mat, model);
                ///the origin of the created object will be in the center of it, this mean: if we draw it, the center of mass of it will be on the midle of the screen
                ///We need to translate it a bit down                
                o.PhysicObject.Position = new Vector2(0, 250);
                this.World.AddObject(o);
            }

            ///Ground 2
            verts = PolygonTools.CreateRectangle(GraphicInfo.BackBufferWidth, 100);
            {
                IModelo2D model = new SpriteFarseer(factory, verts, Color.Green);
                Basic2DTextureMaterial mat = new Basic2DTextureMaterial();
                FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Static);
                I2DObject o = new I2DObject(fs, mat, model);
                ///the origin of the created object will be in the center of it, this mean: if we draw it, the center of mass of it will be on the midle of the screen
                ///We need to translate it a bit down                
                o.PhysicObject.Position = new Vector2(GraphicInfo.BackBufferWidth, 250);
                this.World.AddObject(o);
            }

            ///Ground 3
            verts = PolygonTools.CreateRectangle(GraphicInfo.BackBufferWidth, 100);
            {
                IModelo2D model = new SpriteFarseer(factory, verts, Color.Yellow);
                Basic2DTextureMaterial mat = new Basic2DTextureMaterial();
                FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Static);
                I2DObject o = new I2DObject(fs, mat, model);
                ///the origin of the created object will be in the center of it, this mean: if we draw it, the center of mass of it will be on the midle of the screen
                ///We need to translate it a bit down                
                o.PhysicObject.Position = new Vector2(GraphicInfo.BackBufferWidth * 2, 250);
                this.World.AddObject(o);
            }

            ///Support 
            verts = PolygonTools.CreateRectangle(50, 200);
            {
                IModelo2D model = new SpriteFarseer(factory, verts, Color.Yellow);
                Basic2DTextureMaterial mat = new Basic2DTextureMaterial();
                FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Static);
                I2DObject o = new I2DObject(fs, mat, model);
                ///the origin of the created object will be in the center of it, this mean: if we draw it, the center of mass of it will be on the midle of the screen
                ///We need to translate it a bit down                
                o.PhysicObject.Position = new Vector2(0, 100);
                this.World.AddObject(o);
            }

            ///target 1
            verts = PolygonTools.CreateRectangle(50, 200);
            {
                IModelo2D model = new SpriteFarseer(factory, verts, Color.Green);
                Basic2DTextureMaterial mat = new Basic2DTextureMaterial();
                FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Dynamic);
                I2DObject o = new I2DObject(fs, mat, model);
                ///the origin of the created object will be in the center of it, this mean: if we draw it, the center of mass of it will be on the midle of the screen
                ///We need to translate it a bit down                
                o.PhysicObject.Position = new Vector2(GraphicInfo.BackBufferWidth * 1.5f, 100);
                this.World.AddObject(o);
            }

            ///target 2
            verts = PolygonTools.CreateRectangle(50, 200);
            {
                IModelo2D model = new SpriteFarseer(factory, verts, Color.Green);
                Basic2DTextureMaterial mat = new Basic2DTextureMaterial();
                FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Dynamic);
                I2DObject o = new I2DObject(fs, mat, model);
                ///the origin of the created object will be in the center of it, this mean: if we draw it, the center of mass of it will be on the midle of the screen
                ///We need to translate it a bit down                
                o.PhysicObject.Position = new Vector2(GraphicInfo.BackBufferWidth * 1.6f, 100);
                this.World.AddObject(o);
            }

            ///target 3
            verts = PolygonTools.CreateRectangle(200, 50);
            {
                IModelo2D model = new SpriteFarseer(factory, verts, Color.Green);
                Basic2DTextureMaterial mat = new Basic2DTextureMaterial();
                FarseerObject fs = new FarseerObject(fworld, model, 1, BodyType.Dynamic);
                I2DObject o = new I2DObject(fs, mat, model);
                ///the origin of the created object will be in the center of it, this mean: if we draw it, the center of mass of it will be on the midle of the screen
                ///We need to translate it a bit down                
                o.PhysicObject.Position = new Vector2(GraphicInfo.BackBufferWidth * 1.55f, -100);
                this.World.AddObject(o);
            }

            ///objective
            ///from texture
            {
                Texture2D tex = factory.GetTexture2D("Textures//goo");
                tex = factory.GetScaledTexture(tex,new Vector2(2));
                IModelo2D model = new SpriteFarseer(tex);
                Basic2DTextureMaterial mat = new Basic2DTextureMaterial();
                FarseerObject fs = new FarseerObject(fworld, model);                
                goo = new I2DObject(fs, mat, model);
                goo.PhysicObject.Position = new Vector2(GraphicInfo.BackBufferWidth * 1.55f, -175);
                this.World.AddObject(goo);
            }

            ///Ball
            CircleShape circle = new CircleShape(50, 1);
            {
                IModelo2D model = new SpriteFarseer(factory, circle, Color.Orange);
                Basic2DTextureMaterial mat = new Basic2DTextureMaterial();
                FarseerObject fs = new FarseerObject(fworld, model);
                ball = new I2DObject(fs, mat, model);
                ball.PhysicObject.Position = new Vector2(0, -25);
                ball.OnUpdate += new PloobsEngine.SceneControl._2DScene.OnUpdate(ball_OnUpdate);
                this.World.AddObject(ball);
            }

            SimpleConcreteMouseBottomInputPlayable SimpleConcreteMouseBottomInputPlayable1 = new SimpleConcreteMouseBottomInputPlayable(StateKey.PRESS, EntityType.TOOLS, PloobsEngine.Input.MouseButtons.LeftButton,
                 (sample) =>
                 {
                     mousepressed = true;
                 }
             );
            this.BindInput(SimpleConcreteMouseBottomInputPlayable1);


            SimpleConcreteMouseBottomInputPlayable SimpleConcreteMouseBottomInputPlayable = null;
            SimpleConcreteMouseBottomInputPlayable = new SimpleConcreteMouseBottomInputPlayable(StateKey.RELEASE, EntityType.TOOLS, PloobsEngine.Input.MouseButtons.LeftButton,
                 (sample) =>
                 {
                     mousepressed = false;
                     lines.isEnabled = false;
                     fired = true;

                     Vector2 mpos = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
                     Vector2 wpos = this.World.Camera2D.ConvertScreenToWorld(mpos);
                     Vector2 force = (ball.PhysicObject.Position - wpos) * 30;
                     ball.PhysicObject.ApplyForce(force);
                     this.RemoveInputBinding(SimpleConcreteMouseBottomInputPlayable);
                     this.RemoveInputBinding(SimpleConcreteMouseBottomInputPlayable1);

                     (this.World.Camera2D as Camera2D).TrackingBody = ball;                     
                 }
             );
            this.BindInput(SimpleConcreteMouseBottomInputPlayable);

            
            ///the basic ortographic 2D camera
            this.World.Camera2D = new Camera2D(GraphicInfo);
            base.LoadContent(GraphicInfo, factory, contentManager);

            Primitive2DDraw.Add2DPrimitive(lines);
        }