예제 #1
0
        static void Main()
        {
            var form = new RenderForm("KinectLight");
            form.Size = new System.Drawing.Size(1920,1200);

            var desc = new SwapChainDescription()
            {
                BufferCount = 1,
                ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed = true,
                OutputHandle = form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput
            };

            SharpDX.Direct3D10.Device1 device;
            SwapChain swapChain;
            SharpDX.Direct3D10.Device1.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, desc, SharpDX.Direct3D10.FeatureLevel.Level_10_1, out device, out swapChain);

            var d2dFactory = new SharpDX.Direct2D1.Factory();
            var surface = Surface.FromSwapChain(swapChain, 0);

            RenderTarget dc = new RenderTarget(d2dFactory, surface, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));

            MainGame.Instance.Height = form.ClientSize.Height;
            MainGame.Instance.Width = form.ClientSize.Width;
            GameTime gameTime = new GameTime();

            var config = new HttpSelfHostConfiguration("http://localhost:8080");

            config.Routes.MapHttpRoute(
                "API Default", "api/{controller}/{action}/{name}",
                new { id = RouteParameter.Optional });

            HttpSelfHostServer server = new HttpSelfHostServer(config);
            server.OpenAsync().Wait();

            RenderLoop.Run(form, () =>
            {
                gameTime.StartFrame();
                MainGame.Instance.Update(gameTime);
                dc.BeginDraw();
                dc.Clear(Colors.White);
                MainGame.Instance.Render(dc);
                var res = dc.EndDraw();
                swapChain.Present(1, PresentFlags.None);
                //Thread.Sleep(1);
            });

            server.Dispose();
            MainGame.Instance.Dispose();
            dc.Dispose();
            surface.Dispose();
            d2dFactory.Dispose();
            device.Dispose();
            swapChain.Dispose();
        }
예제 #2
0
        public void Update(GameTime gameTime)
        {
            for (int i = 0; i < _things.Count; i++)
            {
                _things[i].Update(gameTime);
                if (Player != "" && _skeleton.HitTest(_things[i]))
                {
                    _thingsToRemove.Add(_things[i]);
                    Score++;
                }
            }

            foreach (var thing in _things.Where(t => t.Position.Y > Height))
                _thingsToRemove.Add(thing);

            for (int i = 0; i < _thingsToRemove.Count; i++)
            {
                _things.Remove(_thingsToRemove[i]);
            }

            _thingsToRemove.Clear();

            if (gameTime.WorldTime % 1000 > 1 && _things.Count() < 10)
                _things.Add(new GoodThing() { Position = new Vector3((float)(r.NextDouble() * Width), 0, 0), Velocity = new Vector3(0, 20 + (float)(r.NextDouble() * 10), 0) });

            if (Player != "")
            {
                var playtime = DateTime.Now - PlayerStartTime;
                if (playtime.TotalSeconds > 60)
                {
                    Player = "";
                }
            }
        }
예제 #3
0
 internal void Update(GameTime gameTime)
 {
     Position = Position + (Velocity * (float)(gameTime.FrameDeltaTime /1000));
 }