Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,7 @@ public BoxingPlayer GetPlayerInFront(BoxingPlayer p, float y, int direction)
public bool Update(GameTime gameTime)
{

camera.UpdateCamera(players.ToList<BoxingPlayer>(), graphicsDevice);


switch (state)
{
// The idle state is just to display the background while the settings are configured.
Expand Down
130 changes: 96 additions & 34 deletions Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BoxingPlayer> players, GraphicsDevice graphicsDevice)
public void UpdateCamera(List<BoxingPlayer> players, GraphicsDevice graphicsDevice, GameTime gameTime)
{


Expand All @@ -64,15 +75,6 @@ public void UpdateCamera(List<BoxingPlayer> 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<int>();
var ylist = new List<int>();

Expand All @@ -84,10 +86,10 @@ public void UpdateCamera(List<BoxingPlayer> 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);
Expand All @@ -97,14 +99,12 @@ public void UpdateCamera(List<BoxingPlayer> 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

Expand Down Expand Up @@ -135,26 +135,88 @@ public void UpdateCamera(List<BoxingPlayer> 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;
}


}
}

Expand Down
16 changes: 13 additions & 3 deletions Auction_Boxing_2/Auction_Boxing_2/Auction_Boxing_2/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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),
Expand Down Expand Up @@ -87,6 +89,8 @@ protected override void UnloadContent()
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
///
TimeSpan pts = TimeSpan.Zero;
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
Expand All @@ -98,21 +102,27 @@ protected override void Update(GameTime gameTime)
foreach (Input_Handler input in inputs)
input.Update();



currentState.Update(gameTime);

if (currentState is Brawl_Game_State)
{
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();

base.Update(gameTime);
}


/// <summary>
/// This is called when the game should draw itself.
/// </summary>
Expand Down