Ejemplo n.º 1
0
        public static void UpdateScreen()
        {
            /*
             * Updates the screen buffer and prepares it to be written to the screen by the Draw() method
             *
             */

            // Fill screen with background
            foreach (int Y in RCore.GetArrayRange(background.GetLength(0)))
            {
                foreach (int X in RCore.GetArrayRange(background.GetLength(1)))
                {
                    if (background[Y, X] != '\0')
                    {
                        screen[Y, X] = background[Y, X];
                    }
                }
            }

            // Check is a Sprite object was ever instantiated. If not, skip the sprite check.
            if (spriteList == null)
            {
                goto SkipSpriteCheck;
            }

            // Fill screen with Sprites
            foreach (var sprite in spriteList)
            {
                if (sprite == null)
                {
                    continue;
                }
                if (sprite.Active == true)
                {
                    imageBuffer = sprite.GetImage();

                    foreach (int Y in RCore.GetArrayRange(imageBuffer.GetLength(0)))
                    {
                        foreach (int X in RCore.GetArrayRange(imageBuffer.GetLength(1)))
                        {
                            if (imageBuffer[Y, X] == '\0' || Char.IsWhiteSpace(imageBuffer[Y, X]))
                            {
                                continue;
                            }                                                                                                               // skip blank spaces in the image
                            try
                            {
                                screen[sprite.position.PosY + Y, sprite.position.PosX + X] = imageBuffer[Y, X];
                            }
                            catch (IndexOutOfRangeException)
                            {
                                // This will skip parts of the sprite that are no longer on the screen.
                                continue;
                            }
                        }
                    }
                }
            }
            SkipSpriteCheck :;
        }
Ejemplo n.º 2
0
        public State NewState(string name)
        {
            // New State with NO Image or Animation

            // Resize the list
            RCore.ListUp <State>(ref stateList);

            stateList[Array.IndexOf(stateList, null)] = new State(name);

            return(stateList[stateList.Length - 1]);
        }
Ejemplo n.º 3
0
        public static Sprite NewSprite(int Xpos, int Ypos)
        {
            // Resize the list
            RCore.ListUp <Sprite>(ref spriteList);

            // Replace next null occurrence with a new instance of Sprite.
            spriteList[Array.IndexOf(spriteList, null)] = new Sprite(new Position(Xpos, Ypos, screen), screen);

            // Return a reference to the Sprite we just created so we can issue commands from the top level.
            return(spriteList[spriteList.Length - 1]);
        }
Ejemplo n.º 4
0
        public static void FillBackground(string imageSource)
        {
            /*
             * Fill the background with Image object.
             * If the Image object is not large enough to fill the background, it will be tiled.
             *
             */

            Image image = new Image(imageSource);

            imageBuffer = image.Get();

            RCore.FillArray(ref background, imageBuffer);
        }
Ejemplo n.º 5
0
 public static void SetBackground(Image image)
 {
     imageBuffer = image.Get();
     foreach (int Y in RCore.GetArrayRange(imageBuffer.GetLength(0)))
     {
         foreach (int X in RCore.GetArrayRange(imageBuffer.GetLength(1)))
         {
             if (Y >= background.GetLength(0) || X >= background.GetLength(1))
             {
                 continue;
             }
             background[Y, X] = imageBuffer[Y, X];
         }
     }
 }
Ejemplo n.º 6
0
        public State NewAnimationState(string animationSource, string name)
        {
            // New State with Animation

            // Resize the animationList and add a new instance of Animation
            RCore.ListUp <Animation>(ref animationList);
            animationList[Array.IndexOf(animationList, null)] = new Animation(animationSource);

            // Resize the stateList and add a new instance of State
            RCore.ListUp <State>(ref stateList);
            stateList[Array.IndexOf(stateList, null)] = new State(animationList[animationList.Length - 1], name);

            // Return a reference of the State instance to the top level
            return(stateList[stateList.Length - 1]);
        }
Ejemplo n.º 7
0
        public State NewImageState(string imageSource, string name)
        {
            // New State with Image

            // Resize the imageList and add a new instance of Image
            RCore.ListUp <Image>(ref imageList);
            imageList[Array.IndexOf(imageList, null)] = new Image(imageSource);

            // Resize the stateList and add a new instance of State
            RCore.ListUp <State>(ref stateList);
            stateList[Array.IndexOf(stateList, null)] = new State(imageList[imageList.Length - 1], name);

            // Return a reference of the State instance to the top level
            return(stateList[stateList.Length - 1]);
        }
Ejemplo n.º 8
0
 public static void Draw()
 {
     Console.Clear();
     if (showStats == true)
     {
         Console.WriteLine("FPS: {0} WaitTime: {1} ActiveSprites: {2} ", Updates.statFPS, Updates.statWaitTime, spriteList.Length);
     }
     // Draw the screen
     foreach (int Y in RCore.GetArrayRange(screen.GetLength(0)))
     {
         foreach (int X in RCore.GetArrayRange(screen.GetLength(1)))
         {
             Console.Write(screen[Y, X]);
         }
         Console.WriteLine();
     }
 }
Ejemplo n.º 9
0
        public Animation(string animationSource)
        {
            animation = new Image[RCore.CalculateKeyFrames(animationSource)];
            foreach (char item in animationSource)
            {
                if (item != '\t')
                {
                    frameBuffer = String.Concat(frameBuffer, item);
                }
                else if (item == '\t')
                {
                    animation[keyFrame] = new Image(frameBuffer);
                    frameBuffer         = "";
                    keyFrame++;
                }
            }

            keyFrame = 0;
        }
Ejemplo n.º 10
0
        public void Convert(string source)
        {
            /*
             * Convert a string into a two-dimensional char array.
             * string "  @  \n @@@ \n@@@@@"
             *
             *         |___@___|
             *         |__@@@__|
             * becomes:|_@@@@@_| Inside of a two-dimensional matrix
             *
             * This makes it easier to draw to the screen buffer and subsequently be displayed to the user.
             */

            // Instance the Image Array with proper size
            size  = RCore.CalculateArraySize(source);
            image = new char[size[0], size[1]];

            // Convert string into char array and assign it to the proper position inside of the image array
            RCore.StringToArray(ref image, source);
        }
Ejemplo n.º 11
0
 public void ChangeState(string name)
 {
     // Change currentState = State.name if State.name exist in the stateList.
     foreach (int index in RCore.GetArrayRange(stateList.Length))
     {
         if (stateList[index].Name == name)
         {
             stateList[index].state = true;
             if (currentState != null)
             {
                 currentState.Reset();
                 currentState = stateList[index];
             }
             else if (currentState == null)
             {
                 currentState = stateList[index];
             }
         }
     }
 }
Ejemplo n.º 12
0
        public char[,] GetImage()
        {
            /*
             * Check Sprite's current state.
             * Then check if that state has an associated animation or image to be displayed.
             * Then return that animation frame or image.
             *
             *
             */


            // Check if Sprite has any States that will yield an image
            if (stateList != null)
            {
                foreach (int index in RCore.GetArrayRange(stateList.Length))
                {
                    if (stateList[index].state == true)
                    {
                        return(stateList[index].GetImage().Get());
                    }
                }
            }

            // Check if Sprite has an Animation
            else if (animation != null)
            {
                return(animation.GetImage().Get());
            }

            // Finally check if Sprite has an Image
            else if (image != null)
            {
                return(image.Get());
            }

            // If Sprite does no contain any images to render then return and empty array.
            return(new char[0, 0]);
        }