diff --git a/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2.csproj.Debug.cachefile b/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2.csproj.Debug.cachefile index fd665fd..b2daa24 100644 --- a/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2.csproj.Debug.cachefile +++ b/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2.csproj.Debug.cachefile @@ -34,10 +34,6 @@ Content\Boxing\Player_Punch.xnb Content\Boxing\Player_Punch_Hit.xnb Content\Boxing\Player_Running_Side.xnb Content\Boxing\Player_Walking_Side.xnb -Content\BoxingItems\BowlerHat_Instance.xnb -Content\Boxing\Bitmaps\Player_Cane_Bitmap.xnb -Content\Boxing\Bitmaps\Player_Cane_Pull_Bitmap.xnb -Content\Boxing\Bitmaps\Player_Punch_Bitmap.xnb Content\Boxing\LevelBackground.xnb Content\BoxingItems\Player_BowlerHat.xnb Content\BoxingItems\Player_BowlerHat_Catch.xnb @@ -50,6 +46,10 @@ Content\BoxingItems\Player_Revolver.xnb Content\BoxingItems\Player_Revolver_Hit.xnb Content\Boxing\Player_Duck.xnb Content\BoxingItems\Player_Revolver_Reload.xnb +Content\BoxingItems\BowlerHat_Instance.xnb +Content\Boxing\Bitmaps\Player_Cane_Bitmap.xnb +Content\Boxing\Bitmaps\Player_Cane_Pull_Bitmap.xnb +Content\Boxing\Bitmaps\Player_Punch_Bitmap.xnb Content\Boxing\AB Background.xnb Content\BoxingItems\Player_Cape.xnb Content\BoxingItems\Player_Cape_Stuck.xnb diff --git a/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Boxing/Boxing_Manager.cs b/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Boxing/Boxing_Manager.cs index e959cec..aee2b56 100644 --- a/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Boxing/Boxing_Manager.cs +++ b/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Boxing/Boxing_Manager.cs @@ -557,8 +557,7 @@ public BoxingPlayer GetPlayerInFront(BoxingPlayer p, float y, int direction) public bool Update(GameTime gameTime) { - camera.UpdateCamera(players.ToList(), graphicsDevice); - + switch (state) { // The idle state is just to display the background while the settings are configured. diff --git a/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Camera.cs b/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Camera.cs index 961233a..8bc7699 100644 --- a/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Camera.cs +++ b/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Camera.cs @@ -13,34 +13,45 @@ public class Camera { Rectangle stage; // rectnagle to focus on stage Rectangle fullScreen; // the full screen rectangle - - Rectangle drawToRectangle; // the current focus rectangle - public Rectangle DrawToRectangle { get { return drawToRectangle; } } + Rectangle desiredRec; + Rectangle persistant; + public Rectangle DrawToRectangle { get { return persistant; } } + const int changeratex = 2; // rate at which the camera moves + const int changeratey = 4; + const int inflaterate = 2; // rate at which the camera inflates + const int refreshrate = 1; // in millis. just another way to speedup or slowdown the inflate rate and change rate. affects both + int counter; + const int allowabletolerance_INFLATE = 10; // need to fix camera shaking + const int allowabletolerance_MOVE = 10; + double aspectration; public Camera(Rectangle screenBounds) { fullScreen = screenBounds; - + persistant = screenBounds; stage = new Rectangle( screenBounds.Width / 4, 3 * screenBounds.Height / 7, screenBounds.Width / 2, - screenBounds.Height / 2); + screenBounds.Height / 2); + aspectration = (double)screenBounds.Width / (double)screenBounds.Height; + desiredRec = screenBounds; - this.drawToRectangle = screenBounds; + counter = 0; + } public void FocusStage() { - drawToRectangle = stage; + desiredRec = stage; } public void FocusWholeScreen() { - drawToRectangle = fullScreen; + desiredRec = fullScreen; } - public void UpdateCamera(List players, GraphicsDevice graphicsDevice) + public void UpdateCamera(List players, GraphicsDevice graphicsDevice, GameTime gameTime) { @@ -64,15 +75,6 @@ public void UpdateCamera(List players, GraphicsDevice graphicsDevi int ytop = -1; int ybottom = -1; - - - foreach (Vector2 v in positions) - { - - xavg += (int)(v.X / positions.Count); - yavg += (int)(v.Y / positions.Count); - } - var xlist = new List(); var ylist = new List(); @@ -84,10 +86,10 @@ public void UpdateCamera(List players, GraphicsDevice graphicsDevi }); //change these to add space at the edge of the screen - var ytopbuffer = 2 *players[0].GetHeight; - var xrightbuffer =2* players[0].GetWidth; - var ybottombuffer = 2*players[0].GetHeight; - var xleftbuffer = 2*players[0].GetWidth; + var ytopbuffer = 2 * players[0].GetHeight; + var xrightbuffer = 2 * players[0].GetWidth; + var ybottombuffer = 2 * players[0].GetHeight; + var xleftbuffer = 2 * players[0].GetWidth; //the respective corners of the screen xleft = (int)(xlist.Min() - xleftbuffer); @@ -97,14 +99,12 @@ public void UpdateCamera(List players, GraphicsDevice graphicsDevi //width and height of the screen var width = Math.Abs(xleft - xright); - //if (width < players[0].GetWidth) width = players[0].GetWidth; var height = Math.Abs(ytop - ybottom); - //if (height < players[0].GetHeight) height = players[0].GetHeight; //screen dimensions and aspect ratio - Rectangle screenbounds = graphicsDevice.PresentationParameters.Bounds; - double aspectration = (double)screenbounds.Width / (double)screenbounds.Height; + ///Rectangle screenbounds = graphicsDevice.PresentationParameters.Bounds; + //width = aspectratio * height //height = width / aspectratio @@ -135,26 +135,88 @@ public void UpdateCamera(List players, GraphicsDevice graphicsDevi // edge of the screen if (raw.X <= 0) raw.X = 0; if (raw.Y <= 0) raw.Y = 0; - if (raw.X + raw.Width >= screenbounds.Width) raw.X = screenbounds.Width - raw.Width; - if (raw.Y + raw.Height >= screenbounds.Height) raw.Y = screenbounds.Height - raw.Height; + if (raw.X + raw.Width >= fullScreen.Width) raw.X = fullScreen.Width - raw.Width; + if (raw.Y + raw.Height >= fullScreen.Height) raw.Y = fullScreen.Height - raw.Height; + - - if (raw.X <= 0 && raw.Width >= screenbounds.Width) + if (raw.X <= 0 && raw.Width >= fullScreen.Width) { - raw.Width = screenbounds.Width; + raw.Width = fullScreen.Width; raw.X = 0; } - if (raw.Y <= 0 && raw.Height > screenbounds.Height) + if (raw.Y <= 0 && raw.Height > fullScreen.Height) { - raw.Height = screenbounds.Height; + raw.Height = fullScreen.Height; raw.Y = 0; } //the rectanlge that the render target is drawing to - drawToRectangle = raw; + desiredRec = raw; + Optimize(gameTime); + + } + + + void Optimize(GameTime gameTime) + { + + counter += gameTime.ElapsedGameTime.Milliseconds; + if (counter > refreshrate) + { + counter = 0; + + int widthdiff = desiredRec.Width - persistant.Width; + + if (widthdiff > allowabletolerance_INFLATE) + { + persistant.Inflate(inflaterate, 0); + persistant.Height = (int)(persistant.Width / aspectration); + } + + else if (-widthdiff > allowabletolerance_INFLATE) + { + persistant.Inflate(-inflaterate, 0); + persistant.Height = (int)(persistant.Width / aspectration); + } + + + + + if (desiredRec.Center.X - persistant.Center.X > allowabletolerance_MOVE) + { + persistant.Offset(changeratex, 0); + Console.WriteLine("Xinc"); + } + + else if (persistant.Center.X - desiredRec.Center.X > allowabletolerance_MOVE) + { + persistant.Offset(-changeratex, 0); + Console.WriteLine("Xdec"); + } + + if (desiredRec.Center.Y - persistant.Center.Y > allowabletolerance_MOVE) + { + persistant.Offset(0, changeratey); + Console.WriteLine("Yinc"); + } + + else if (persistant.Center.Y - desiredRec.Center.Y > allowabletolerance_MOVE) + { + persistant.Offset(0, -changeratey); + Console.WriteLine("Ydec"); + } + } + if (persistant.X < 0) persistant.X = 0; + if (persistant.Y < 0) persistant.Y = 0; + + if (persistant.X + persistant.Width > fullScreen.Width) + persistant.X = fullScreen.Width - persistant.Width; + if (persistant.Y + persistant.Height > fullScreen.Height) + persistant.Y = fullScreen.Height - persistant.Height; } + } } diff --git a/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Game.cs b/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Game.cs index ae36d46..0f133af 100644 --- a/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Game.cs +++ b/Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Game.cs @@ -19,7 +19,8 @@ public class Game : Microsoft.Xna.Framework.Game RenderTarget2D renderTarget; public Game_State currentState; public Input_Handler[] inputs; - + Rectangle drawrec; + double aspectratio; public Game() { graphics = new GraphicsDeviceManager(this); @@ -44,7 +45,8 @@ protected override void Initialize() //sm = new State_Manager(Content, Window.ClientBounds); //sm.Initialize(); - + drawrec = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height); + aspectratio = (double)(Window.ClientBounds.Width / Window.ClientBounds.Height); // Initialize the inputs. inputs = new Input_Handler[] { new Input_Handler(0), @@ -87,6 +89,8 @@ protected override void UnloadContent() /// checking for collisions, gathering input, and playing audio. /// /// Provides a snapshot of timing values. + /// + TimeSpan pts = TimeSpan.Zero; protected override void Update(GameTime gameTime) { // Allows the game to exit @@ -98,6 +102,7 @@ protected override void Update(GameTime gameTime) foreach (Input_Handler input in inputs) input.Update(); + currentState.Update(gameTime); @@ -105,7 +110,11 @@ protected override void Update(GameTime gameTime) { Brawl_Game_State b = currentState as Brawl_Game_State; if (b.State == brawlgamestate.brawl) - camera.UpdateCamera(b.boxingManager.Players, GraphicsDevice); + { + + camera.UpdateCamera(b.boxingManager.Players, GraphicsDevice, gameTime); + + } } else camera.FocusWholeScreen(); @@ -113,6 +122,7 @@ protected override void Update(GameTime gameTime) base.Update(gameTime); } + /// /// This is called when the game should draw itself. ///