Exemplo n.º 1
0
 internal void _drawDebug()
 {
     if (GameApplication.DrawUtilizationDebugger)
     {
         string ctor = $"Current Game Tick: {GameApplication.GetGameTick()}{Environment.NewLine}Game Tickrate: {GameApplication.CurrentGameTickrate} tps{Environment.NewLine}Game Framerate: {GameApplication.CurrentGameFramerate} fps{Environment.NewLine}Game Collisions UPS: {GameApplication.CurrentGameCollisionUpdateRate} ups";
         BaseCanvas.RazorGFX.DrawString(ctor, new Font("Segoe UI", 8.0f), dbgText, 0, 0);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Crashes game. If <see cref="GameCrashHandler.ThrowMessageToUser"/> true, throws message and exits from application, else just exits from application
 /// </summary>
 /// <param name="exception"><see cref="Exception"/> that crashed game</param>
 /// <param name="messageTitle">Message title</param>
 /// <param name="messageIcon">Message icon</param>
 public void Crash(Exception exception, string messageTitle = "craftersmine GameEngine - Game was crashed!", MessageBoxIcon messageIcon = MessageBoxIcon.Error)
 {
     this.exception = exception;
     GameApplication.LogException(this.exception);
     if (ThrowMessageToUser)
     {
         ThrowToUser(messageTitle, messageIcon);
     }
     GameApplication.Exit(0);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Saves config to disk
        /// </summary>
        public void SaveConfig()
        {
            GameApplication.Log(Utils.LogEntryType.Info, "Saving game configuration... " + Path.Combine(cfgAppDataPath, cfgFileName + ".cfg"));
            List <string> lines = new List <string>();

            foreach (var cfgentry in cfg)
            {
                string ln = string.Join("=", cfgentry.Key, cfgentry.Value);
            }
            File.WriteAllLines(ConfigFilePath, lines);
        }
Exemplo n.º 4
0
        private void DrawGameObjectTexture(GameObject gameObject)
        {
            if (gameObject != null)
            {
                if (gameObject.TextureBoundings.IntersectsWith(CameraBounds))
                {
                    switch (gameObject.CurrentTexture.TextureLayout)
                    {
                    case TextureLayout.Default:
                    case TextureLayout.Stretch:
                        BaseCanvas.RazorGFX.DrawImage(gameObject.CurrentTexture.TextureImage, gameObject.TextureBoundings);
                        break;

                    case TextureLayout.Center:
                        int xCenter = (gameObject.Width / 2) - (gameObject.CurrentTexture.TextureImage.Width / 2) + gameObject.X;
                        int yCenter = (gameObject.Height / 2) - (gameObject.CurrentTexture.TextureImage.Height / 2) + gameObject.Y;
                        BaseCanvas.RazorGFX.DrawImage(gameObject.CurrentTexture.TextureImage, xCenter, yCenter);
                        break;

                    case TextureLayout.Tile:
                        if (!gameObject.IsTiledTextureCached)
                        {
                            Texture tiledTex = PrepareTiledTexture(gameObject.CurrentTexture, gameObject.TextureBoundings);
                            gameObject.IsTiledTextureCached = true;
                            gameObject.TiledTextureCache    = tiledTex;
                            BaseCanvas.RazorGFX.DrawImage(gameObject.TiledTextureCache.TextureImage, gameObject.TextureBoundings);
                        }
                        else
                        {
                            BaseCanvas.RazorGFX.DrawImage(gameObject.TiledTextureCache.TextureImage, gameObject.TextureBoundings);
                        }
                        break;
                    }
                }
                if (GameApplication.DrawTextureBoundings)
                {
                    BaseCanvas.RazorGFX.DrawRectangle(texBoundingsRects, gameObject.TextureBoundings);
                }
                if (GameApplication.DrawColliderBoundings)
                {
                    BaseCanvas.RazorGFX.DrawRectangle(collBoundingsRects, gameObject.BoundingBox);
                }
            }
            else
            {
                GameApplication.Log(Utils.LogEntryType.Warning, "GameEngine unable to draw game object!");
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Loads or reloads config from disk
 /// </summary>
 public void LoadConfig()
 {
     GameApplication.Log(Utils.LogEntryType.Info, "Loading game configuration... " + Path.Combine(cfgAppDataPath, cfgFileName + ".cfg"));
     ConfigFilePath = Path.Combine(GameApplication.AppDataGameRoot, cfgAppDataPath, cfgFileName + ".cfg");
     if (File.Exists(ConfigFilePath))
     {
         IsCreated = false;
         string[] file = File.ReadAllLines(ConfigFilePath);
         foreach (var ln in file)
         {
             string[] kvp = ln.Split('=');
             cfg.Add(kvp[0], kvp[1]);
         }
     }
     else
     {
         IsCreated = true;
     }
 }
Exemplo n.º 6
0
 internal void _drawRects()
 {
     foreach (var rect in Rectangles)
     {
         if (rect.Rect != null)
         {
             if (rect.Rect.IntersectsWith(CameraBounds))
             {
                 if (rect.FillColor != Color.Transparent || rect.FillColor.A > 0)
                 {
                     BaseCanvas.RazorGFX.FillRectangle(rect.FillBrush, rect.Rect);
                 }
                 BaseCanvas.RazorGFX.DrawRectangle(rect.BorderPen, rect.Rect);
             }
         }
         else
         {
             GameApplication.Log(Utils.LogEntryType.Warning, "GameEngine unable to draw rectangle!");
         }
     }
 }
Exemplo n.º 7
0
        internal void _calcLights()
        {
            // Reset buffer
            lightingDrawHelper.Clear(lightingDarkestColor);
            // Calc lights for any object
            foreach (var gObj in GameObjects)
            {
                if (gObj.IsIlluminatingLight)
                {
                    Point  objCenterPoint = new Point(gObj.X / 2, gObj.Y / 2);
                    int    lWidth         = gObj.LightWidth;
                    int    lHeight        = gObj.LightHeight;
                    int    lX             = objCenterPoint.X - lWidth / 2;
                    int    lY             = objCenterPoint.Y - lHeight / 2;
                    Bitmap cookieData     = null;
                    switch (gObj.LightCookieType)
                    {
                    case LightCookieType.Default:
                    case LightCookieType.Circle:
                        cookieData = (Bitmap)GameEngineContent.LightCookieCircle.TextureImage;
                        break;

                    case LightCookieType.Square:
                        cookieData = (Bitmap)GameEngineContent.LightCookieSquare.TextureImage;
                        break;

                    case LightCookieType.Custom:
                        cookieData = (Bitmap)gObj.CustomLightCookie.TextureImage;
                        break;
                    }
                    if (cookieData != null)
                    {
                        cookieData = ImageResizer.ResizeImage(cookieData, lWidth, lHeight);
                        for (int xCookie = 0; xCookie < cookieData.Width; xCookie++)
                        {
                            for (int yCookie = 0; yCookie < cookieData.Height; yCookie++)
                            {
                                int   lXn          = xCookie + lX;
                                int   lYn          = yCookie + lY;
                                float lAlpha       = lightingDarkestColor.A / 255.0f;
                                float lAlphaCookie = cookieData.GetPixel(xCookie, yCookie).A / 255.0f;
                                float lAlphaN      = (lAlpha + lAlphaCookie) * gObj.LightIntensity;
                                if (lAlphaN > 1.0f)
                                {
                                    lAlphaN = 1.0f;
                                }
                                if (lAlphaN < 0.0f)
                                {
                                    lAlphaN = lAlphaCookie;
                                }

                                lightingBuffer.SetPixel(lXn, lYn, Color.FromArgb((int)(lAlphaN * 255.0f), gObj.IlluminationColor));
                            }
                        }
                    }
                    else
                    {
                        GameApplication.Log(Utils.LogEntryType.Warning, "Unable to draw light of \"@" + gObj.InternalName + "\"! No light cookie found!");
                    }
                }
            }

            // Draw on canvas
            BaseCanvas.RazorGFX.DrawImage(lightingBuffer, Point.Empty);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Calls at game exit
 /// </summary>
 public virtual void OnExit()
 {
     GameApplication.Exit(0);
 }