public Ship(GraphicsDevice GraphDev, int HeightAndWidth) : base(GraphDev, HeightAndWidth, HeightAndWidth)
        {
            int             DrawSize;
            CollisionRegion CollideRegion = new CollisionRegion();

            //Diagonal of square = SqRt(2) * SideLength
            //That is max with of ship rotated
            DrawSize = (int)((float)HeightAndWidth / (float)Math.Sqrt(2));

            //cDrawRegion = new Rectangle();
            cDrawRegion.X      = ((HeightAndWidth - DrawSize) / 2) + (DrawSize / 2);
            cDrawRegion.Y      = ((HeightAndWidth - DrawSize) / 2) + (DrawSize / 2);
            cDrawRegion.Width  = DrawSize;
            cDrawRegion.Height = DrawSize;

            cSpeedX = 0;
            cSpeedY = 0;

            ImageInitialAngle = 0;

            cCollisionList         = new List <CollisionRegion>();
            CollideRegion.Type     = CollideType.Circle;
            CollideRegion.Origin.X = Left + cDrawRegion.X + (DrawSize / 2);
            CollideRegion.Origin.Y = Top + cDrawRegion.Y + (DrawSize / 2);;
            CollideRegion.Radius   = (DrawSize / 2) * 0.9f;

            cCollisionList.Add(CollideRegion);

            cTint = Color.White;

            MouseRotate = false;
        }
Ejemplo n.º 2
0
        protected override void LoadContent()
        {
            string          FileToLoad;
            Texture2D       TextureImage;
            CollisionRegion NewCollide = new CollisionRegion();
            int             Ctr;

            cDrawBatch = new SpriteBatch(cGraphDevMgr.GraphicsDevice);

            //Load all texture files
            foreach (Textures CurrTexture in Enum.GetValues(typeof(Textures)))
            {
                FileToLoad = String.Format("{0}{1}{2}", CONTENT_PATH, Path.DirectorySeparatorChar, EnumTools.GetEnumDescriptionAttribute(CurrTexture));

                TextureImage = Texture2D.FromStream(cGraphDevMgr.GraphicsDevice, File.OpenRead(FileToLoad));

                cTextureDict.Add(CurrTexture, TextureImage);
            }

            //Create drawing objects
            cFont                    = new TextureFont(cTextureDict[Textures.Font]);
            cDevConsole              = new GameConsole(cGraphDevMgr.GraphicsDevice, cFont, cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Width, cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Height / 2);
            cDevConsole.CommandSent += ConsoleCommandHandler;
            cDevConsole.OpenEffect   = DisplayEffect.SlideDown;
            cDevConsole.CloseEffect  = DisplayEffect.SlideUp;

            //Create interface controls
            TextureImage = new Texture2D(cGraphDevMgr.GraphicsDevice, 1, 1);
            TextureImage.SetData(new[] { Color.Transparent });

            cLeftPaddleInputBtn                 = new Button(cGraphDevMgr.GraphicsDevice, TextureImage, 0, 0, 50, 200);
            cLeftPaddleInputBtn.Visible         = true;
            cLeftPaddleInputBtn.Font            = cFont;
            cLeftPaddleInputBtn.FontSize        = 15;
            cLeftPaddleInputBtn.FontColor       = Color.Orange;
            cLeftPaddleInputBtn.SendMouseEvents = true;
            cLeftPaddleInputBtn.MouseEnter     += PaddleInputBtnMouseEnter;
            cLeftPaddleInputBtn.MouseLeave     += PaddleInputBtnMouseLeave;
            cLeftPaddleInputBtn.MouseUp        += LeftPaddleInputBtnCLick;

            cRightPaddleInputBtn                 = new Button(cGraphDevMgr.GraphicsDevice, TextureImage, 0, cGraphDevMgr.GraphicsDevice.Viewport.Width - 200, 50, 200);
            cRightPaddleInputBtn.Visible         = true;
            cRightPaddleInputBtn.Font            = cFont;
            cRightPaddleInputBtn.FontSize        = 15;
            cRightPaddleInputBtn.FontColor       = Color.LightBlue;
            cRightPaddleInputBtn.SendMouseEvents = true;
            cRightPaddleInputBtn.MouseEnter     += PaddleInputBtnMouseEnter;
            cRightPaddleInputBtn.MouseLeave     += PaddleInputBtnMouseLeave;
            cRightPaddleInputBtn.MouseUp        += RightPaddleInputBtnCLick;

            cScoreLbl           = new Button(cGraphDevMgr.GraphicsDevice, TextureImage, 0, cLeftPaddleInputBtn.Top + cLeftPaddleInputBtn.Width, 50, cGraphDevMgr.GraphicsDevice.Viewport.Width - cLeftPaddleInputBtn.Width - cRightPaddleInputBtn.Width);
            cScoreLbl.Text      = "0 - 0";
            cScoreLbl.Font      = cFont;
            cScoreLbl.FontSize  = 20;
            cScoreLbl.FontColor = Color.AntiqueWhite;
            cScoreLbl.Visible   = true;

            //Create the boundary bars (0 = top, 1 = bottom, 2&3 could be left and right?)
            for (Ctr = 0; Ctr < cBoundaryBars.Length; Ctr++)
            {
                cBoundaryBars[Ctr]                 = new GameObject(cGraphDevMgr.GraphicsDevice, 10, cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Width);
                cBoundaryBars[Ctr].Left            = 0;
                cBoundaryBars[Ctr].Height          = 20;
                cBoundaryBars[Ctr].BackgroundColor = Color.White;
                cBoundaryBars[Ctr].Visible         = true;

                NewCollide.Type               = CollideType.Rectangle;
                NewCollide.Origin             = cBoundaryBars[Ctr].GetCenterCoordinates();
                NewCollide.RectOffsets.X      = (int)(NewCollide.Origin.X * -1);
                NewCollide.RectOffsets.Y      = -1 * (cBoundaryBars[Ctr].Height / 2);
                NewCollide.RectOffsets.Width  = cBoundaryBars[Ctr].Width;
                NewCollide.RectOffsets.Height = cBoundaryBars[Ctr].Height;

                cBoundaryBars[Ctr].AddCollisionRegion(NewCollide);
            }

            cBoundaryBars[0].Top = 50;
            cBoundaryBars[1].Top = cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Height - cBoundaryBars[1].Height;

            //Create the ball
            cBall            = new GameObject(cGraphDevMgr.GraphicsDevice, 75);
            cBall.Top        = (int)((cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Height / 2) - cBall.GetCenterCoordinates().Y);
            cBall.Left       = (int)((cGraphDevMgr.GraphicsDevice.Viewport.Bounds.Width / 2) - cBall.GetCenterCoordinates().X);
            cBall.Visible    = true;
            cBall.Background = cTextureDict[Textures.Circle];

            NewCollide.Type   = CollideType.Circle;
            NewCollide.Origin = cBall.GetCenterCoordinates();
            NewCollide.Radius = cBall.Width / 2;

            cBall.AddCollisionRegion(NewCollide);

            //Create the paddles
            cLeftPaddle                 = new GameObject(cGraphDevMgr.GraphicsDevice, 150, 20);
            cLeftPaddle.Top             = (cGraphDevMgr.GraphicsDevice.Viewport.Height / 2) - (cLeftPaddle.Height / 2);
            cLeftPaddle.Left            = 20;
            cLeftPaddle.Visible         = true;
            cLeftPaddle.BackgroundColor = Color.Orange;

            NewCollide.Type               = CollideType.Rectangle;
            NewCollide.Origin             = cLeftPaddle.GetCenterCoordinates();
            NewCollide.RectOffsets.X      = -1 * cLeftPaddle.Width / 2;
            NewCollide.RectOffsets.Y      = -1 * cLeftPaddle.Height / 2;
            NewCollide.RectOffsets.Width  = cLeftPaddle.Width;
            NewCollide.RectOffsets.Height = cLeftPaddle.Height;
            cLeftPaddle.AddCollisionRegion(NewCollide);

            cRightPaddle                 = new GameObject(cGraphDevMgr.GraphicsDevice, 150, 20);
            cRightPaddle.Top             = (cGraphDevMgr.GraphicsDevice.Viewport.Height / 2) - (cRightPaddle.Height / 2);
            cRightPaddle.Left            = cGraphDevMgr.GraphicsDevice.Viewport.Width - cRightPaddle.Width - 20;
            cRightPaddle.Visible         = true;
            cRightPaddle.BackgroundColor = Color.LightBlue;

            NewCollide.Type               = CollideType.Rectangle;
            NewCollide.Origin             = cRightPaddle.GetCenterCoordinates();
            NewCollide.RectOffsets.X      = -1 * cRightPaddle.Width / 2;
            NewCollide.RectOffsets.Y      = -1 * cRightPaddle.Height / 2;
            NewCollide.RectOffsets.Width  = cRightPaddle.Width;
            NewCollide.RectOffsets.Height = cRightPaddle.Height;
            cRightPaddle.AddCollisionRegion(NewCollide);
        }
Ejemplo n.º 3
0
 public void AddCollisionRegion(CollisionRegion CollideReg)
 {
     cCollisionList.Add(CollideReg);
 }