Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            Initialize();


            /* Load small Sounds before ambient as otherwise we get error creating buffer */
            gun  = new MissileWeapon(c.defaultPath, w.getActiveCamera());
            gun2 = new InstantExplosionWeapon(c.defaultPath, w.getActiveCamera());
            LoadAudio();

            LoadObjects();

            w.getActiveCamera().getPosition().set(0.0f, 0.0f, 10.0f);
            w.getActiveCamera().rotateX(-3.0f);
            //w.getActiveCamera().linkLookAtPosition(playerPosition);

            FPSCounter frameCounter = new FPSCounter();
            bool       quitFlag     = false;

            while (!quitFlag)
            {
                float frameTime = frameCounter.Update();

                //playerPosition.set(new Vector3f(1.0f, 0.0f, 0.0f).stretch(w.getActiveCamera().getPosition()) + new Vector3f(0.0f, 1.0f, 0.0f));

                playerVelocity.y -= 0.01f * frameTime;
                playerPosition.set(playerPosition + playerVelocity);
                crosshairPosition.set(crosshairPosition + playerVelocity);

                float zoom = crosshairPosition.length(playerPosition) * -2.0f;
                Console.Out.WriteLine(zoom);
                zoom = zoom > -10.0f ? -10.0f : zoom;
                w.getActiveCamera().getPosition().set(w.getActiveCamera().getFrontVector().copy().stretch(zoom) + ((playerPosition + crosshairPosition) * 0.5f));

                if (playerPosition.y < 1.0f)
                {
                    playerPosition.y = 1.0f;
                    playerVelocity.y = 0;
                }

                quitFlag = w.Update(frameTime);
                updateAudio();
            }

            Deinitialize();
        }
Exemplo n.º 2
0
        private static void Main()
        {
            var framebuffer = new Framebuffer <uint>(1024, 512, ColorUtils.PackColor(255, 255, 255));
            var raycaster   = new TinyRaycaster
            {
                Framebuffer = framebuffer,
                Player      = new Player
                {
                    X   = 3.456f, // player x position
                    Y   = 2.345f, // player y position
                    A   = 1.523f,
                    FOV = MathF.PI / 3.0f
                }
            };

            var sdlWindow = new SDLWindow(1024, 512, framebuffer);


            if (!sdlWindow.Init())
            {
                Console.WriteLine(sdlWindow.GetError());
                return;
            }


            var time = DateTime.Now;

            while (true)
            {
                var time2 = DateTime.Now;
                if ((time2 - time).TotalMilliseconds < 20)
                {
                    Thread.Sleep(3);
                    continue;
                }

                time = time2;

                var(type, key) = sdlWindow.GetEvent();

                if (type == EventType.Quit)
                {
                    break;
                }

                if (type == EventType.KeyUp)
                {
                    switch (key)
                    {
                    case KeyCode.A:
                    case KeyCode.D:
                        raycaster.Player.Turn = 0;
                        break;

                    case KeyCode.W:
                    case KeyCode.S:
                        raycaster.Player.Walk = 0;
                        break;
                    }
                }

                if (type == EventType.KeyDown)
                {
                    switch (key)
                    {
                    case KeyCode.A:
                        raycaster.Player.Turn = -1;
                        break;

                    case KeyCode.D:
                        raycaster.Player.Turn = 1;
                        break;

                    case KeyCode.W:
                        raycaster.Player.Walk = 1;
                        break;

                    case KeyCode.S:
                        raycaster.Player.Walk = -1;
                        break;
                    }
                }

                raycaster.Run();
                sdlWindow.Update();
            }

            sdlWindow.Destroy();
        }