Skip to content

Commit

Permalink
Code style cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoatease committed Jun 7, 2015
1 parent 87b420f commit c954a28
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 133 deletions.
38 changes: 17 additions & 21 deletions breakout/breakout/Breakout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ namespace breakout {
/// Class Breakout.
/// </summary>
public class Breakout : Game {
/// <summary>
/// The graphics
/// </summary>
GraphicsDeviceManager graphics;
/// <summary>
/// The sprite batch
/// </summary>
Expand All @@ -49,14 +45,16 @@ public class Breakout : Game {
/// The sounds
/// </summary>
private Sounds sounds;

/// <summary>
/// The song start
/// </summary>
private bool songStart = false;
private bool songStart;

/// <summary>
/// The Mute song
/// </summary>
private bool muteSong = false;
private bool muteSong;

/// <summary>
/// The game state
Expand Down Expand Up @@ -138,9 +136,11 @@ public class Breakout : Game {
/// Initializes a new instance of the <see cref="Breakout"/> class.
/// </summary>
public Breakout() {
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = 800;
graphics.PreferredBackBufferHeight = 600;
new GraphicsDeviceManager(this)
{
PreferredBackBufferWidth = 800,
PreferredBackBufferHeight = 600
};

Content.RootDirectory = "Content";
int screenWidth = Window.ClientBounds.Width;
Expand Down Expand Up @@ -296,9 +296,9 @@ protected override void Update(GameTime gameTime) {
}

foreach(Brick b in gameLevel.BricksMap){
if (b.Bonus.Activated == true)
if (b.Bonus.Activated)
{
b.Bonus.Update(gameTime, gameLevel.Bat.Hitbox, gameLevel, b);
b.Bonus.Update(gameTime, gameLevel.Bat.Hitbox, gameLevel);
}
}
gameLevel.Bat.HandleInput(keyboardState, previousKeyboardState);
Expand Down Expand Up @@ -374,8 +374,6 @@ protected override void Update(GameTime gameTime) {
case GameState.EXIT:
this.Exit();
break;
default:
break;
}


Expand Down Expand Up @@ -576,7 +574,7 @@ protected override void Draw(GameTime gameTime) {

foreach (Brick b in gameLevel.BricksMap)
{
if (b.Bonus.Activated == true)
if (b.Bonus.Activated)
{
b.Bonus.Draw(spriteBatch, gameTime);
}
Expand All @@ -598,7 +596,7 @@ protected override void Draw(GameTime gameTime) {

foreach (Brick b in gameLevel.BricksMap)
{
if (b.Bonus.Activated == true)
if (b.Bonus.Activated)
{
b.Bonus.Draw(spriteBatch, gameTime);
}
Expand All @@ -624,7 +622,7 @@ protected override void Draw(GameTime gameTime) {

foreach (Brick b in gameLevel.BricksMap)
{
if (b.Bonus.Activated == true)
if (b.Bonus.Activated)
{
b.Bonus.Draw(spriteBatch, gameTime);
}
Expand All @@ -647,8 +645,6 @@ protected override void Draw(GameTime gameTime) {
exitButton.Draw(spriteBatch, gameTime);
menuArrow.Draw(spriteBatch, gameTime);
break;
default:
break;
}
spriteBatch.End();

Expand Down Expand Up @@ -698,11 +694,11 @@ private void PutBricksTexture()
/// <summary>
/// Gets the lives.
/// </summary>
/// <param name="spriteBatch">The sprite batch.</param>
/// <param name="batch">The sprite batch.</param>
/// <param name="gameTime">The game time.</param>
private void GetLives(ref SpriteBatch spriteBatch, GameTime gameTime)
private void GetLives(ref SpriteBatch batch, GameTime gameTime)
{
livesSprites[gameLevel.Lives].Draw(spriteBatch, gameTime);
livesSprites[gameLevel.Lives].Draw(batch, gameTime);

}
}
Expand Down
1 change: 0 additions & 1 deletion breakout/breakout/DefaultLevels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Configuration;
using System.Reflection;
using breakout.Util;

Expand Down
14 changes: 7 additions & 7 deletions breakout/breakout/GameComponents/Ball.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Ball(int screenWidth, int screenHeight) : base(screenWidth, screenHeight)
/// </summary>
/// <param name="ball">The ball.</param>
public Ball(Ball ball)
: base(ball.screenWidth, ball.screenHeight) {
: base(ball.ScreenWidth, ball.ScreenHeight) {
this.Position = ball.Position;
this.Texture = ball.Texture;
this.Direction = -ball.Direction;
Expand Down Expand Up @@ -119,12 +119,12 @@ public void Update(GameTime gameTime, Rectangle batHitBox, GameLevel gameLevel,
/// <param name="gameLevel">The game level.</param>
private void BouncingOnTheWalls(GameLevel gameLevel) {
if ((Position.Y <= 0 && Direction.Y < 0)) {
this.sm.bump.Play(0.5f, 0.0f, 0.0f);
this.sm.Bump.Play(0.5f, 0.0f, 0.0f);
Direction = new Vector2(Direction.X, -Direction.Y);
gameLevel.Score -= 10;
}
if (Position.X <= 0 && Direction.X < 0 || Position.X > screenWidth - Texture.Height && Direction.X > 0) {
this.sm.bump.Play(0.5f, 0.0f, 0.0f);
if (Position.X <= 0 && Direction.X < 0 || Position.X > ScreenWidth - Texture.Height && Direction.X > 0) {
this.sm.Bump.Play(0.5f, 0.0f, 0.0f);
Direction = new Vector2(-Direction.X, Direction.Y);
gameLevel.Score -= 10;
}
Expand All @@ -137,7 +137,7 @@ private void BouncingOnTheBat(Rectangle batHitBox) {
if ((Direction.Y > 0 && this.hitbox.IntersectsRec(batHitBox))) {
Direction = new Vector2(((float)hitbox.X - batHitBox.Center.X) / (batHitBox.Width / 2), -Direction.Y);
Direction = Vector2.Normalize(Direction);
this.sm.bump.Play(0.5f, 0.0f, 0.0f);
this.sm.Bump.Play(0.5f, 0.0f, 0.0f);
}
}

Expand All @@ -151,9 +151,9 @@ private List<Brick> GetTouchedBricks(GameLevel gameLevel) {
foreach (Brick b in gameLevel.BricksMap) {
if (this.hitbox.IntersectsRec(b.Hitbox) && b.Resistance > 0) {
if (b.Resistance == 4) {
this.sm.bump.Play(0.5f, 0.0f, 0.0f);
this.sm.Bump.Play(0.5f, 0.0f, 0.0f);
} else {
this.sm.bumpBrick.Play(0.5f, 0.0f, 0.0f);
this.sm.BumpBrick.Play(0.5f, 0.0f, 0.0f);
}

if (b.Bonus.Type != BonusType.NONE && b.Bonus.Activated == false) {
Expand Down
16 changes: 2 additions & 14 deletions breakout/breakout/GameComponents/Bat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public class Bat : MovingSprite {
/// </summary>
private Vector2 acceleration = Vector2.Zero;
/// <summary>
/// Gets or sets the acceleration.
/// </summary>
/// <value>The acceleration.</value>
public Vector2 Acceleration { get { return acceleration; } set { acceleration = value; } }
/// <summary>
/// Gets the hitbox.
/// </summary>
/// <value>The hitbox.</value>
Expand All @@ -56,21 +51,14 @@ public Rectangle Hitbox {
/// <param name="screenHeight">Height of the screen.</param>
public Bat(int screenWidth, int screenHeight) : base(screenWidth, screenHeight) { }

/// <summary>
/// Initializes this instance and sets a default position at the top right of the screen and a zero direction/speed.
/// </summary>
public override void Initialize() {
base.Initialize();
}

/// <summary>
/// Loads the content common to every sprite of our game, the texture 2D
/// </summary>
/// <param name="content">The content manager.</param>
/// <param name="assetName">Name of the asset.</param>
public override void LoadContent(ContentManager content, string assetName) {
base.LoadContent(content, assetName);
Position = new Vector2(screenWidth / 2 - Texture.Width / 2, screenHeight - 10 - Texture.Height / 2);
Position = new Vector2(ScreenWidth / 2 - Texture.Width / 2, ScreenHeight - 10 - Texture.Height / 2);
}

/// <summary>
Expand Down Expand Up @@ -113,7 +101,7 @@ public override void HandleInput(KeyboardState keyboardState, KeyboardState prev
/// </summary>
/// <param name="gameTime">The game time.</param>
public override void Update(GameTime gameTime) {
if ((position.X <= 0 && direction.X < 0) || (position.X >= screenWidth - Texture.Width && direction.X > 0)) {
if ((position.X <= 0 && direction.X < 0) || (position.X >= ScreenWidth - Texture.Width && direction.X > 0)) {
speed = 0;
acceleration = Vector2.Zero;
}
Expand Down
29 changes: 11 additions & 18 deletions breakout/breakout/GameComponents/Bonus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public BonusType Type
/// <summary>
/// The activated
/// </summary>
private bool activated = false;
private bool activated;
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Bonus"/> is activated.
/// </summary>
Expand All @@ -84,13 +84,6 @@ private Rectangle hitbox
get { return new Rectangle((int)Position.X, (int)Position.Y, Texture.Width, Texture.Height); }
}

/// <summary>
/// Initializes a new instance of the <see cref="Sprite" /> class.
/// </summary>
/// <param name="screenWidth">Width of the screen.</param>
/// <param name="screenHeight">Height of the screen.</param>
public Bonus(int screenWidth, int screenHeight) : base(screenWidth, screenHeight) { }

/// <summary>
/// Initializes a new instance of the <see cref="Bonus"/> class.
/// </summary>
Expand Down Expand Up @@ -122,22 +115,22 @@ public override void LoadContent(ContentManager content, String assetName)
/// <param name="batHitBox">The bat hit box.</param>
/// <param name="gameLevel">The game level.</param>
/// <param name="brick">The brick.</param>
public void Update(GameTime gameTime, Rectangle batHitBox, GameLevel gameLevel, Brick brick)
public void Update(GameTime gameTime, Rectangle batHitBox, GameLevel gameLevel)
{
Direction = new Vector2(0, 1);
if (this.hitbox.Intersects(batHitBox))
{
switch (this.Type)
{
case BonusType.HIGH_SPEED:
this.sm.powerDown.Play();
this.sm.PowerDown.Play();
foreach (Ball b in gameLevel.Balls)
{
b.Speed *= 1.5f;
}
break;
case BonusType.HIGH_RESISTANCE:
this.sm.powerDown.Play();
this.sm.PowerDown.Play();
foreach (Brick b in gameLevel.BricksMap)
{
if (b.Resistance != 0 && b.Resistance != 4)
Expand All @@ -148,22 +141,22 @@ public void Update(GameTime gameTime, Rectangle batHitBox, GameLevel gameLevel,
}
break;
case BonusType.BAT_REDUCED:
this.sm.powerDown.Play();
this.sm.PowerDown.Play();
gameLevel.Bat.Texture = gameLevel.BatTexture.Reduced;
break;
case BonusType.BAT_EXTENDED:
this.sm.powerUp.Play();
this.sm.PowerUp.Play();
gameLevel.Bat.Texture = gameLevel.BatTexture.Extended;
break;
case BonusType.DOWN_LIFE:
this.sm.powerDown.Play();
this.sm.PowerDown.Play();
if (gameLevel.Lives > 0)
{
gameLevel.Lives--;
}
break;
case BonusType.LOW_RESISTANCE:
this.sm.powerUp.Play();
this.sm.PowerUp.Play();
foreach (Brick b in gameLevel.BricksMap)
{
if (b.Resistance != 0 && b.Resistance != 4)
Expand All @@ -174,14 +167,14 @@ public void Update(GameTime gameTime, Rectangle batHitBox, GameLevel gameLevel,
}
break;
case BonusType.LOW_SPEED:
this.sm.powerUp.Play();
this.sm.PowerUp.Play();
foreach (Ball b in gameLevel.Balls)
{
b.Speed /= 1.5f;
}
break;
case BonusType.UP_LIFE:
this.sm.powerUp.Play();
this.sm.PowerUp.Play();
if (gameLevel.Lives < 4)
{
gameLevel.Lives++;
Expand All @@ -199,7 +192,7 @@ public void Update(GameTime gameTime, Rectangle batHitBox, GameLevel gameLevel,

Type = BonusType.NONE;
Activated = false;
} else if(Position.Y >= screenHeight/0.6){
} else if(Position.Y >= ScreenHeight/0.6){
Activated = false;
}

Expand Down
31 changes: 1 addition & 30 deletions breakout/breakout/GameComponents/Brick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ namespace breakout.GameComponents
/// </summary>
public class Brick : Sprite
{
/// <summary>
/// Gets or sets the height.
/// </summary>
/// <value>The height.</value>
private int height { get; set; }
/// <summary>
/// Gets or sets the width.
/// </summary>
/// <value>The width.</value>
private int width { get; set; }

/// <summary>
/// Gets or sets the bonus.
/// </summary>
Expand Down Expand Up @@ -71,23 +60,13 @@ public Rectangle Hitbox
/// <param name="w">The w.</param>
/// <param name="r">The r.</param>
/// <param name="b">The b.</param>
public Brick(int screenWidth, int screenHeight, Vector2 position, int h, int w, int r = 1, BonusType b = BonusType.NONE) : base( screenWidth, screenHeight)
public Brick(int screenWidth, int screenHeight, Vector2 position, int r = 1, BonusType b = BonusType.NONE) : base( screenWidth, screenHeight)
{
this.height = h;
this.width = w;
this.Position = position;
this.Resistance = r;
this.Bonus = new Bonus(screenWidth, screenHeight, b);
}

/// <summary>
/// Initializes this instance and sets a default position at the top right of the screen.
/// </summary>
public override void Initialize()
{
base.Initialize();
}

/// <summary>
/// Draws the sprite.
/// </summary>
Expand Down Expand Up @@ -157,13 +136,5 @@ public int UpdateTexture(BrickTexture textures)
}
return newScore;
}

/// <summary>
/// Updates this instance.
/// </summary>
public override void Update()
{
base.Update();
}
}
}
Loading

0 comments on commit c954a28

Please sign in to comment.