// 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; } }
// Just draws background private void _drawBg() { if (GameApplication.GameWindow.CurrentScene.BackgroundTexture != null) { MainBufferDrawer.DrawImage(GameApplication.GameWindow.CurrentScene.BackgroundTexture.TextureImage, 0, 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; } } } } }
// 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); } } } }
// 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); }