コード例 #1
0
        // Draw texture at specific position and size (Currently unused)
        private void DrawTexture(Texture texture, int xPos, int yPos, int width, int height)
        {
            Rectangle textureBounding = new Rectangle(xPos, yPos, width, height);

            switch (texture.TextureLayout)
            {
            case TextureLayout.Stretch:
                MainBufferDrawer.DrawImage(texture.TextureImage, textureBounding);
                break;

            case TextureLayout.Tile:
                Texture tiledTex = PrepareTiledTexture(texture, textureBounding);
                MainBufferDrawer.DrawImage(tiledTex.TextureImage, textureBounding);
                break;

            case TextureLayout.Center:
                int xCenter = (width / 2) - (texture.TextureImage.Width / 2);
                int yCenter = (height / 2) - (texture.TextureImage.Height / 2);
                textureBounding.X      = xCenter;
                textureBounding.Y      = yCenter;
                textureBounding.Width  = texture.TextureImage.Width;
                textureBounding.Height = texture.TextureImage.Height;
                MainBufferDrawer.DrawImage(texture.TextureImage, textureBounding);
                break;
            }
        }
コード例 #2
0
 // Just draws background
 private void _drawBg()
 {
     if (GameApplication.GameWindow.CurrentScene.BackgroundTexture != null)
     {
         MainBufferDrawer.DrawImage(GameApplication.GameWindow.CurrentScene.BackgroundTexture.TextureImage, 0, 0);
     }
 }
コード例 #3
0
        // Game Object drawer
        private void _drawGameObjects()
        {
            // If current scene have any game layer start draw layers
            if (GameApplication.GameWindow.CurrentScene.GameLayers.Any())
            {
                foreach (var layer in GameApplication.GameWindow.CurrentScene.GameLayers)
                {
                    for (int gObjIndex = 0; gObjIndex < layer.Value.GameObjects.Count; gObjIndex++)
                    {
                        // If game object bounding box intersects with camera bounding box (In viewport) continue
                        if (layer.Value.GameObjects[gObjIndex].Transform.CameraBoundings.IntersectsWith(GameApplication.GameWindow.CurrentScene.Camera.CameraBounds))
                        {
                            layer.Value.GameObjects[gObjIndex].IsCameraVisible = true;  // Set that object is in viewport
                            // If game object layout is tiled and game object have invalid cached tiled texture, then
                            if (layer.Value.GameObjects[gObjIndex].ObjectTexture.TextureLayout == TextureLayout.Tile && layer.Value.GameObjects[gObjIndex].IsInvalidTiledTextureCache)
                            {
                                // Prepare and save tiled texture in cache
                                layer.Value.GameObjects[gObjIndex].CachedTiledTexture = PrepareTiledTexture(layer.Value.GameObjects[gObjIndex].ObjectTexture, layer.Value.GameObjects[gObjIndex].Transform.BoundingsRectangle);
                                // Set that game object have now valid tiled texture in cache
                                layer.Value.GameObjects[gObjIndex].IsInvalidTiledTextureCache = false;
                            }
                            // Draw game object texture in main buffer
                            MainBufferDrawer.DrawImage(layer.Value.GameObjects[gObjIndex].DrawableImage, layer.Value.GameObjects[gObjIndex].Transform.CameraBoundings);

                            //if (GameApplication.GameWindow.CurrentScene.GameObjects[gObjIndex].IsIlluminatingLight)
                            //{
                            //    GraphicsPath lightPath = new GraphicsPath();
                            //    Rectangle lightRect = new Rectangle((GameApplication.GameWindow.CurrentScene.GameObjects[gObjIndex].Transform.Width * 5) / 2 - (GameApplication.GameWindow.CurrentScene.GameObjects[gObjIndex].Transform.Width / 2), (GameApplication.GameWindow.CurrentScene.GameObjects[gObjIndex].Transform.Height * 5) / 2 - (GameApplication.GameWindow.CurrentScene.GameObjects[gObjIndex].Transform.Height / 2), GameApplication.GameWindow.CurrentScene.GameObjects[gObjIndex].Transform.Width * 5, GameApplication.GameWindow.CurrentScene.GameObjects[gObjIndex].Transform.Height * 5);
                            //    lightPath.AddEllipse(lightRect);
                            //    using (PathGradientBrush grad = new PathGradientBrush(lightPath))
                            //    {
                            //        grad.CenterColor = GameApplication.GameWindow.CurrentScene.GameObjects[gObjIndex].LightColor;
                            //        grad.SurroundColors = new Color[] { Color.Black };
                            //        LightBufferDrawer.FillRectangle(grad, lightRect);
                            //    }
                            //}

                            // If true draw debug rectangles (Main bounding box and collision box)
                            if (DrawDebugRects)
                            {
                                MainBufferDrawer.DrawRectangle(DebugRectangleBoundings, layer.Value.GameObjects[gObjIndex].Transform.CameraBoundings);                      // GameObject main bounding box
                                MainBufferDrawer.DrawRectangle(DebugCollisionBoxRectangleBoundings, layer.Value.GameObjects[gObjIndex].CollisionBox.CollisionBoxBoundings); // GameObject collision bounding box
                            }
                            // Draw debug info about that object
                            if (DrawDebugInfo)
                            {
                                MainBufferDrawer.DrawString("X: " + layer.Value.GameObjects[gObjIndex].X + "\r\nY: " + layer.Value.GameObjects[gObjIndex].Y + "\r\nCamX: " + layer.Value.GameObjects[gObjIndex].Transform.CameraX + "\r\nCamY: " + layer.Value.GameObjects[gObjIndex].Transform.CameraY, GameApplication.GameWindow.Font, FontBrush, layer.Value.GameObjects[gObjIndex].Transform.CameraX, layer.Value.GameObjects[gObjIndex].Transform.CameraY);
                            }
                        }
                        // Or if game object don't intersects with camera bounding box (Not in viewport), set that game object no being visible by camera
                        else
                        {
                            layer.Value.GameObjects[gObjIndex].IsCameraVisible = false;
                        }
                    }
                }
            }
        }
コード例 #4
0
 // UI layer drawer
 private void _drawUiLayer()
 {
     // If current scene have any UIControl, start draw
     if (GameApplication.GameWindow.CurrentScene.UIControls.Any())
     {
         for (int uiInd = 0; uiInd < GameApplication.GameWindow.CurrentScene.UIControls.Count; uiInd++)
         {
             GameApplication.GameWindow.CurrentScene.UIControls[uiInd].CallDrawMethod();          // Call user-defined draw method
             if (GameApplication.GameWindow.CurrentScene.UIControls[uiInd].DrawableImage != null) // If drawable image not null, drae it
             {
                 MainBufferDrawer.DrawImage(GameApplication.GameWindow.CurrentScene.UIControls[uiInd].DrawableImage, GameApplication.GameWindow.CurrentScene.UIControls[uiInd].Transform.X, GameApplication.GameWindow.CurrentScene.UIControls[uiInd].Transform.Y);
             }
         }
     }
 }
コード例 #5
0
 // Main draw caller
 private void DrawCaller()
 {
     lock (GameApplication.GameWindow.Canvas.RazorLock)  // Set lock for resize or etc.
     {
         while (IsRunning)
         {
             // Clear light buffer
             //LightBufferDrawer.Clear(Color.Black);
             // Set interpolation mode
             MainBufferDrawer.InterpolationMode = TextureInterpolationMode;
             // If Current Scene not null
             if (GameApplication.GameWindow.CurrentScene != null)
             {
                 // Clear Main buffer with scene color
                 MainBufferDrawer.Clear(GameApplication.GameWindow.CurrentScene.BackgroundColor);
                 // Draw background
                 _drawBg();
                 // Draw gameobjects
                 _drawGameObjects();
                 // Calculate and draw lights
                 //_calcLighting();
                 // Draw UI controls
                 _drawUiLayer();
             }
             else
             {
                 // Or if Current Scene is null just clear all window with base color
                 MainBufferDrawer.Clear(GameApplication.GameWindow.BaseColor);
             }
             // Draw main buffer
             GameApplication.GameWindow.Canvas.RazorGFX.DrawImage(DrawBuffer, 0, 0);
             if (DrawDebugRects)  // Draw debug rects if true
             {
                 GameApplication.GameWindow.Canvas.RazorGFX.DrawRectangle(DebugCameraRectangleBoundings, GameApplication.GameWindow.CurrentScene.Camera.CameraBounds);
                 GameApplication.GameWindow.Canvas.RazorGFX.DrawRectangle(DebugMousePointRectangleBoundings, GameApplication.GameWindow.MousePoint);
             }
             if (DrawDebugInfo)  // Draw debug texts if true
             {
                 GameApplication.GameWindow.Canvas.RazorGFX.DrawString($"craftersmine EtherEngine{Environment.NewLine}{Environment.NewLine}WindowSize: {GameApplication.GameWindow.Width}x{GameApplication.GameWindow.Height}{Environment.NewLine}DrawCall: {DrawCall} {Environment.NewLine}FPS: {Framerate}{Environment.NewLine}{AdditionalDebugInfo}", GameApplication.GameWindow.Font, FontBrush, 0, 0);
             }
             // Render
             GameApplication.GameWindow.Canvas.RazorPaint();
             DrawCall++;  // Increment draw call
         }
     }
 }
コード例 #6
0
 // Global illumination and objects illumination (Lighting)
 private void _calcLighting()
 {
     // Set light buffer opacity and draw it on main buffer
     SetImageOpacity(LightingBuffer, 1.0f - GameApplication.GameWindow.CurrentScene.LightValue);
     MainBufferDrawer.DrawImage(LightingBuffer, 0, 0);
 }