Beispiel #1
0
 public Tile(GameArea currentGameArea, int x, int y, int blockWidth, int blockHeight) : base(currentGameArea)
 {
     X           = x;
     Y           = y;
     BlockHeight = blockHeight;
     BlockWidth  = blockWidth;
 }
        public BackgroundInformation(GameArea currentGameArea)
        {
            boundGameArea = currentGameArea;

            TextureId = DrawingUtility.GetColoredDotTextureId(Color.CornflowerBlue);

            GraphicsUtility.AddBackgroundCollection(this);
        }
Beispiel #3
0
        public Tile2(GameArea currentGameArea, int x, int y, int tileNumber, string assetName, int tilewidth, int tileheight) : base(currentGameArea)
        {
            X = x;
            Y = y;

            Height = 32;
            Width  = 32;

            TileNumber = tileNumber;
            AssetName  = assetName;
            TileWidth  = tilewidth;
            TileHeight = tileheight;
        }
Beispiel #4
0
 public ScreenSectors(GameArea areaToSectorize, int SectorSize, SectorStyle style)
 {
 }
Beispiel #5
0
 public GameObject(GameArea currentGameArea)
 {
     CurrentGameArea = currentGameArea;
 }
Beispiel #6
0
        public static void Draw()
        {
            CurrentGame.GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin();
#pragma warning disable CS0618 // Type or member is obsolete

            // draw backgrounds
            foreach (BackgroundInformation back in backgroundCollection)
            {
                spriteBatch.Draw(TextureCollection[back.TextureId], back.boundGameArea.ViewportRectangle, Color.White);

                // those are the only allowed drawing locations
                if (!bufferedGameAreaRectangles.Contains(back.boundGameArea.ViewportRectangle))
                {
                    bufferedGameAreaRectangles.Add(back.boundGameArea.ViewportRectangle);
                    bufferedGameAreas.Add(back.boundGameArea);
                }
            }

            // draw objects
            for (int i = 0; i < visibleGameObjects.Count; i++)
            {
                foreach (GameObject obj in visibleGameObjects[i])
                {
                    bool     onScreen = false;
                    GameArea area     = null;

                    Rectangle clippingRectangle = obj.GetDrawingRectangle();
                    Rectangle positionRectangle = Rectangle.Empty;

                    // check for viewport clipping or offscreen objects
                    foreach (Rectangle gameAreaRec in bufferedGameAreaRectangles)
                    {
                        if (gameAreaRec.Intersects(obj.PositionRectangle))
                        {
                            onScreen = true;

                            // keep gamearea
                            area = bufferedGameAreas[bufferedGameAreaRectangles.IndexOf(gameAreaRec)];

                            // check if we need to clip
                            // game area edge clip
                            Rectangle intersectRectangle = Rectangle.Intersect(gameAreaRec, obj.PositionRectangle);

                            if (intersectRectangle.Width != obj.PositionRectangle.Width ||
                                intersectRectangle.Height != obj.PositionRectangle.Height)
                            {
                                clippingRectangle = new Rectangle(obj.GetDrawingRectangle().Location, obj.GetDrawingRectangle().Size);
                                positionRectangle = new Rectangle(obj.PositionRectangle.Location, obj.PositionRectangle.Size);

                                if (clippingRectangle == Rectangle.Empty)
                                {
                                    clippingRectangle = new Rectangle(Point.Zero, positionRectangle.Size);
                                }

                                if (intersectRectangle.Width < obj.PositionRectangle.Width)
                                {
                                    clippingRectangle.Width = intersectRectangle.Width;
                                    positionRectangle.Width = intersectRectangle.Width;

                                    if (obj.PositionRectangle.X < gameAreaRec.X)
                                    {
                                        clippingRectangle.X += obj.PositionRectangle.Width - intersectRectangle.Width;
                                    }
                                }

                                if (intersectRectangle.Height < obj.PositionRectangle.Height)
                                {
                                    clippingRectangle.Height = intersectRectangle.Height;
                                    positionRectangle.Height = intersectRectangle.Height;

                                    if (obj.PositionRectangle.Y < gameAreaRec.Y)
                                    {
                                        clippingRectangle.Y += obj.PositionRectangle.Height - intersectRectangle.Height;
                                    }
                                }
                            }

                            // swap game area if applicable
                            if (typeof(IMobile).IsAssignableFrom(obj.GetType()) &&
                                obj.CurrentGameArea != area &&
                                obj.CurrentGameArea.EdgeBehaviorX == GameAreaEdgeBehavior.NONE &&
                                obj.CurrentGameArea.EdgeBehaviorY == GameAreaEdgeBehavior.NONE)
                            {
                                if (typeof(ICollidable).IsAssignableFrom(obj.GetType()))
                                {
                                    area.Collision.AddCollidableObject((ICollidable)obj);
                                    obj.CurrentGameArea.Collision.RemoveCollidableObject((ICollidable)obj);
                                }

                                if (typeof(IMobile).IsAssignableFrom(obj.GetType()))
                                {
                                    area.Gravity.AddGravityAffectedObject((IMobile)obj);
                                    obj.CurrentGameArea.Gravity.RemoveGravityAffectedObject((IMobile)obj);
                                }

                                obj.DeScale();
                                obj.CurrentGameArea = area;
                                obj.ReScale();
                            }

                            // TODO : layer overlap clip

                            // exit; no support for game objects on 2 game area simultaneously
                            break;
                        }
                    }

                    // set visibility
                    obj.Visible = onScreen;

                    // draw if applicable
                    if (obj.Visible)
                    {
                        if (clippingRectangle == Rectangle.Empty)
                        {
                            if (positionRectangle == Rectangle.Empty)
                            {
                                spriteBatch.Draw(texture: TextureCollection[obj.textureId], destinationRectangle: obj.PositionRectangle);
                            }
                            else
                            {
                                spriteBatch.Draw(texture: TextureCollection[obj.textureId], destinationRectangle: positionRectangle);
                            }
                        }
                        else
                        {
                            if (positionRectangle == Rectangle.Empty)
                            {
                                spriteBatch.Draw(texture: TextureCollection[obj.textureId], destinationRectangle: obj.PositionRectangle, sourceRectangle: clippingRectangle);
                            }
                            else
                            {
                                spriteBatch.Draw(texture: TextureCollection[obj.textureId], destinationRectangle: positionRectangle, sourceRectangle: clippingRectangle);
                            }
                        }
                    }
                }
            }

#pragma warning restore CS0618 // Type or member is obsolete
            spriteBatch.End();
        }
Beispiel #7
0
 public CollisionHandler(GameArea currentArea)
 {
     sectors = new ScreenSectors(currentArea, 8, ScreenSectors.SectorStyle.Matrix);
 }