Skip to content

Commit

Permalink
Dynamically figure out main menu level
Browse files Browse the repository at this point in the history
  • Loading branch information
DizWARE committed Mar 16, 2011
1 parent 8c77eb4 commit 71e6fcb
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 806 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,23 @@ public void ApplyImmediateForce(Vector2 force)
/// <summary>
/// TEMP METHOD - WILL GIVE THE PLAYER THE ABILITY TO FALL FROM ONE END OF THE SCREEN TO THE OTHER
/// </summary>
public void FixForBounds(int width, int height)
public void FixForBounds(int width, int height, bool isFixed)
{
if (mPosition.X < 0) mPosition.X += width;
if (mPosition.Y < 0) mPosition.Y += height;
if (!isFixed)
{
if (mPosition.X < 0) mPosition.X += width;
if (mPosition.Y < 0) mPosition.Y += height;

mPosition.X %= width;
mPosition.Y %= height;
return;
}

mPosition.X %= width;
mPosition.Y %= height;
if (mPosition.X < 0) { mPosition.X = 0; mVelocity = new Vector2();}
if (mPosition.Y < 0) {mPosition.Y = 0; mVelocity = new Vector2();}
if (mPosition.X + this.mBoundingBox.Width > width) {mPosition.X = width - this.mBoundingBox.Width; mVelocity = new Vector2();}
if (mPosition.Y + this.mBoundingBox.Height > height) { mPosition.Y = height - this.mBoundingBox.Height; mVelocity = new Vector2(); }

}

/// <summary>
Expand Down Expand Up @@ -696,26 +706,18 @@ public virtual int HandleCollideCircleAndBox(GameObject otherObject)
Point centerB = new Point();
if ((center.X < p[0].X) && (center.Y < p[0].Y))// top left corner
{
// and no tile is above me or to the left!!!!!!!!!!!!!!!!!!!!!!!!!TODO
// else return HandleCollideBoxAndBox(otherObject);
centerB = p[0];
}
else if ((center.X > p[1].X) && (center.Y < p[1].Y))// top right corner
{
// and no tile is above me or to the right!!!!!!!!!!!!!!!!!!!!!!!!!TODO
// else return HandleCollideBoxAndBox(otherObject);
centerB = p[1];
}
else if ((center.X > p[2].X) && (center.Y > p[2].Y))// bottom right corner
{
// and no tile is below me or to the right!!!!!!!!!!!!!!!!!!!!!!!!!TODO
// else return HandleCollideBoxAndBox(otherObject);
centerB = p[2];
}
else if ((center.X < p[3].X) && (center.Y > p[3].Y))// bottom left corner
{
// and no tile is below me or to the left!!!!!!!!!!!!!!!!!!!!!!!!!TODO
// else return HandleCollideBoxAndBox(otherObject);
centerB = p[3];
}

Expand All @@ -727,35 +729,7 @@ public virtual int HandleCollideCircleAndBox(GameObject otherObject)
centerDiff.Normalize();
Vector2 add = Vector2.Multiply(centerDiff, delta);


// normal of the collision
Vector2 N = centerDiff;
N.Normalize();
// tangent of the collision
Vector2 T = new Vector2(N.Y, -N.X);

float e = 0.9f;//0.9f; // elasticity of the collision

float vain = Vector2.Dot(this.mVelocity, N);
float vait = Vector2.Dot(this.mVelocity, T);

float vbin = Vector2.Dot(Vector2.Zero, N);
float vbit = Vector2.Dot(Vector2.Zero, T);

float vafn = ((e + 1.0f) * vbin + vain * (1 - e)) / 2;
float vbfn = ((e + 1.0f) * vain - vbin * (1 - e)) / 2;
float vaft = vait;
float vbft = vbit;

if (!mIsRail)
{
this.mVelocity.X = vafn * N.X + vaft * T.X;
this.mVelocity.Y = vafn * N.Y + vaft * T.Y;
}
else if (mOriginalInfo.mProperties[XmlKeys.RAIL] == XmlKeys.RAIL_X)
this.mVelocity.X = vafn * N.X + vaft * T.X;
else
this.mVelocity.Y = vafn * N.Y + vaft * T.Y;
//Do not change velocity because we want an inelastic collision on corners.

// place the Y pos just so it is not colliding.
if (!mIsRail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ protected override void Initialize()

mTitle = new Title(mControls, mGraphics);
mMainMenu = new MainMenu(mControls, mGraphics);
mMainMenuLevel = Level.MainMenuLevel("Content\\Levels\\MainMenu.xml", mControls, mGraphics.GraphicsDevice.Viewport);

mMenu = new Menu(mControls, mGraphics);

//mMenu = new Menu(mControls, mGraphics);
mScoring = new Scoring(mControls);

mWorldSelect = new WorldSelect(mControls, mGraphics);
Expand Down Expand Up @@ -183,12 +182,14 @@ protected override void LoadContent()

mTitle.Load(Content, mGraphics.GraphicsDevice);

mMainMenuLevel.Load(Content);
mMainMenu.Load(Content);
mMainMenuLevel = Level.MainMenuLevel("Content\\Levels\\MainMenu.xml", mControls, mGraphics.GraphicsDevice.Viewport, mMainMenu.GetInnerRegion());

mMainMenuLevel.Load(Content);
mCredits.Load(Content);
mOptions.Load(Content);

mMenu.Load(Content, mGraphics.GraphicsDevice);
//mMenu.Load(Content, mGraphics.GraphicsDevice);
mScoring.Load(Content, mGraphics.GraphicsDevice);
mPause.Load(Content);
GameSound.Load(Content);
Expand Down Expand Up @@ -645,7 +646,7 @@ public void DrawHUD()

//HUDTrans block
mSpriteBatch.Draw(mHUDTrans, new Rectangle(mScreenRect.Left, mScreenRect.Bottom - (int)mLives[0].Height - 10,
(int)livesLength.X + (int)mLives[0].Width * (mCurrentLevel.NumLives+1), (int)mLives[0].Height + 5), Color.White);
(int)livesLength.X + (int)(mLives[0].Width * 0.75f) * (mCurrentLevel.NumLives+1), (int)mLives[0].Height + 5), Color.White);

//Number lives
placement = new Vector2(mScreenRect.Left + 10, mScreenRect.Bottom - (int) mLives[0].Height - 10);
Expand All @@ -656,39 +657,37 @@ public void DrawHUD()
placement = new Vector2(mScreenRect.Left + livesLength.X, mScreenRect.Bottom - (int)mLives[0].Height - 10);
if (mCurrentLevel.NumLives == 5)
{
mSpriteBatch.Draw(mLives[5], new Rectangle((int)(placement.X + mLives[0].Width), (int) placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);
mSpriteBatch.Draw(mLives[5], new Rectangle((int)(placement.X + 2 * mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);
mSpriteBatch.Draw(mLives[5], new Rectangle((int)(placement.X + 3 * mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);
mSpriteBatch.Draw(mLives[5], new Rectangle((int)(placement.X + 4 * mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);
mSpriteBatch.Draw(mLives[5], new Rectangle((int)(placement.X + 5 * mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);
mSpriteBatch.Draw(mLives[5], new Rectangle((int)(placement.X + (mLives[0].Width * 0.75f)), (int) placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
mSpriteBatch.Draw(mLives[5], new Rectangle((int)(placement.X + 2 * (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
mSpriteBatch.Draw(mLives[5], new Rectangle((int)(placement.X + 3 * (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
mSpriteBatch.Draw(mLives[5], new Rectangle((int)(placement.X + 4 * (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
mSpriteBatch.Draw(mLives[5], new Rectangle((int)(placement.X + 5 * (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
}
else if (mCurrentLevel.NumLives == 4)
{
mSpriteBatch.Draw(mLives[4], new Rectangle((int)(placement.X + mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);
mSpriteBatch.Draw(mLives[4], new Rectangle((int)(placement.X + 2 * mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);
mSpriteBatch.Draw(mLives[4], new Rectangle((int)(placement.X + 3 * mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);
mSpriteBatch.Draw(mLives[4], new Rectangle((int)(placement.X + 4 * mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);

mSpriteBatch.Draw(mLives[4], new Rectangle((int)(placement.X + (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
mSpriteBatch.Draw(mLives[4], new Rectangle((int)(placement.X + 2 * (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
mSpriteBatch.Draw(mLives[4], new Rectangle((int)(placement.X + 3 * (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
mSpriteBatch.Draw(mLives[4], new Rectangle((int)(placement.X + 4 * (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
}
else if (mCurrentLevel.NumLives == 3)
{
mSpriteBatch.Draw(mLives[3], new Rectangle((int)(placement.X + mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);
mSpriteBatch.Draw(mLives[3], new Rectangle((int)(placement.X + 2 * mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);
mSpriteBatch.Draw(mLives[3], new Rectangle((int)(placement.X + 3 * mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);

mSpriteBatch.Draw(mLives[3], new Rectangle((int)(placement.X + (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
mSpriteBatch.Draw(mLives[3], new Rectangle((int)(placement.X + 2 * (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
mSpriteBatch.Draw(mLives[3], new Rectangle((int)(placement.X + 3 * (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
}
else if (mCurrentLevel.NumLives == 2)
{
mSpriteBatch.Draw(mLives[2], new Rectangle((int)(placement.X + mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);
mSpriteBatch.Draw(mLives[2], new Rectangle((int)(placement.X + 2 * mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);
mSpriteBatch.Draw(mLives[2], new Rectangle((int)(placement.X + (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
mSpriteBatch.Draw(mLives[2], new Rectangle((int)(placement.X + 2 * (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
}
else if (mCurrentLevel.NumLives == 1)
{
mSpriteBatch.Draw(mLives[1], new Rectangle((int)(placement.X + mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);
mSpriteBatch.Draw(mLives[1], new Rectangle((int)(placement.X + (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
}
else if (mCurrentLevel.NumLives == 0)
{
mSpriteBatch.Draw(mLives[0], new Rectangle((int)(placement.X + mLives[0].Width), (int)placement.Y, (int)(mLives[0].Width * 0.75f), (int)(mLives[0].Height * 0.75f)), Color.White);
mSpriteBatch.Draw(mLives[0], new Rectangle((int)(placement.X + (mLives[0].Width * 0.75f)), (int)placement.Y, (int)(mLives[0].Width * 0.6f), (int)(mLives[0].Height * 0.6f)), Color.White);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Level ImportLevel(Level level)
{
if (item.Name == XmlKeys.NAME)
level.Name = item.Value;
if (item.Name == XmlKeys.SIZE)
if (item.Name == XmlKeys.SIZE && !level.IsMainMenu)
level.Size = GridSpace.GetDrawingCoord(new Vector2(int.Parse(item.Attribute(XName.Get("X", "")).Value),
int.Parse(item.Attribute(XName.Get("Y", "")).Value)));
if (item.Name == XmlKeys.BACKGROUND)
Expand All @@ -71,7 +71,8 @@ public Level ImportLevel(Level level)
mEntities.Add(new EntityInfo(element));
}

GetPlayerStart(level);
if(!level.IsMainMenu)
GetPlayerStart(level);

return level;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,14 @@ private enum DeathStates
private float mDeathPanUpdates;
private static float SCALING_FACTOR = 85;


private bool isCameraFixed = false;
private bool shouldAnimate = true;

public bool IsMainMenu
{
get { return isCameraFixed; }
}
// Camera
public static Camera mCam;

Expand Down Expand Up @@ -457,7 +462,7 @@ public void Update(GameTime gameTime, ref GameStates gameState)
{
PhysicsObject pObject = (PhysicsObject)gObject;

pObject.FixForBounds((int)Size.X, (int)Size.Y);
pObject.FixForBounds((int)Size.X, (int)Size.Y, isCameraFixed);
Vector2 oldPos = GridSpace.GetGridCoord(pObject.mPosition);

if (pObject is Player)
Expand All @@ -467,7 +472,7 @@ public void Update(GameTime gameTime, ref GameStates gameState)
pObject.Update(gameTime);

// Update zoom based on players velocity
pObject.FixForBounds((int)Size.X, (int)Size.Y);
pObject.FixForBounds((int)Size.X, (int)Size.Y, isCameraFixed);
UpdateCollisionMatrix(pObject, oldPos);

// handle collision right after you move
Expand Down Expand Up @@ -982,11 +987,13 @@ private AnimatedSprite GetAnimation(string name)
return newAnimation;
}

public static Level MainMenuLevel(string filepath, IControlScheme controls, Viewport viewport)
public static Level MainMenuLevel(string filepath, IControlScheme controls, Viewport viewport, Rectangle region)
{
Level main = new Level(filepath,controls,viewport);
main.isCameraFixed = true;
main.shouldAnimate = false;
main.Size = new Vector2(region.Width*33/32, region.Height*7/8);
main.mStartingPoint = new Vector2(region.Width/2, region.Height/8);
return main;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,21 @@ public Rectangle GetRegion(MenuChoices choice, Texture2D texture)
viewport.TitleSafeArea.Center.Y + (int)(mTitle.Height * mSize[1]) / 2 - ((int)(texture.Height * mSize[1]) / 2), (int)(texture.Width * mSize[0]), (int)(texture.Height * mSize[1]));
return new Rectangle();
}

/// <summary>
/// Gets the rectangle between the menu options
/// </summary>
/// <returns>Rectangle between menu choices</returns>
public Rectangle GetInnerRegion()
{
Rectangle topRectangle = GetRegion(MenuChoices.Exit, mSelected[MenuChoices.Exit]);
Rectangle leftRectangle = GetRegion(MenuChoices.Credits, mSelected[MenuChoices.Credits]);
Rectangle rightRectangle = GetRegion(MenuChoices.Options, mSelected[MenuChoices.Options]);
Rectangle bottomRectangle = GetRegion(MenuChoices.StartGame, mSelected[MenuChoices.StartGame]);

Rectangle region = new Rectangle(leftRectangle.Left, topRectangle.Top,
rightRectangle.Right - leftRectangle.Left,bottomRectangle.Bottom - topRectangle.Top);
return region;
}
}
}
Loading

0 comments on commit 71e6fcb

Please sign in to comment.