Beispiel #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 :;
        }
Beispiel #2
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];
         }
     }
 }
Beispiel #3
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();
     }
 }
Beispiel #4
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];
             }
         }
     }
 }
Beispiel #5
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]);
        }