예제 #1
0
 public void DetachBack(BackgroundEntity entity)
 {
     if (BackEntities.Remove(entity))
     {
         OnBackDetach?.Invoke(this, entity);
     }
 }
예제 #2
0
        /// <summary>
        /// Factory method to create Section from a given BackgroundEntity
        /// </summary>
        /// <param name="backgroundEnt"></param>
        /// <returns></returns>
        private Section CreateLevelBlock(BackgroundEntity backgroundEnt)
        {
            var levelBlock = new Section();

            levelBlock.AddBackgroundEntity(backgroundEnt.Entity).AddHoleRange(backgroundEnt.Holes);

            var len = levelBlock.Length;

            RandomAddObstacles(levelBlock, len, backgroundEnt.MaxNbObstacles);

            return(levelBlock);
        }
예제 #3
0
파일: Level.cs 프로젝트: tws2xa/RunningGame
        //This creates the background entity for the level.
        public BackgroundEntity getMyBackgroundEntity()
        {
            string fullImageAddress = "RunningGame.Resources.Artwork.Background.Bkg11.png";
            string imageStub        = "Artwork.Background.Bkg";
            //string preColorImageStub = "Artwork.Background.BkgPreColor";
            //string fullImageAddress = "RunningGame.Resources.Artwork.Background.back21.png";
            //string imageStub = "Artwork.Background.back";


            Bitmap tempImg = getBkgImg();

            float newWidth  = tempImg.Width;
            float newHeight = tempImg.Height;

            if (!GlobalVars.fullForegroundImage)
            {
                float scaleFactor = 1.1f;

                while (newWidth / scaleFactor > levelWidth || newHeight / scaleFactor > levelHeight)
                {
                    newWidth  /= scaleFactor;
                    newHeight /= scaleFactor;
                }

                while (newWidth < levelWidth || newHeight < levelHeight)
                {
                    newWidth  *= scaleFactor;
                    newHeight *= scaleFactor;
                }
            }
            BackgroundEntity  bkgEnt   = new BackgroundEntity(this, 0, 0, newWidth, newHeight);
            DrawComponent     drawComp = ( DrawComponent )bkgEnt.getComponent(GlobalVars.DRAW_COMPONENT_NAME);
            PositionComponent posComp  = ( PositionComponent )bkgEnt.getComponent(GlobalVars.POSITION_COMPONENT_NAME);


            /*
             * //Static Background
             * if (sysManager.bkgPosSystem.scrollType == 0)
             * {
             *  float initWidth = drawComp.getImage().Width;
             *  float initHeight = drawComp.getImage().Height;
             *
             *  float xDiff = Math.Abs(initWidth - levelWidth);
             *  float yDiff = Math.Abs(initHeight - levelHeight);
             *
             *  //Make it fit horizontally
             *  if (xDiff < yDiff)
             *  {
             *      float ratio = initWidth / levelWidth;
             *      getMovementSystem().changeSize(posComp, levelWidth, initHeight * ratio);
             *      drawComp.resizeImages((int)levelWidth, (int)(initHeight * ratio));
             *      getMovementSystem().changePosition(posComp, levelWidth/2, levelHeight-initHeight*ratio/2, false);
             *  }
             *  //Make it fit vertically
             *  else
             *  {
             *      float ratio = initHeight / levelHeight;
             *      getMovementSystem().changeSize(posComp, initWidth*ratio , levelHeight);
             *      drawComp.resizeImages((int)(initWidth*ratio), (int)(levelHeight));
             *      getMovementSystem().changePosition(posComp, initWidth * ratio / 2, levelHeight / 2, false);
             *  }
             * }
             * else if (sysManager.bkgPosSystem.scrollType == 3)
             * {
             *  Bitmap tempImg = getBkgImg();
             *  float newWidth = tempImg.Width;
             *  float newHeight = tempImg.Height;
             *
             *  float scaleFactor = 1.1f;
             *
             *  while (newWidth/scaleFactor > levelWidth || newHeight/scaleFactor > levelHeight)
             *  {
             *      newWidth /= scaleFactor;
             *      newHeight /= scaleFactor;
             *  }
             *
             *  while (newWidth < levelWidth || newHeight < levelHeight)
             *  {
             *      newWidth *= scaleFactor;
             *      newHeight *= scaleFactor;
             *  }
             *
             *  getMovementSystem().changeSize(posComp, newWidth, newHeight);
             *  drawComp.width = newWidth;
             *  drawComp.height = newHeight;
             *  drawComp.resizeImages((int)newWidth, (int)newHeight);
             *  getMovementSystem().changePosition(posComp, newWidth / 2, newHeight / 2, false);
             * }
             * */
            /*
             * //Proportion Scrolling
             * if (sysManager.bkgPosSystem.scrollType == 1 || sysManager.bkgPosSystem.scrollType == 2)
             * {
             *  System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
             *  // THIS WONT WORK BECAUSE IT"S GETTING THE DEFAULT IMAGE NOT IMAGE STUB
             *  System.IO.Stream myStream = myAssembly.GetManifestResourceStream(fullImageAddress);
             *  Bitmap sprite = new Bitmap(myStream); //Getting an error here? Did you remember to make your image an embedded resource?
             *  myStream.Close();
             *
             *  float w = sprite.Width;
             *  float h = sprite.Height;
             *
             *  float multiplier = 0.5f;
             *
             *  while (w > levelWidth || (h > levelHeight && sysManager.bkgPosSystem.scrollType == 1))
             *  {
             *      w *= multiplier;
             *      h *= multiplier;
             *  }
             *
             *  getMovementSystem().changeSize(posComp, w, h);
             *
             * }
             */

            drawComp.addSprite(imageStub, fullImageAddress, "MainBkg");
            drawComp.setSprite("MainBkg");

            bkgEnt.isStartingEntity = true;

            return(bkgEnt);
        }
예제 #4
0
 public void AttachToBack(BackgroundEntity entity)
 {
     BackEntities.Add(entity);
     OnBackAttach?.Invoke(this, entity);
 }
예제 #5
0
        /// <summary>
        /// Factory method to create Section from a given BackgroundEntity
        /// </summary>
        /// <param name="backgroundEnt"></param>
        /// <returns></returns>
        private Section CreateLevelBlock(BackgroundEntity backgroundEnt)
        {
            var levelBlock = new Section();

            levelBlock.AddBackgroundEntity(backgroundEnt.Entity).AddHoleRange(backgroundEnt.Holes);

            var len = levelBlock.Length;
            RandomAddObstacles(levelBlock, len, backgroundEnt.MaxNbObstacles);

            return levelBlock;
        }
예제 #6
0
파일: View.cs 프로젝트: tws2xa/RunningGame
        public void Draw(Graphics mainG, List <Entity> entities)
        {
            //g.FillRectangle(bkgBrush, new Rectangle(0, 0, (int)width, (int)height)); //Clear

            if (!(level is RunningGame.Level_Editor.CreationLevel))
            {
                if (!hasDecreasedQuality)
                {
                    g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; // or NearestNeighbour
                    g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.None;
                    g.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.None;
                    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
                    g.TextRenderingHint  = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;

                    mainG.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; // or NearestNeighbour
                    mainG.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.None;
                    mainG.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.None;
                    mainG.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
                    mainG.TextRenderingHint  = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;

                    hasDecreasedQuality = true;
                }

                //Find background Entity first if need be
                if (bkgEnt == null)
                {
                    foreach (Entity e in entities)
                    {
                        if (e is BackgroundEntity)
                        {
                            bkgEnt = ( BackgroundEntity )e; //Find background entity
                        }
                    }
                }

                if (staticObjImg == null /*|| redrawStatics*/)
                {
                    if (seperateStaticObjImage)
                    {
                        staticObjImg = new Bitmap(( int )Math.Ceiling(level.levelWidth), ( int )Math.Ceiling(level.levelHeight));
                    }
                    else
                    {
                        foreach (Entity e in entities)
                        {
                            if (e is BackgroundEntity)
                            {
                                if (bkgEnt == null)
                                {
                                    bkgEnt = ( BackgroundEntity )e; //Find background entity
                                }
                                DrawComponent bkgDraw = ( DrawComponent )bkgEnt.getComponent(GlobalVars.DRAW_COMPONENT_NAME);
                                staticObjImg = ( Bitmap )bkgDraw.getImage();
                            }
                        }
                    }

                    //Draw static entities onto background
                    if (!GlobalVars.fullForegroundImage)
                    {
                        foreach (Entity ent in GlobalVars.groundEntities.Values)
                        {
                            DrawComponent grnDraw = ( DrawComponent )ent.getComponent(GlobalVars.DRAW_COMPONENT_NAME);

                            /*DrawComponent bkgDraw = (DrawComponent)bkgEnt.getComponent(GlobalVars.DRAW_COMPONENT_NAME);
                             *
                             * PositionComponent posComp = (PositionComponent)ent.getComponent(GlobalVars.POSITION_COMPONENT_NAME);
                             * PointF drawPoint = posComp.getPointF();
                             * drawPoint.X -= (posComp.width / 2.0f);
                             * drawPoint.Y -= (posComp.height / 2.0f);
                             *
                             * Graphics graph = Graphics.FromImage(bkgDraw.getImage());*/


                            PositionComponent posComp   = ( PositionComponent )ent.getComponent(GlobalVars.POSITION_COMPONENT_NAME);
                            PointF            drawPoint = posComp.getLocAsPoint();
                            drawPoint.X -= (posComp.width / 2.0f);
                            drawPoint.Y -= (posComp.height / 2.0f);

                            Graphics graph = Graphics.FromImage(staticObjImg);
                            lock (grnDraw.getImage()) {
                                graph.DrawImageUnscaled(grnDraw.getImage(), new Point(( int )drawPoint.X, ( int )drawPoint.Y));     //Draw the image to the view
                            }
                            grnDraw.needRedraw = false;
                            //redrawStatics = false;
                        }
                    }
                }

                //First, if there's a background entity, draw that!
                if (bkgEnt != null)
                {
                    drawBkgEntity(bkgEnt);
                }
                if (seperateStaticObjImage)
                {
                    drawStaticObjImage();
                }


                //If there's a grapple, draw it
                if (level.sysManager != null && level.sysManager.grapSystem.isGrappling)
                {
                    foreach (Entity e in GlobalVars.nonGroundEntities.Values)
                    {
                        if (e is GrappleEntity)
                        {
                            GrappleComponent grapComp = ( GrappleComponent )e.getComponent(GlobalVars.GRAPPLE_COMPONENT_NAME);

                            PointF start = grapComp.getFirstPoint();
                            PointF end   = grapComp.getLastPoint();

                            /*
                             * // Calc the pos relative to the view
                             * start.X -= this.x;
                             * start.Y -= this.y;
                             * end.X -= this.x;
                             * end.Y -= this.y;
                             *
                             * start.X *= wRatio;
                             * start.Y *= hRatio;
                             * end.X *= wRatio;
                             * end.Y *= hRatio;
                             */
                            g.DrawLine(GrapplePen, start, end);
                            break; //Should only be one - this'll save some time.
                        }
                    }
                }


                //For all applicable entities (Entities with required components)
                foreach (Entity e in entities)
                {
                    if (!(e is BackgroundEntity))
                    {
                        drawEntity(e);
                    }
                }

                if (level.sysManager.drawSystem.drawDebugStuff)
                {
                    for (int i = 0; i < level.sysManager.drawSystem.debugLines.Count - 1; i += 2)
                    {
                        g.DrawLine(new Pen(Color.Blue, 3), level.sysManager.drawSystem.debugLines[i], level.sysManager.drawSystem.debugLines[i + 1]);
                    }
                    level.sysManager.drawSystem.debugLines.Clear();
                    int circWidth = 4;
                    for (int i = 0; i < level.sysManager.drawSystem.debugPoints.Count; i++)
                    {
                        g.FillEllipse(Brushes.Green, ( int )Math.Round(level.sysManager.drawSystem.debugPoints[i].X - circWidth / 2), ( int )Math.Round(level.sysManager.drawSystem.debugPoints[i].Y) - circWidth / 2, circWidth, circWidth);
                    }
                    level.sysManager.drawSystem.debugPoints.Clear();
                }


                //mainG.DrawImage(drawImg, new Point((int)displayX, (int)displayY)); //Draw the view to the main window
                //mainG.DrawImageUnscaled(drawImg, new Point((int)displayX, (int)displayY)); //Draw the view to the main window
                mainG.DrawImage(drawImg, new RectangleF(displayX, displayY, displayWidth, displayHeight), new RectangleF(x, y, width, height), GraphicsUnit.Pixel);


                //Draw Border
                if (this.hasBorder)
                {
                    if (!this.borderFade)
                    {
                        mainG.DrawRectangle(new Pen(borderBrush, borderSize), new Rectangle(( int )(displayX), ( int )(displayY),
                                                                                            ( int )(displayWidth), ( int )(displayHeight)));
                    }
                    else
                    {
                        int alphaDiff = ( int )Math.Ceiling(255.0f / (borderSize - amntSolid));     //How much to decrease alpha per layer
                        //Draw the solid bit
                        //mainG.DrawRectangle(new Pen(borderBrush, amntSolid), new Rectangle((int)(displayX), (int)(displayY),
                        //(int)(displayWidth), (int)(displayHeight)));

                        int alphaVal = 255;
                        alphaVal -= alphaDiff;

                        for (int i = 0; i <= borderSize; i++)
                        {
                            if (alphaVal < 0)
                            {
                                alphaVal = 0;
                            }
                            Color tmpCol = Color.FromArgb(alphaVal, borderBrush.Color);
                            Pen   pen    = new Pen(new SolidBrush(tmpCol), 1);
                            mainG.DrawRectangle(pen, new Rectangle(( int )(displayX + i), ( int )(displayY + i),
                                                                   ( int )(displayWidth - 2 * i), ( int )(displayHeight - 2 * i))); alphaVal -= alphaDiff;
                            alphaVal -= alphaDiff;
                            if (alphaVal < 0)
                            {
                                alphaVal = 0;
                            }
                        }
                    }
                }
            }
            else
            {
                //For all applicable entities (Entities with required components)
                foreach (Entity e in entities)
                {
                    drawEntity(e);
                }
                mainG.DrawImage(drawImg, new RectangleF(displayX, displayY, displayWidth, displayHeight), new RectangleF(x, y, width, height), GraphicsUnit.Pixel);
            }
        }