Esempio n. 1
0
        public static void ConstructScene()
        {
            GamePixel[][] scene = new GamePixel[viewport.size.y][];

            for (int y = 0; y < viewport.size.y; y++)
            {
                scene[y] = new GamePixel[viewport.size.x];

                for (int x = 0; x < viewport.size.x; x++)
                {
                    Coord gridPos = new Coord(x + viewport.position.x, y + viewport.position.y);

                    scene[y][x] = grid[gridPos.y][gridPos.x];

                    foreach (Entity entity in entities)
                    {
                        if (entity.rect.top <= gridPos.y & entity.rect.bottom >= gridPos.y & entity.rect.left <= gridPos.x & entity.rect.right >= gridPos.x)
                        {
                            if (entity.spriteSheet[entity.activeSpriteSet][entity.activeSprite].grid[gridPos.y - entity.rect.top][gridPos.x - entity.rect.left].foreground >= 0 & entity.spriteSheet[entity.activeSpriteSet][entity.activeSprite].grid[gridPos.y - entity.rect.top][gridPos.x - entity.rect.left].background >= 0)
                            {
                                scene[y][x] = entity.spriteSheet[entity.activeSpriteSet][entity.activeSprite].grid[gridPos.y - entity.rect.top][gridPos.x - entity.rect.left];
                            }
                        }
                    }
                }
            }

            gameRegion.SetContent(scene);
        }
Esempio n. 2
0
        public Sprite(Coord size, string[][] texture, int foreground, int background)
        {
            if (texture.Length == size.y & texture[0].Length == size.x)
            {
                this.size = size;

                if (foreground > 15)
                {
                    foreground = 15;
                }
                if (background > 15)
                {
                    background = 15;
                }

                grid = new GamePixel[size.y][];

                for (int y = 0; y < size.y; y++)
                {
                    grid[y] = new GamePixel[size.x];

                    for (int x = 0; x < size.x; x++)
                    {
                        grid[y][x] = new GamePixel(texture[y][x], foreground, background);
                    }
                }
            }
            else
            {
                throw new Exception("Cannot instantiate Sprite because the specified size does not match the array sizes.");
            }
        }
Esempio n. 3
0
        public Sprite(Coord size, string texture, int foreground, int background)
        {
            this.size = size;

            if (foreground > 15)
            {
                foreground = 15;
            }
            if (background > 15)
            {
                background = 15;
            }

            grid = new GamePixel[size.y][];

            for (int y = 0; y < size.y; y++)
            {
                grid[y] = new GamePixel[size.x];

                for (int x = 0; x < size.x; x++)
                {
                    grid[y][x] = new GamePixel(texture, foreground, background);
                }
            }
        }
Esempio n. 4
0
        public static void InitGrid()
        {
            grid = new GamePixel[size.y][];

            for (int y = 0; y < size.y; y++)
            {
                grid[y] = new GamePixel[size.x];

                for (int x = 0; x < size.x; x++)
                {
                    grid[y][x] = background;
                }
            }
        }
Esempio n. 5
0
 public static void Init(Coord windowSize, Coord gameSize, int pixelWidth)
 {
     Window.Init(windowSize);
     Game.pixelWidth = pixelWidth;
     background      = new GamePixel(pixelWidth, 0, 0);
     if (gameSize.x <= 0 | gameSize.y <= 0)
     {
         gameSize = new Coord(Console.WindowWidth / pixelWidth, Console.WindowHeight);
     }
     size       = gameSize;
     gameRegion = new ScreenRegion(new Coord(0, 0));
     InitGrid();
     InitViewport();
     edgeBumper     = 2;
     entities       = new List <Entity>();
     excludedLayers = new List <int>();
     gameTicker     = new Ticker(0.1f);
     viewportTicker = gameTicker;
     paused         = false;
 }
Esempio n. 6
0
        public Pixel(GamePixel pixel, int index)
        {
            try
            {
                texture = pixel.texture[index];
            }
            catch
            {
                texture = pixel.texture[0];
            }

            if (pixel.foreground > 15)
            {
                pixel.foreground = 15;
            }
            if (pixel.background > 15)
            {
                pixel.background = 15;
            }
            foreground = pixel.foreground;
            background = pixel.background;
        }
Esempio n. 7
0
 public static void SetBackground(GamePixel background)
 {
     Game.background = background;
     InitGrid();
 }