예제 #1
0
        public override void Init()
        {
            Content.ContentPath = "Data";

            scene = new Scene();
            scene.View = this;

            scene.Camera = new LookatCartesianCamera()
            {
                Lookat = new Vector3(size.Width / 2f, size.Height / 2f, 0),
                Position = new Vector3(10, 10, 10),
                FOV = 0.5f,
                ZFar = 100,
                AspectRatio = AspectRatio
            };

            viewport = new Graphics.GraphicsDevice.Viewport(Device9.Viewport);

            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)scene.Camera,
                InputHandler = new InteractiveSceneManager { Scene = scene },
            };

            renderer = new Graphics.Renderer.Renderer(Device9) { Scene = scene, StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9), Settings = new Graphics.Renderer.Settings { WaterEnable = false } };
            //renderer = new Graphics.DummyRenderer.Renderer { Scene = scene, StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9), Settings = new Graphics.Renderer.Settings { WaterEnable = false } };
            renderer.Initialize(this);

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Renderer = renderer,
                Scene = scene
            };
            sceneRendererConnector.Initialize();

            motionSimulation = new Common.Motion.Simulation();

            scene.EntityAdded += new Action<Entity>(scene_EntityAdded);
            scene.EntityRemoved += new Action<Entity>(scene_EntityRemoved);

            var sim = (Common.Motion.Simulation)motionSimulation;

            npcs = new List<Common.IMotion.INPC>();
            Vector2 startingPosition = new Vector2(size.Width / 2f, size.Height / 2f);
            CreateGround(true);
            scene.Add(controlledUnit = CreateUnit(startingPosition));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(2, -2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(-4, 2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(4, -2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(7, -1)), new Vector3(1, 1, 1.5f)));
            //scene.Add(CreateNPC(startingPosition + new Vector2(3, 3)));
            scene.Add(CreateNPC(startingPosition + new Vector2(3, -1)));
            scene.Add(CreateNPC(startingPosition + new Vector2(-5, 3)));
            scene.Add(CreateNPC(startingPosition + new Vector2(-2, 1)));
            Vector2 unitGroupStartingPosition = startingPosition + new Vector2(3, 3);
            for (int y = 0; y < 5; y++)
            {
                for (int x = 0; x < 5; x++)
                {
                    scene.Add(CreateNPC(unitGroupStartingPosition + new Vector2(x, y)));
                }
            }

            BulletCreation = (() =>
            {
                scene.Add(CreateBullet(controlledUnit.Translation + Vector3.UnitZ,
                    bulletSpeed,
                    controlledUnit.MotionObject.Rotation.Angle,
                    bulletAcceleration));
            });

            foreach (var npc in npcs)
                npc.Pursue(controlledUnit.MotionObject, 1f);
        }
예제 #2
0
        protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.KeyCode == System.Windows.Forms.Keys.D1)
            {
                bulletSpeed = 10.0f;
                bulletAcceleration = Vector3.Zero;
            }
            if (e.KeyCode == System.Windows.Forms.Keys.D2)
            {
                bulletSpeed = 5.0f;
                bulletAcceleration = new Vector3(0, 0, -9.82f);
            }
            if (e.KeyCode == System.Windows.Forms.Keys.D3)
            {
                bulletSpeed = 10.0f;
                bulletAcceleration = new Vector3(-3, -3, 0);
            }
            if (e.KeyCode == System.Windows.Forms.Keys.D4)
            {
                BulletCreation = (() =>
                    {
                        scene.Add(CreateBullet(controlledUnit.Translation + Vector3.UnitZ,
                            bulletSpeed,
                            controlledUnit.MotionObject.Rotation.Angle,
                            bulletAcceleration));
                    });
            }
            if (e.KeyCode == System.Windows.Forms.Keys.D5)
            {
                BulletCreation = (() =>
                    {
                        for (float i = -(float)Math.PI / 4f; i <= (float)Math.PI / 4f; i += (float)Math.PI / 8f)
                            scene.Add(CreateBullet(controlledUnit.Translation + Vector3.UnitZ,
                                bulletSpeed,
                                controlledUnit.MotionObject.Rotation.Angle + i,
                                bulletAcceleration));
                    });
            }
            if (e.KeyCode == System.Windows.Forms.Keys.D6)
            {
                BulletCreation = (() =>
                    {
                        for (float i = 0.0f; i < 2f * (float)Math.PI; i += (float)Math.PI / 8f)
                            scene.Add(CreateBullet(controlledUnit.Translation + Vector3.UnitZ,
                                bulletSpeed,
                                controlledUnit.MotionObject.Rotation.Angle + i,
                                bulletAcceleration));
                    });
            }

            //var bullet = CreateBullet(controlledUnit.Translation + Vector3.UnitZ,
            //        bulletSpeed,
            //        controlledUnit.MotionObject.Orientation,
            //        bulletAcceleration);
            //scene.Add(bullet);

            if (e.KeyCode == System.Windows.Forms.Keys.Up)
                if (controlledUnit != null)
                    ((Common.Motion.Unit)controlledUnit.MotionObject).RunVelocity = new Vector2(((Common.Motion.Unit)controlledUnit.MotionObject).RunVelocity.X, -2);
            if (e.KeyCode == System.Windows.Forms.Keys.Down)
                if (controlledUnit != null)
                    ((Common.Motion.Unit)controlledUnit.MotionObject).RunVelocity = new Vector2(((Common.Motion.Unit)controlledUnit.MotionObject).RunVelocity.X, 2);
            if (e.KeyCode == System.Windows.Forms.Keys.Left)
                if (controlledUnit != null)
                    ((Common.Motion.Unit)controlledUnit.MotionObject).RunVelocity = new Vector2(-2, ((Common.Motion.Unit)controlledUnit.MotionObject).RunVelocity.Y);
            if (e.KeyCode == System.Windows.Forms.Keys.Right)
                if (controlledUnit != null)
                    ((Common.Motion.Unit)controlledUnit.MotionObject).RunVelocity = new Vector2(2, ((Common.Motion.Unit)controlledUnit.MotionObject).RunVelocity.Y);

            if (e.KeyCode == System.Windows.Forms.Keys.OemMinus)
            {
                if (!motionSimulation.Running)
                {
                    AdvanceFrame();
                }
            }
            if (e.KeyCode == System.Windows.Forms.Keys.Enter)
            {
                motionSimulation.Running = true;
            }
        }