Esempio n. 1
0
 public Ghost(Chixel chixel, Vector2 pos)
 {
     Game.Instance.Characters.Add(this);
     Chixel   = chixel;
     Position = pos;
     Velocity = Vector2.Up;
 }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            //Ball();

            Console.ResetColor();

            Bitmap isl = new Bitmap("frac.png");

            Sprite s = new Sprite(new Box((ushort)isl.Width, (ushort)isl.Height, new Point2D(1, 1)));

            for (ushort y = 0; y < s.Height; y++)
            {
                for (ushort x = 0; x < s.Width; x++)
                {
                    s[x, y] = new Chixel(new Graphics.Coloring.Color((uint)isl.GetPixel(x, y).ToArgb()));
                }
            }



            s.Render(Sprite.RenderOption.Default);


            Console.CursorVisible = false;

            //Console.Title = "\"An 8-bit Adventure RPG\"";

            Console.ReadLine();
            Console.ResetColor();
        }
Esempio n. 3
0
        //

        // to-do: finish
        public void Rotate(Point2D about, double angle)
        {
            // use ceiling then directly map exact coordinates
            ushort w = (ushort)Math.Ceiling(area.Height * Math.Cos(angle) * area.Width * Math.Sin(angle));
            ushort h = (ushort)Math.Ceiling(area.Height * Math.Sin(angle) * area.Width * Math.Cos(angle));

            // floor value of x, y
            ushort fx;
            ushort fy;

            // ceiling value of x, y
            ushort cx;
            ushort cy;

            Chixel[,] mat = new Chixel[w, h];
            Chixel[,] mem = new Chixel[w, h];

            Point2D current;

            for (ushort y = 0; y < Height; y++)
            {
                for (ushort x = 0; x < Width; x++)
                {
                    current = new Point2D(x, y);
                    current.Rotate(about, angle);

                    fx = (ushort)Math.Floor(current.X);
                    fy = (ushort)Math.Floor(current.Y);

                    cx = (ushort)Math.Ceiling(current.X);
                    cy = (ushort)Math.Ceiling(current.Y);
                }
            }
        }
Esempio n. 4
0
        public Pacman(Chixel chixel, Vector2 pos)
        {
            Instance = this;

            Chixel   = chixel;
            Position = pos;

            Velocity = Vector2.Right;
        }
Esempio n. 5
0
        public Clyde(Chixel chixel, Vector2 pos)
        {
            Chixel   = chixel;
            Position = pos;
            Velocity = Vector2.Up;

            Game.Instance.Characters.Add(this);

            ScatterTarget = Map.Instance.GetTile(new Vector2(3, Map.Instance.MapSize.Y - 2));
        }
Esempio n. 6
0
        public Blinky(Chixel chixel, Vector2 pos)
        {
            Chixel   = chixel;
            Position = pos;
            Velocity = Vector2.Right;

            Game.Instance.Characters.Add(this);

            ScatterTarget = Map.Instance.GetTile(new Vector2(Map.Instance.MapSize.X - 4, 0));
        }
Esempio n. 7
0
        //

        public void Apply(Image img, double pos, bool usegamma, Blend.Mode mode)
        {
            for (ushort y = 0; y < Height; y++)
            {
                for (ushort x = 0; x < Width; x++)
                {
                    matrix[x, y] = new Chixel(Blend.Apply(img[x, y].MeshColor, matrix[x, y].MeshColor,
                                                          pos, usegamma, mode));
                }
            }
        }
Esempio n. 8
0
        public new void Initalize(Box area)
        {
            memory = new Chixel[(ushort)area.Width, (ushort)area.Height];

            for (ushort y = 0; y < area.Height; y++)
            {
                for (ushort x = 0; x < area.Width; x++)
                {
                    memory[x, y] = new Chixel();
                }
            }
            LoadMap(DEFAULT_MAP_MODE);
        }
Esempio n. 9
0
        public void Initalize(Box area)
        {
            matrix = new Chixel[(ushort)area.Width, (ushort)area.Height];

            for (ushort y = 0; y < area.Height; y++)
            {
                for (ushort x = 0; x < area.Width; x++)
                {
                    matrix[x, y] = new Chixel();
                }
            }
            this.area = new Box(area);
        }
Esempio n. 10
0
        public Snake(int currentLength, Chixel headChixel, Chixel bodyChixel,
                     Directions startingDirection = Directions.RIGHT)
        {
            // Classic constructor stuff
            this.CurrentLength       = currentLength;
            this.chixelList          = new List <PosChixel>();
            this.BodyChixel          = bodyChixel;
            this.HeadChixel          = headChixel;
            this.CurrentDirection    = startingDirection;
            this.deltaDirectionStack = new ConcurrentStack <Directions>();

            // Setting the snake up so that the head is in the center and its body is on its left.
            chixelList.Add(new PosChixel(FrameBuffer.Instance.Width / 2, FrameBuffer.Instance.Height / 2, headChixel));
            for (int i = 1; i < currentLength; i++)
            {
                chixelList.Add(new PosChixel(chixelList.Last().x - 1, chixelList.Last().y, bodyChixel));
            }

            DrawSnake();
        }
Esempio n. 11
0
        public void RenderChixel(ushort x, ushort y, RenderOption option, PointerAdvance outmode)
        {
            Console.Title = "[Sx Sy]: [" + area.Source.X + " " + area.Source.Y + "]";

            Chixel final = new Chixel();
            Chixel current;

            // update the internal image of the screen
            if ((RenderOption.Record & option) == RenderOption.Record)
            {
                memory[x, y] = new Chixel(matrix[x, y]);
            }
            // do not render if chixel is not on the screen
            if ((Terminal.PointerX == area.Source.X + x && Terminal.PointerY == area.Source.Y + y) ||
                (area.Source.X + x <= Terminal.Width && area.Source.Y + y <= Terminal.Height))
            {
                Terminal.Pointer((ushort)(area.Source.X + x), (ushort)(area.Source.Y + y));
            }
            else
            {
                return;
            }
            // just-in-time opacity merging
            if (matrix[x, y].MeshColor.Opacity != Color.ARGB_MAX)
            {
                // override view level for opacity blending
                if ((RenderOption.Reset & option) == RenderOption.Reset)
                {
                    Terminal.Colors(Chixel.DEFAULT_FG.Console, Chixel.DEFAULT_BG.Console);
                    Terminal.Put(Chixel.EMPTY_GLYPH, (Terminal.OutputMode)outmode, GetHashCode());
                }
                current = new Chixel(Terminal.GlyphAt((ushort)(area.Source.X + x), (ushort)(area.Source.Y + y), VIEW_LEVEL),
                                     new Color(Terminal.ForeAt((ushort)(area.Source.X + x), (ushort)(area.Source.Y + y), VIEW_LEVEL)),
                                     new Color(Terminal.BackAt((ushort)(area.Source.X + x), (ushort)(area.Source.Y + y), VIEW_LEVEL)));

                final.MeshColor = Blend.Apply(matrix[x, y].MeshColor, current.MeshColor,
                                              Blend.DEFAULT_POS, Blend.DEFAULT_USE_GAMMA, Blend.DEFAULT_MODE);

                Terminal.Colors(final.Fore.Console, final.Back.Console);
                Terminal.Put(final.Glyph, (Terminal.OutputMode)outmode, GetHashCode());
            }
            else
            {
                Terminal.Colors(matrix[x, y].Fore.Console, matrix[x, y].Back.Console);
                Terminal.Put(matrix[x, y].Glyph, (Terminal.OutputMode)outmode, GetHashCode());
            }
            // return the render matrix to the internal image of the screen
            if ((RenderOption.Restore & option) == RenderOption.Restore)
            {
                matrix[x, y] = new Chixel(memory[x, y]);
            }
            // reset the chixels in the internal image
            if ((RenderOption.CleanUp & option) == RenderOption.CleanUp)
            {
                memory[x, y] = new Chixel();
            }
            // reset the chixels in the render matrix
            if ((RenderOption.Blank & option) == RenderOption.Blank)
            {
                matrix[x, y] = new Chixel();
            }
        }
Esempio n. 12
0
        //

        public void Translate(Point2D delta)
        {
            Point2D src;

            // Width and Height are always > 0
            short w = (short)(area.Width + Math.Abs(delta.X));
            short h = (short)(area.Height + Math.Abs(delta.Y));

            Chixel[,] mat = new Chixel[w, h];
            Chixel[,] mem = new Chixel[w, h];

            if (delta.X >= 0 && delta.Y >= 0)
            {
                src = new Point2D(area.LowerLeft);

                for (ushort y = 0; y < h; y++)
                {
                    for (ushort x = 0; x < w; x++)
                    {
                        mat[x, y] = x >= w - area.Width && y >= h - area.Height ?
                                    new Chixel(matrix[(ushort)(x - w + area.Width), (ushort)(y - h + area.Height)]) :
                                    new Chixel();

                        mem[x, y] = x < area.Width && y < area.Height ?
                                    new Chixel(memory[x, y]) :
                                    new Chixel();
                    }
                }
                //w= (short)(1 * w);
                //h= (short)(1 * h);
            }
            else if (delta.X >= 0 && delta.Y < 0)
            {
                src = new Point2D(area.UpperLeft);

                for (ushort y = 0; y < h; y++)
                {
                    for (ushort x = 0; x < w; x++)
                    {
                        mat[x, y] = x >= w - area.Width && y < area.Height ?
                                    new Chixel(matrix[(ushort)(x - w + area.Width), y]) :
                                    new Chixel();

                        mem[x, y] = x < area.Width && y >= h - area.Height ?
                                    new Chixel(memory[x, (ushort)(y - h + area.Height)]) :
                                    new Chixel();
                    }
                }
                //w= (short)(1 * w);
                h = (short)(-1 * h);
            }
            else if (delta.X < 0 && delta.Y >= 0)
            {
                src = new Point2D(area.LowerRight);

                for (ushort y = 0; y < h; y++)
                {
                    for (ushort x = 0; x < w; x++)
                    {
                        mat[x, y] = x < area.Width && y >= h - area.Height ?
                                    new Chixel(matrix[x, (ushort)(y - h + area.Height)]) :
                                    new Chixel();

                        mem[x, y] = x >= w - area.Width && y < area.Height ?
                                    new Chixel(memory[(ushort)(x - w + area.Width), y]) :
                                    new Chixel();
                    }
                }
                w = (short)(-1 * w);
                //h= 1 * h;
            }
            else if (delta.X < 0 && delta.Y <= 0)
            {
                src = new Point2D(area.UpperRight);

                for (ushort y = 0; y < h; y++)
                {
                    for (ushort x = 0; x < w; x++)
                    {
                        mat[x, y] = x < area.Width && y < area.Height ?
                                    new Chixel(matrix[x, y]) :
                                    new Chixel();

                        mem[x, y] = x >= w - area.Width && y >= h - area.Height ?
                                    new Chixel(memory[(ushort)(x - w + area.Width), (ushort)(y - h + area.Height)]) :
                                    new Chixel();
                    }
                }
                w = (short)(-1 * w);
                h = (short)(-1 * h);
            }
            // delta.X == 0 && delta.Y == 0
            else
            {
                return;
            }
            matrix = new Chixel[Math.Abs(w), Math.Abs(h)];
            memory = new Chixel[Math.Abs(w), Math.Abs(h)];

            for (ushort y = 0; y < Math.Abs(h); y++)
            {
                for (ushort x = 0; x < Math.Abs(w); x++)
                {
                    matrix[x, y] = new Chixel(mat[x, y]);
                    memory[x, y] = new Chixel(mem[x, y]);
                }
            }
            area = new Box(w, h, src);

            LoadMap(DEFAULT_MAP_MODE);
        }
Esempio n. 13
0
        //

        public void Rebox()
        {
            Point2D src;

            Chixel[,] mat;
            Chixel[,] mem;

            ushort w;
            ushort h;

            ushort xmin = ushort.MaxValue;
            ushort xmax = ushort.MinValue;

            ushort ymin = ushort.MaxValue;
            ushort ymax = ushort.MinValue;

            for (ushort y = 0; y < Height; y++)
            {
                for (ushort x = 0; x < Width; x++)
                {
                    if (matrix[x, y].Glyph != memory[x, y].Glyph ||
                        matrix[x, y].Fore.ARGB != memory[x, y].Fore.ARGB ||
                        matrix[x, y].Back.ARGB != memory[x, y].Back.ARGB)
                    {
                        xmax = x > xmax ? x : xmax;
                        xmin = x < xmin ? x : xmin;

                        ymax = y > ymax ? y : ymax;
                        ymin = y < ymin ? y : ymin;
                    }
                }
            }
            xmin = xmin == ushort.MaxValue ? ushort.MinValue : xmin;
            xmax = xmax == ushort.MinValue ? (ushort)(Width - 1) : xmax;

            ymin = ymin == ushort.MaxValue ? ushort.MinValue : ymin;
            ymax = ymax == ushort.MinValue ? (ushort)(Height - 1) : ymax;

            w = (ushort)(xmax - xmin + 1);
            h = (ushort)(ymax - ymin + 1);

            src = new Point2D(area.Source.X + xmin, area.Source.Y + ymin);

            mat = new Chixel[w, h];
            mem = new Chixel[w, h];

            for (ushort y = 0; y < h; y++)
            {
                for (ushort x = 0; x < w; x++)
                {
                    mat[x, y] = new Chixel(matrix[xmin + x, ymin + y]);
                    mem[x, y] = new Chixel(memory[xmin + x, ymin + y]);
                }
            }
            matrix = new Chixel[w, h];
            memory = new Chixel[w, h];

            for (ushort y = 0; y < h; y++)
            {
                for (ushort x = 0; x < w; x++)
                {
                    matrix[x, y] = new Chixel(mat[x, y]);
                    memory[x, y] = new Chixel(mem[x, y]);
                }
            }
            area = new Box(w, h, src);

            LoadMap(DEFAULT_MAP_MODE);
        }
Esempio n. 14
0
 public PosChixel(int locX, int locY, Chixel other)
     : base(other)
 {
     x = locX;
     y = locY;
 }
Esempio n. 15
0
        public static void Ball()
        {
            Random rand = new Random();

            Console.Title = "Test";

            Console.CursorVisible = false;

            Console.ResetColor();

            Console.BackgroundColor = ConsoleColor.Black;

            Bitmap b  = new Bitmap("ball.png");
            Bitmap bb = new Bitmap("frac.png");
            Bitmap bg = new Bitmap("ball.png");

            Sprite s  = new Sprite(new Box((ushort)b.Width, (ushort)b.Height, new Point2D(80, 40)));
            Sprite ss = new Sprite(new Box((ushort)bb.Width, (ushort)bb.Height, new Point2D(0, 0)));
            Sprite ii = new Sprite(new Box((ushort)bg.Width, (ushort)bg.Height, new Point2D(4, 44)));

            for (ushort y = 0; y < s.Height; y++)
            {
                for (ushort x = 0; x < s.Width; x++)
                {
                    s[x, y] = new Chixel(new Graphics.Coloring.Color((uint)b.GetPixel(x, y).ToArgb()));
                }
            }
            for (ushort y = 0; y < ss.Height; y++)
            {
                for (ushort x = 0; x < ss.Width; x++)
                {
                    ss[x, y] = new Chixel(new Graphics.Coloring.Color((uint)bb.GetPixel(x, y).ToArgb()));
                }
            }
            for (ushort y = 0; y < ii.Height; y++)
            {
                for (ushort x = 0; x < ii.Width; x++)
                {
                    ii[x, y] = new Chixel(new Graphics.Coloring.Color((uint)bg.GetPixel(x, y).ToArgb()));
                }
            }

            //ii.LoadXYMaps(Sprite.RenderMode.Random);

            for (byte i = 0; true; i++)
            {
                ii.Move(new Point2D(70, -40), Sprite.RenderOption.Record, Sprite.FillMode.YX_IV);
                ii.Rebox();
                ii.Move(new Point2D(70, 40), Sprite.RenderOption.Record, Sprite.FillMode.YX_I);
                ii.Rebox();

                ii.Move(new Point2D(-70, 40), Sprite.RenderOption.Record, Sprite.FillMode.YX_II);
                ii.Rebox();
                ii.Move(new Point2D(-70, -40), Sprite.RenderOption.Record, Sprite.FillMode.YX_III);
                ii.Rebox();

                ii.Move(new Point2D(20, 0), Sprite.RenderOption.Record, Sprite.FillMode.YX_I);
                ii.Rebox();

                ii.Move(new Point2D(20, -40), Sprite.RenderOption.Record, Sprite.FillMode.XY_IV);
                ii.Rebox();
                ii.Move(new Point2D(20, 40), Sprite.RenderOption.Record, Sprite.FillMode.XY_I);
                ii.Rebox();

                ii.Move(new Point2D(23, 0), Sprite.RenderOption.Record, Sprite.FillMode.YX_I);
                ii.Rebox();

                ii.Move(new Point2D(20, -40), Sprite.RenderOption.Record, Sprite.FillMode.XY_IV);
                ii.Rebox();
                ii.Move(new Point2D(20, 40), Sprite.RenderOption.Record, Sprite.FillMode.XY_I);
                ii.Rebox();

                ii.Move(new Point2D(20, 0), Sprite.RenderOption.Record, Sprite.FillMode.YX_I);
                ii.Rebox();

                ii.Move(new Point2D(-20, 0), Sprite.RenderOption.Record, Sprite.FillMode.YX_III);
                ii.Rebox();

                ii.Move(new Point2D(-20, 40), Sprite.RenderOption.Record, Sprite.FillMode.XY_II);
                ii.Rebox();
                ii.Move(new Point2D(-20, -40), Sprite.RenderOption.Record, Sprite.FillMode.XY_III);
                ii.Rebox();

                ii.Move(new Point2D(-23, 0), Sprite.RenderOption.Record, Sprite.FillMode.YX_III);
                ii.Rebox();

                ii.Move(new Point2D(-20, 40), Sprite.RenderOption.Record, Sprite.FillMode.XY_II);
                ii.Rebox();
                ii.Move(new Point2D(-20, -40), Sprite.RenderOption.Record, Sprite.FillMode.XY_III);
                ii.Rebox();

                ii.Move(new Point2D(-20, 0), Sprite.RenderOption.Record, Sprite.FillMode.YX_III);
                ii.Rebox();
            }

            /*Console.Clear();
            *  ii.Render(Sprite.RenderOption.None, Sprite.RenderMode.Random_YX_I);
            *  Console.Clear();
            *  ii.Render(Sprite.RenderOption.None, Sprite.RenderMode.Random_XY_II);
            *  Console.Clear();
            *  ii.Render(Sprite.RenderOption.None, Sprite.RenderMode.Random_YX_II);
            *  Console.Clear();
            *  ii.Render(Sprite.RenderOption.None, Sprite.RenderMode.Random_XY_III);
            *  Console.Clear();
            *  ii.Render(Sprite.RenderOption.None, Sprite.RenderMode.Random_YX_III);
            *  Console.Clear();
            *  ii.Render(Sprite.RenderOption.None, Sprite.RenderMode.Random_XY_IV);
            *  Console.Clear();
            *  ii.Render(Sprite.RenderOption.None, Sprite.RenderMode.Random_YX_IV);
            *  Console.Clear();*/

            Console.ReadLine();
        }
Esempio n. 16
0
 public Teleport(Chixel chixel, Vector2 pos, TileType type)
 {
     Chixel   = chixel;
     Position = pos;
     Type     = type;
 }