Example #1
0
        public void TestPInfo()
        {
            PInfo[,] data = new PInfo[_BufferWidth, _BufferHeight];
            data.Populate(new PInfo().SetC('c').SetBg(ConsoleColor.Red).SetFg(ConsoleColor.Blue));

            PrintBuffer(data);
        }
Example #2
0
        public static PInfo[,] getColoredStrip(int height, Tuple <Tuple <int, int, int>, PInfo> mid, PInfo top, PInfo bottom)
        {
            //int notwall = (height - mid.Item1 ) / 2;
            PInfo[,] data = new PInfo[1, height];
            data.Populate();
            for (int y = 0; y < height; y++)
            {
                if (y < mid.Item1.Item1)
                {
                    data[0, y].Override(top);
                }
                else
                {
                    if (y < mid.Item1.Item1 + mid.Item1.Item2)
                    {
                        data[0, y].Override(mid.Item2);
                    }
                    else
                    {
                        data[0, y].Override(bottom);
                    }
                }
            }

            return(data);
        }
Example #3
0
        public virtual PInfo[,] Render(double Dist, int ScreenHeight, double PlayerHeight, double RoomHeight, double DistFromLeft)
        {
            double updown = 30 * Math.PI / 180;
            // calculate required height of sprite
            // TODO: Make the system "realistic" things further up will be visible differently than headon
            // currently only spreading the pixels over the calculated are


            double upHigh = RoomHeight - PlayerHeight;



            double unseenTop = Math.Tan(updown) * upHigh;
            double unseenBot = Math.Tan(updown) * PlayerHeight;

            double angleMidTop = Math.Atan(upHigh / Dist);
            double angleMidBot = Math.Atan(PlayerHeight / Dist);
            double angleTop    = (90 * Math.PI / 180) - unseenTop - angleMidTop;
            double angleBot    = (90 * Math.PI / 180) - unseenBot - angleMidBot;

            double halfheight = ScreenHeight / 2;

            double Top    = (int)Math.Round((angleTop / (angleTop + angleMidTop)) * halfheight);
            double Mid    = (int)Math.Round(((angleMidTop / (angleTop + angleMidTop)) * halfheight) + ((angleMidBot / (angleBot + angleMidBot)) * halfheight));
            double Bottom = (int)Math.Round((angleBot / (angleBot + angleMidBot)) * halfheight);

            while (Top + Mid + Bottom < ScreenHeight)
            {
                Mid++;
            }
            // now we have the height of our image


            // then return one by one the pixels of the sprite equivalent to the pixel on screen
            PInfo[,] data = new PInfo[1, ScreenHeight];
            data.Populate();
            double scale = Sprite.GetLength(1) / Mid * 1.0;

            int column = (int)((Sprite.GetLength(0) / Width) * DistFromLeft);

            for (int i = 0; i < Mid; i++)
            {
                // set pixel to the the right image
                data[0, i + (int)Bottom] = Sprite[column, (int)Math.Floor((i) * scale)];
            }
            //Debug.WriteLine("i showed a sprite");
            return(data);
        }
Example #4
0
        static void Main(string[] args)
        {
            Console.ReadLine();
            Stopwatch stop = new Stopwatch();

            DirectConsoleAccess d   = new DirectConsoleAccess(90, 90, 1, 1);
            FastGMU             gmu = new FastGMU(90, 90);

            Console.ReadLine();
            stop.Start();

            //d.TestOutput();
            //d.TestPInfo();

            PInfo[,] data = new PInfo[90, 90];
            data.Populate(new PInfo().SetC('A').SetBg(ConsoleColor.Black).SetFg(ConsoleColor.White));
            d.PrintBuffer(data);


            stop.Stop();
            Console.WriteLine((double)stop.ElapsedMilliseconds / 1000);
            Console.WriteLine("-------------");

            Console.ReadLine();
            ClassicDebugger debugger = new ClassicDebugger();

            Holder <int> x     = new Holder <int>("X", 0, 10);
            Holder <int> y     = new Holder <int>("Y", 0, 10);
            Holder <int> index = new Holder <int>("i", 0, 10);
            Holder <int> left  = new Holder <int>("left", 0, 10);
            Holder <int> top   = new Holder <int>("top", 0, 10);
            Holder <int> w     = new Holder <int>("with", 0, 10);
            Holder <int> h     = new Holder <int>("height", 0, 10);

            HolderString s = new HolderString("---");

            debugger.Watcher.Add(x);
            debugger.Watcher.Add(y);
            debugger.Watcher.Add(index);
            debugger.Watcher.Add(left);
            debugger.Watcher.Add(top);
            debugger.Watcher.Add(w);
            debugger.Watcher.Add(h);
            debugger.Watcher.Add(s);

            debugger.UpdateTime = 200;
            debugger.Activate();

            //Console.SetWindowPosition(10, 10);



            while (!Console.KeyAvailable)
            {
                //index.value++;
                var i = MouseInput.GetMousePosition();
                x.value = i.X;
                y.value = i.Y;

                var pos = MouseInput.GetMouseConsolePosition();

                left.value = pos.X;
                top.value  = pos.Y;
                w.value    = pos.W;
                h.value    = pos.H;

                s.Value = "".PadRight(w.value - 1, '-');

                System.Threading.Thread.Sleep(50);
            }

            debugger.Abort();

            Console.ReadLine();
        }
        private PInfo[,] renderLine(Line look)
        {
            PInfo[,] strip = new PInfo[1, height];
            strip.Populate();

            // Renderable, dist from origin, dist from player
            Stack <Tuple <IRenderable, double, double> > renderstack = new Stack <Tuple <IRenderable, double, double> >();


            // create a list of all things
            List <Tuple <Line, IRenderable> > visibles = new List <Tuple <Line, IRenderable> >();


            foreach (var item in SpriteObjects)
            {
                Line l = new Line();
                // angle to player
                double changeX = Player.x_2 - Player.x_1;
                double changeY = Player.y_2 - Player.y_1;
                // get angle to player
                double angle = Math.Atan2(changeY, changeX);
                // now rotate and get cords of start and end
                // origin, left of player
                l.x_1 = item.Value.Item1 + (Math.Cos(angle - (90 / Math.PI * 2)) * item.Key.Width / 2);
                l.y_1 = item.Value.Item2 + (Math.Sin(angle - (90 / Math.PI * 2)) * item.Key.Width / 2);
                // other side right of player
                l.x_2 = item.Value.Item1 + (Math.Cos(angle + (90 / Math.PI * 2)) * item.Key.Width / 2);
                l.y_2 = item.Value.Item2 + (Math.Sin(angle + (90 / Math.PI * 2)) * item.Key.Width / 2);
                visibles.Add(new Tuple <Line, IRenderable>(l, item.Key));
            }

            foreach (var item in DObjectects)
            {
                visibles.Add(new Tuple <Line, IRenderable>(item.Key, item.Value));
            }

            // create shorter representation of line
            double dirX = look.x_2 - look.x_1;
            double dirY = look.y_2 - look.y_1;

            double dist = Math.Sqrt(dirX * dirX + dirY * dirY);

            // normalize vector
            dirX /= dist;
            dirY /= dist;

            // now calculate the number of pixels until first contact with a wall

            //PInfo wallLook = new PInfo() { hasBackground = true, background = ConsoleColor.Black };
            bool reachedWall = false;



            look.x_2 = look.x_1 + dirX * MAXDRAWDIST;
            look.y_2 = look.y_1 + dirY * MAXDRAWDIST;

            double xInt;
            double yInt;

            if (look.y_2 == 15.3)
            {
                Debug.WriteLine("");
            }

            var found = visibles
                        .Where(v => doLinesIntersect(look, v.Item1, out xInt, out yInt))
                        .Select(i =>
            {
                double atX;
                double atY;
                doLinesIntersect(look, i.Item1, out atX, out atY);
                return(new { Object = i, Distance = Math.Sqrt(Math.Pow(look.x_1 - atX, 2) + Math.Pow(look.y_1 - atY, 2)), XInt = atX, YInt = atY });
            })
                        .ToList();

            if (found.Count == 0)
            {
                Debug.WriteLine("empty");
            }
            var ToRender = found
                           .Where(f => f.Distance <= found.Where(wall => !wall.Object.Item2.isTransparent).Min(closest => closest.Distance))
                           .OrderBy(all => - all.Distance)
                           .ToList();


            foreach (var some in ToRender)
            {
                double distFromOrigin = Math.Sqrt(Math.Pow(some.XInt - some.Object.Item1.x_1, 2) + Math.Pow(some.YInt - some.Object.Item1.y_1, 2));
                renderstack.Push(new Tuple <IRenderable, double, double>(some.Object.Item2, distFromOrigin, some.Distance));
            }
            //Debug.WriteLine(ToRender.Count);

            /*
             * foreach (var item in visibles)
             * {
             *  double xIntersect;
             *  double yIntersect;
             *  if (doLinesIntersect(look, item.Item1, out xIntersect, out yIntersect))
             *  {
             *
             *      if (!renderstack.Select((x) => { return x.Item1; }).Contains(item.Item2))
             *      {
             *          if (!item.Item2.isTransparent)
             *          {
             *              reachedWall = true;
             *          }
             *          // distance from object origin
             *          double distFromOrigin = Math.Sqrt(Math.Pow(xIntersect - item.Item1.x_1, 2) + Math.Pow(yIntersect - item.Item1.y_1, 2));
             *          // Object, distance from object origin, distance from camera
             *          renderstack.Push(new Tuple<IRenderable, double, double>(item.Item2, distFromOrigin, inst * 0.01));
             *      }
             *
             *  }
             * }*/



            renderstack.Push(new Tuple <IRenderable, double, double>(
                                 new Object3D()
            {
                isTransparent = false,
                pattern       = new PInfo[, ]
                {
                    {
                        new PInfo()
                        {
                            HasBackground = true, Background = ConsoleColor.Black
                        }
                    }
                }
            }
                                 , 1
                                 , MAXDRAWDIST
                                 ));

            while (renderstack.Count > 0)
            {
                Tuple <IRenderable, double, double> data = renderstack.Pop();

                strip.Merge(data.Item1.Render(data.Item3, height, PlayerHeight, RoomHeight, data.Item2));
            }

            return(strip);
        }
Example #6
0
        public virtual PInfo[,] Render(double Dist, int ScreenHeight, double PlayerHeight, double roomHeight, double DistFromLeft)
        {
            double updown = 30 * Math.PI / 180;

            // calculate the parts of top and bottom
            double upHigh = roomHeight - PlayerHeight;

            // calculate what left
            DistFromLeft = DistFromLeft % patternwidth;
            double side = DistFromLeft * pattern.GetLength(0);


            double unseenTop = Math.Tan(updown) * upHigh;
            double unseenBot = Math.Tan(updown) * PlayerHeight;

            double angleMidTop = Math.Atan(upHigh / Dist);
            double angleMidBot = Math.Atan(PlayerHeight / Dist);
            double angleTop    = (90 * Math.PI / 180) - unseenTop - angleMidTop;
            double angleBot    = (90 * Math.PI / 180) - unseenBot - angleMidBot;

            double halfheight = ScreenHeight / 2;

            int Bottom = (int)Math.Round((angleTop / (angleTop + angleMidTop)) * halfheight);
            int Mid    = (int)Math.Round(((angleMidTop / (angleTop + angleMidTop)) * halfheight) + ((angleMidBot / (angleBot + angleMidBot)) * halfheight));
            int Top    = (int)Math.Round((angleBot / (angleBot + angleMidBot)) * halfheight);

            while (Top + Mid + Bottom < ScreenHeight)
            {
                Mid++;
            }

            double pixelPerHeight = roomHeight / Mid;


            #region create strip
            //int notwall = (height - mid.Item1 ) / 2;
            PInfo[,] data = new PInfo[1, ScreenHeight];
            data.Populate();
            for (int y = 0; y < ScreenHeight; y++)
            {
                if (y < Bottom)
                {
                    data[0, y].Override(new PInfo().SetBg(ConsoleColor.Gray));
                }
                else
                {
                    if (y < Bottom + Mid)
                    {
                        // calculate what pixels
                        double up = ((y - Bottom) * pixelPerHeight) % patternheight;

                        data[0, y].Override(pattern[(int)Math.Floor(side), (int)Math.Floor(up)]);
                    }
                    else
                    {
                        data[0, y].Override(new PInfo().SetBg(ConsoleColor.DarkGray));
                    }
                }
            }
            #endregion


            return(data);
        }