Skip to content
Browse files

Tabs to spaces

  • Loading branch information...
1 parent 013eebd commit f681fe5faeea62f88fdcade8a278f886dddd3fb9 @daniellee committed Mar 26, 2012
View
52 BallBounceMVC.Test/PlayerModelTests.cs
@@ -3,39 +3,39 @@
namespace BallBounceMVC.Test
{
- [TestFixture]
- public class PlayerModelTests
- {
- private World _world;
- private PlayerModel _playerModel;
+ [TestFixture]
+ public class PlayerModelTests
+ {
+ private World _world;
+ private PlayerModel _playerModel;
- [SetUp]
- public void Setup()
- {
- _world = new World(800, 600) { GameSpeed = 1f };
+ [SetUp]
+ public void Setup()
+ {
+ _world = new World(800, 600) { GameSpeed = 1f };
- _playerModel = new PlayerModel(_world);
- }
+ _playerModel = new PlayerModel(_world);
+ }
- [Test]
- public void PlayerShouldNotGoFurtherLeftThanTheLeftSideOfTheFrame()
- {
- _playerModel.Update(-10000000);
+ [Test]
+ public void PlayerShouldNotGoFurtherLeftThanTheLeftSideOfTheFrame()
+ {
+ _playerModel.Update(-10000000);
- var expected = _world.GetFrameModel().GetLeftWallRectangle().Right;
+ var expected = _world.GetFrameModel().GetLeftWallRectangle().Right;
- Assert.That(_playerModel.GetShip().X, Is.EqualTo(expected));
- }
+ Assert.That(_playerModel.GetShip().X, Is.EqualTo(expected));
+ }
- [Test]
- public void PlayerShouldNotGoFurtherRightThanTheRightSideOfTheFrame()
- {
- _playerModel.Update(10000000);
+ [Test]
+ public void PlayerShouldNotGoFurtherRightThanTheRightSideOfTheFrame()
+ {
+ _playerModel.Update(10000000);
- var expected = _world.GetFrameModel().GetRightWallRectangle().Left - _playerModel.GetShip().Width;
+ var expected = _world.GetFrameModel().GetRightWallRectangle().Left - _playerModel.GetShip().Width;
- Assert.That(_playerModel.GetShip().X, Is.EqualTo(expected));
- }
+ Assert.That(_playerModel.GetShip().X, Is.EqualTo(expected));
+ }
- }
+ }
}
View
218 BallBounceMVC/BallBounceMVC/BallBounceGame.cs
@@ -7,113 +7,113 @@
namespace BallBounceMVC
{
- /// <summary>
- /// This is the main type for your game
- /// </summary>
- public class BallBounceGame : Game
- {
- readonly GraphicsDeviceManager _graphics;
- SpriteBatch _spriteBatch;
- private World _world;
- private BallsViewer _ballsViewer;
- private WorldViewer _worldViewer;
- private Texture2D _ballTexture;
- private Texture2D _frameTexture;
- private FrameViewer _frameViewer;
- private PlayerController _playerController;
- private Texture2D _playerTexture;
- private PlayerViewer _playerViewer;
-
-
- public BallBounceGame()
- {
- _graphics = new GraphicsDeviceManager(this) {PreferredBackBufferWidth = 800, PreferredBackBufferHeight = 600};
- Content.RootDirectory = "Content";
- }
-
- /// <summary>
- /// Allows the game to perform any initialization it needs to before starting to run.
- /// This is where it can query for any required services and load any non-graphic
- /// related content. Calling base.Initialize will enumerate through any components
- /// and initialize them as well.
- /// </summary>
- protected override void Initialize()
- {
- // TODO: Add your initialization logic here
-
- base.Initialize();
- }
-
- /// <summary>
- /// LoadContent will be called once per game and is the place to load
- /// all of your content.
- /// </summary>
- protected override void LoadContent()
- {
- // Create a new SpriteBatch, which can be used to draw textures.
- _spriteBatch = new SpriteBatch(GraphicsDevice);
-
- _world = new World(_graphics.GraphicsDevice.Viewport.Width, _graphics.GraphicsDevice.Viewport.Height);
-
- BallsModel ballsModel = _world.GetBallsModel();
- _ballTexture = Content.Load<Texture2D>("Sprites\\SilverBall");
- _ballsViewer = new BallsViewer(ballsModel.GetAllBalls(), _ballTexture);
-
- _frameTexture = Content.Load<Texture2D>("Frame\\titanium");
- _frameViewer = new FrameViewer(_world.GetFrameModel(), _frameTexture);
- _worldViewer = new WorldViewer();
-
- _playerTexture = Content.Load<Texture2D>("Sprites\\PlayerShip");
- PlayerModel playerModel = _world.GetPlayerModel();
- _playerController = new PlayerController(playerModel);
- _playerViewer = new PlayerViewer(playerModel, _playerTexture);
- }
-
- /// <summary>
- /// UnloadContent will be called once per game and is the place to unload
- /// all content.
- /// </summary>
- protected override void UnloadContent()
- {
- _ballTexture.Dispose();
- _frameTexture.Dispose();
- _playerTexture.Dispose();
- base.UnloadContent();
- }
-
- /// <summary>
- /// Allows the game to run logic such as updating the world,
- /// checking for collisions, gathering input, and playing audio.
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- protected override void Update(GameTime gameTime)
- {
- // Allows the game to exit
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
- Exit();
-
- _world.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
- _playerController.Control((float)gameTime.ElapsedGameTime.TotalSeconds);
-
- base.Update(gameTime);
- }
-
- /// <summary>
- /// This is called when the game should draw itself.
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
-
- _spriteBatch.Begin();
- _worldViewer.Draw(_spriteBatch);
- _frameViewer.Draw(_spriteBatch);
- _ballsViewer.Draw(_spriteBatch);
- _playerViewer.Draw(_spriteBatch);
- _spriteBatch.End();
-
- base.Draw(gameTime);
- }
- }
+ /// <summary>
+ /// This is the main type for your game
+ /// </summary>
+ public class BallBounceGame : Game
+ {
+ readonly GraphicsDeviceManager _graphics;
+ SpriteBatch _spriteBatch;
+ private World _world;
+ private BallsViewer _ballsViewer;
+ private WorldViewer _worldViewer;
+ private Texture2D _ballTexture;
+ private Texture2D _frameTexture;
+ private FrameViewer _frameViewer;
+ private PlayerController _playerController;
+ private Texture2D _playerTexture;
+ private PlayerViewer _playerViewer;
+
+
+ public BallBounceGame()
+ {
+ _graphics = new GraphicsDeviceManager(this) { PreferredBackBufferWidth = 800, PreferredBackBufferHeight = 600 };
+ Content.RootDirectory = "Content";
+ }
+
+ /// <summary>
+ /// Allows the game to perform any initialization it needs to before starting to run.
+ /// This is where it can query for any required services and load any non-graphic
+ /// related content. Calling base.Initialize will enumerate through any components
+ /// and initialize them as well.
+ /// </summary>
+ protected override void Initialize()
+ {
+ // TODO: Add your initialization logic here
+
+ base.Initialize();
+ }
+
+ /// <summary>
+ /// LoadContent will be called once per game and is the place to load
+ /// all of your content.
+ /// </summary>
+ protected override void LoadContent()
+ {
+ // Create a new SpriteBatch, which can be used to draw textures.
+ _spriteBatch = new SpriteBatch(GraphicsDevice);
+
+ _world = new World(_graphics.GraphicsDevice.Viewport.Width, _graphics.GraphicsDevice.Viewport.Height);
+
+ BallsModel ballsModel = _world.GetBallsModel();
+ _ballTexture = Content.Load<Texture2D>("Sprites\\SilverBall");
+ _ballsViewer = new BallsViewer(ballsModel.GetAllBalls(), _ballTexture);
+
+ _frameTexture = Content.Load<Texture2D>("Frame\\titanium");
+ _frameViewer = new FrameViewer(_world.GetFrameModel(), _frameTexture);
+ _worldViewer = new WorldViewer();
+
+ _playerTexture = Content.Load<Texture2D>("Sprites\\PlayerShip");
+ PlayerModel playerModel = _world.GetPlayerModel();
+ _playerController = new PlayerController(playerModel);
+ _playerViewer = new PlayerViewer(playerModel, _playerTexture);
+ }
+
+ /// <summary>
+ /// UnloadContent will be called once per game and is the place to unload
+ /// all content.
+ /// </summary>
+ protected override void UnloadContent()
+ {
+ _ballTexture.Dispose();
+ _frameTexture.Dispose();
+ _playerTexture.Dispose();
+ base.UnloadContent();
+ }
+
+ /// <summary>
+ /// Allows the game to run logic such as updating the world,
+ /// checking for collisions, gathering input, and playing audio.
+ /// </summary>
+ /// <param name="gameTime">Provides a snapshot of timing values.</param>
+ protected override void Update(GameTime gameTime)
+ {
+ // Allows the game to exit
+ if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
+ Exit();
+
+ _world.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
+ _playerController.Control((float)gameTime.ElapsedGameTime.TotalSeconds);
+
+ base.Update(gameTime);
+ }
+
+ /// <summary>
+ /// This is called when the game should draw itself.
+ /// </summary>
+ /// <param name="gameTime">Provides a snapshot of timing values.</param>
+ protected override void Draw(GameTime gameTime)
+ {
+ GraphicsDevice.Clear(Color.CornflowerBlue);
+
+ _spriteBatch.Begin();
+ _worldViewer.Draw(_spriteBatch);
+ _frameViewer.Draw(_spriteBatch);
+ _ballsViewer.Draw(_spriteBatch);
+ _playerViewer.Draw(_spriteBatch);
+ _spriteBatch.End();
+
+ base.Draw(gameTime);
+ }
+ }
}
View
41 BallBounceMVC/BallBounceMVC/Controllers/PlayerController.cs
@@ -1,30 +1,29 @@
-using System;
using BallBounceMVC.Models;
using Microsoft.Xna.Framework.Input;
namespace BallBounceMVC.Controllers
{
- public class PlayerController : ModelController
- {
- private readonly PlayerModel _playerModel;
- private MouseState _previousMouseState;
+ public class PlayerController : ModelController
+ {
+ private readonly PlayerModel _playerModel;
+ private MouseState _previousMouseState;
- public PlayerController(PlayerModel playerModel)
- {
- _playerModel = playerModel;
- _previousMouseState = Mouse.GetState();
- }
+ public PlayerController(PlayerModel playerModel)
+ {
+ _playerModel = playerModel;
+ _previousMouseState = Mouse.GetState();
+ }
- public override void Control(float elapsedSeconds)
- {
- MouseState currentMouseState = Mouse.GetState();
- if (currentMouseState != _previousMouseState)
- {
- float xDifference = currentMouseState.X - _previousMouseState.X;
- _playerModel.Update(xDifference);
- }
+ public override void Control(float elapsedSeconds)
+ {
+ MouseState currentMouseState = Mouse.GetState();
+ if (currentMouseState != _previousMouseState)
+ {
+ float xDifference = currentMouseState.X - _previousMouseState.X;
+ _playerModel.Update(xDifference);
+ }
- _previousMouseState = currentMouseState;
- }
- }
+ _previousMouseState = currentMouseState;
+ }
+ }
}
View
100 BallBounceMVC/BallBounceMVC/Entities/Ball.cs
@@ -4,61 +4,61 @@
namespace BallBounceMVC.Entities
{
- public class Ball : GameObject
- {
- public int Width { get; set; }
- public int Height { get; set; }
+ public class Ball : GameObject
+ {
+ public int Width { get; set; }
+ public int Height { get; set; }
- public Ball(int width, int height, Vector2 startPosition, Vector2 startDirection)
- {
- Width = width;
- Height = height;
- Position = startPosition;
- Velocity = startDirection;
- }
+ public Ball(int width, int height, Vector2 startPosition, Vector2 startDirection)
+ {
+ Width = width;
+ Height = height;
+ Position = startPosition;
+ Velocity = startDirection;
+ }
- public void HandleCollisionWithAnyGameObject(World world)
- {
- var ballRectangle = new Rectangle((int) Position.X, (int) Position.Y, Width, Height);
- var frame = world.GetFrameModel();
- if (frame.IntersectsWithTopWall(ballRectangle))
- {
- ChangeVelocityToDown();
- }
- if (frame.IntersectsWithLeftWall(ballRectangle))
- {
- ChangeVelocityToRight();
- }
+ public void HandleCollisionWithAnyGameObject(World world)
+ {
+ var ballRectangle = new Rectangle((int)Position.X, (int)Position.Y, Width, Height);
+ var frame = world.GetFrameModel();
+ if (frame.IntersectsWithTopWall(ballRectangle))
+ {
+ ChangeVelocityToDown();
+ }
+ if (frame.IntersectsWithLeftWall(ballRectangle))
+ {
+ ChangeVelocityToRight();
+ }
- if (frame.IntersectsWithRightWall(ballRectangle))
- {
- ChangeVelocityToLeft();
- }
+ if (frame.IntersectsWithRightWall(ballRectangle))
+ {
+ ChangeVelocityToLeft();
+ }
- var player = world.GetPlayerModel();
- if(player.IntersectsWith(ballRectangle))
- {
- if (Math.Sign(Velocity.Y) >= 0)
- Velocity.Y = -(Velocity.Y);
- }
- }
+ var player = world.GetPlayerModel();
+ if (player.IntersectsWith(ballRectangle))
+ {
+ if (Math.Sign(Velocity.Y) >= 0)
+ Velocity.Y = -(Velocity.Y);
+ }
+ }
- private void ChangeVelocityToLeft()
- {
- if (Math.Sign(Velocity.X) >= 0)
- Velocity.X = -(Velocity.X);
- }
+ private void ChangeVelocityToLeft()
+ {
+ if (Math.Sign(Velocity.X) >= 0)
+ Velocity.X = -(Velocity.X);
+ }
- private void ChangeVelocityToRight()
- {
- if (Math.Sign(Velocity.X) <= 0)
- Velocity.X = -(Velocity.X);
- }
+ private void ChangeVelocityToRight()
+ {
+ if (Math.Sign(Velocity.X) <= 0)
+ Velocity.X = -(Velocity.X);
+ }
- private void ChangeVelocityToDown()
- {
- if (Math.Sign(Velocity.Y) <= 0)
- Velocity.Y = -(Velocity.Y);
- }
- }
+ private void ChangeVelocityToDown()
+ {
+ if (Math.Sign(Velocity.Y) <= 0)
+ Velocity.Y = -(Velocity.Y);
+ }
+ }
}
View
18 BallBounceMVC/BallBounceMVC/Entities/GameObject.cs
@@ -1,10 +1,10 @@
-using Microsoft.Xna.Framework;
-
-namespace BallBounceMVC.Entities
-{
- public abstract class GameObject
- {
- public Vector2 Position { get; set; }
- public Vector2 Velocity;
- }
+using Microsoft.Xna.Framework;
+
+namespace BallBounceMVC.Entities
+{
+ public abstract class GameObject
+ {
+ public Vector2 Position { get; set; }
+ public Vector2 Velocity;
+ }
}
View
141 BallBounceMVC/BallBounceMVC/Models/BallsModel.cs
@@ -4,85 +4,86 @@
namespace BallBounceMVC.Models
{
- public class BallsModel : Model
- {
- private readonly int _width;
- private readonly int _height;
- private readonly Vector2 _startPosition;
- private readonly Vector2 _startDirection;
- private readonly IList<Ball> _balls;
- private readonly World _world;
+ public class BallsModel : Model
+ {
+ private readonly int _width;
+ private readonly int _height;
+ private readonly Vector2 _startPosition;
+ private readonly Vector2 _startDirection;
+ private readonly IList<Ball> _balls;
+ private readonly World _world;
- public BallsModel(World world, int width, int height, Vector2 startPosition, Vector2 startDirection): base(world)
- {
- _world = world;
- _width = width;
- _height = height;
- _startPosition = startPosition;
- _startDirection = startDirection;
- _balls = new List<Ball>();
- Add(new Ball(_width, _height, _startPosition, _startDirection));
- }
+ public BallsModel(World world, int width, int height, Vector2 startPosition, Vector2 startDirection)
+ : base(world)
+ {
+ _world = world;
+ _width = width;
+ _height = height;
+ _startPosition = startPosition;
+ _startDirection = startDirection;
+ _balls = new List<Ball>();
+ Add(new Ball(_width, _height, _startPosition, _startDirection));
+ }
- public override void Update(float elapsedSeconds)
- {
- for (int i = _balls.Count-1;i>=0;i--)
- {
- var ball = _balls[i];
- ball.Position += ball.Velocity * (World.GameSpeed);
- if (IsBallDead(ball))
- {
- HandleBallDeath(ball);
- }
- else
- {
- ball.HandleCollisionWithAnyGameObject(_world);
- }
- }
- }
+ public override void Update(float elapsedSeconds)
+ {
+ for (int i = _balls.Count - 1; i >= 0; i--)
+ {
+ var ball = _balls[i];
+ ball.Position += ball.Velocity * (World.GameSpeed);
+ if (IsBallDead(ball))
+ {
+ HandleBallDeath(ball);
+ }
+ else
+ {
+ ball.HandleCollisionWithAnyGameObject(_world);
+ }
+ }
+ }
- private void HandleBallDeath(Ball ball)
- {
- Remove(ball);
- if(_balls.Count == 0)
- _world.Lives--;
- }
+ private void HandleBallDeath(Ball ball)
+ {
+ Remove(ball);
+ if (_balls.Count == 0)
+ _world.Lives--;
+ }
- private void Remove(Ball ball)
- {
- _balls.Remove(ball);
- }
+ private void Remove(Ball ball)
+ {
+ _balls.Remove(ball);
+ }
- private bool IsBallDead(Ball ball)
- {
- Rectangle viewport = _world.GetViewport();
+ private bool IsBallDead(Ball ball)
+ {
+ Rectangle viewport = _world.GetViewport();
- return !viewport.Contains(new Point(
- (int)ball.Position.X,
- (int)ball.Position.Y));
- }
+ return !viewport.Contains(new Point(
+ (int)ball.Position.X,
+ (int)ball.Position.Y));
+ }
- public IList<Ball> GetAllBalls()
- {
- return _balls;
- }
+ public IList<Ball> GetAllBalls()
+ {
+ return _balls;
+ }
- public Ball GetBall(int index)
- {
- return _balls[index];
- }
+ public Ball GetBall(int index)
+ {
+ return _balls[index];
+ }
- public Ball GetFirstBall()
- {
- if (_balls.Count == 0)
- return null;
+ public Ball GetFirstBall()
+ {
+ if (_balls.Count == 0)
+ return null;
- return _balls[0];
- }
+ return _balls[0];
+ }
- public void Add(Ball ball)
- {
- _balls.Add(ball);
- }
- }
+ public void Add(Ball ball)
+ {
+ _balls.Add(ball);
+ }
+ }
}
View
126 BallBounceMVC/BallBounceMVC/Models/FrameModel.cs
@@ -1,64 +1,64 @@
-using System;
-using Microsoft.Xna.Framework;
-
-namespace BallBounceMVC.Models
-{
- public class FrameModel: Model
- {
- private readonly Rectangle _topWall, _leftWall, _rightWall;
- private const int WallWidth = 11;
-
- public FrameModel(World world)
- : base(world)
- {
- Rectangle viewport = world.GetViewport();
- _topWall = new Rectangle(viewport.Left + WallWidth, viewport.Top, viewport.Width - (WallWidth * 2), WallWidth);
- _leftWall = new Rectangle(viewport.Left, viewport.Top, WallWidth, viewport.Height);
- _rightWall = new Rectangle(viewport.Right - WallWidth, viewport.Top, WallWidth, viewport.Height);
- }
-
- public override void Update(float elapsedSeconds)
- {
- throw new NotImplementedException();
- }
-
- public bool IntersectsWithTopWall(Rectangle ballRectangle)
- {
- if (ballRectangle.Intersects(_topWall))
- return true;
-
- return false;
- }
-
- public Rectangle GetTopWallRectangle()
- {
- return _topWall;
- }
-
- public Rectangle GetLeftWallRectangle()
- {
- return _leftWall;
- }
-
- public Rectangle GetRightWallRectangle()
- {
- return _rightWall;
- }
-
- public bool IntersectsWithLeftWall(Rectangle ballRectangle)
- {
- if (ballRectangle.Intersects(_leftWall))
- return true;
-
- return false;
- }
-
- public bool IntersectsWithRightWall(Rectangle ballRectangle)
- {
- if (ballRectangle.Intersects(_rightWall))
- return true;
-
- return false;
- }
- }
+using System;
+using Microsoft.Xna.Framework;
+
+namespace BallBounceMVC.Models
+{
+ public class FrameModel : Model
+ {
+ private readonly Rectangle _topWall, _leftWall, _rightWall;
+ private const int WallWidth = 11;
+
+ public FrameModel(World world)
+ : base(world)
+ {
+ Rectangle viewport = world.GetViewport();
+ _topWall = new Rectangle(viewport.Left + WallWidth, viewport.Top, viewport.Width - (WallWidth * 2), WallWidth);
+ _leftWall = new Rectangle(viewport.Left, viewport.Top, WallWidth, viewport.Height);
+ _rightWall = new Rectangle(viewport.Right - WallWidth, viewport.Top, WallWidth, viewport.Height);
+ }
+
+ public override void Update(float elapsedSeconds)
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool IntersectsWithTopWall(Rectangle ballRectangle)
+ {
+ if (ballRectangle.Intersects(_topWall))
+ return true;
+
+ return false;
+ }
+
+ public Rectangle GetTopWallRectangle()
+ {
+ return _topWall;
+ }
+
+ public Rectangle GetLeftWallRectangle()
+ {
+ return _leftWall;
+ }
+
+ public Rectangle GetRightWallRectangle()
+ {
+ return _rightWall;
+ }
+
+ public bool IntersectsWithLeftWall(Rectangle ballRectangle)
+ {
+ if (ballRectangle.Intersects(_leftWall))
+ return true;
+
+ return false;
+ }
+
+ public bool IntersectsWithRightWall(Rectangle ballRectangle)
+ {
+ if (ballRectangle.Intersects(_rightWall))
+ return true;
+
+ return false;
+ }
+ }
}
View
26 BallBounceMVC/BallBounceMVC/Models/Model.cs
@@ -1,14 +1,14 @@
-namespace BallBounceMVC.Models
-{
- public abstract class Model
- {
- protected Model(World world)
- {
- World = world;
- }
-
- public abstract void Update(float elapsedSeconds);
-
- protected World World;
- }
+namespace BallBounceMVC.Models
+{
+ public abstract class Model
+ {
+ protected Model(World world)
+ {
+ World = world;
+ }
+
+ public abstract void Update(float elapsedSeconds);
+
+ protected World World;
+ }
}
View
67 BallBounceMVC/BallBounceMVC/Models/PlayerModel.cs
@@ -3,41 +3,42 @@
namespace BallBounceMVC.Models
{
- public class PlayerModel : Model
- {
- private Rectangle _ship;
- private int _width;
- private int _height;
- private World _world;
+ public class PlayerModel : Model
+ {
+ private Rectangle _ship;
+ private int _width;
+ private int _height;
+ private World _world;
- public PlayerModel(World world) : base(world)
- {
- _world = world;
- _width = 120;
- _height = 20;
- var viewport = world.GetViewport();
- _ship = new Rectangle(viewport.Center.X,
- (viewport.Bottom - viewport.Height / 8),
- _width, _height);
- }
+ public PlayerModel(World world)
+ : base(world)
+ {
+ _world = world;
+ _width = 120;
+ _height = 20;
+ var viewport = world.GetViewport();
+ _ship = new Rectangle(viewport.Center.X,
+ (viewport.Bottom - viewport.Height / 8),
+ _width, _height);
+ }
- public override void Update(float relativeDifference)
- {
- _ship.X += (int)relativeDifference;
- _ship.X = (int)MathHelper.Clamp(
- _ship.X,
- _world.GetFrameModel().GetLeftWallRectangle().Right,
- _world.GetFrameModel().GetRightWallRectangle().Left - _ship.Width);
- }
+ public override void Update(float relativeDifference)
+ {
+ _ship.X += (int)relativeDifference;
+ _ship.X = (int)MathHelper.Clamp(
+ _ship.X,
+ _world.GetFrameModel().GetLeftWallRectangle().Right,
+ _world.GetFrameModel().GetRightWallRectangle().Left - _ship.Width);
+ }
- public Rectangle GetShip()
- {
- return _ship;
- }
+ public Rectangle GetShip()
+ {
+ return _ship;
+ }
- public bool IntersectsWith(Rectangle ballRectangle)
- {
- return _ship.Intersects(ballRectangle);
- }
- }
+ public bool IntersectsWith(Rectangle ballRectangle)
+ {
+ return _ship.Intersects(ballRectangle);
+ }
+ }
}
View
104 BallBounceMVC/BallBounceMVC/Models/World.cs
@@ -2,56 +2,56 @@
namespace BallBounceMVC.Models
{
- public class World
- {
- public float GameSpeed = 2.0f;
- private const int BoxLength = 18;
- private readonly BallsModel _ballsModel;
- private readonly Vector2 _startDirectionForNewBall = new Vector2(0.5f, -4.0f);
- private readonly Rectangle _viewportRect;
- private readonly FrameModel _frameModel;
- private readonly PlayerModel _playerModel;
- private int _lives = 3;
-
- public World(int viewportWidth, int viewportHeight)
- {
- _viewportRect = new Rectangle(0, 0,
- viewportWidth,
- viewportHeight);
- _ballsModel = new BallsModel(this, BoxLength, BoxLength, new Vector2(400f, 400f), _startDirectionForNewBall);
- _frameModel = new FrameModel(this);
- _playerModel = new PlayerModel(this);
- }
-
- public int Lives
- {
- get { return _lives; }
- set { _lives = value; }
- }
-
- public BallsModel GetBallsModel()
- {
- return _ballsModel;
- }
-
- public FrameModel GetFrameModel()
- {
- return _frameModel;
- }
-
- public Rectangle GetViewport()
- {
- return _viewportRect;
- }
-
- public PlayerModel GetPlayerModel()
- {
- return _playerModel;
- }
-
- public void Update(float elapsedSeconds)
- {
- _ballsModel.Update(elapsedSeconds);
- }
- }
+ public class World
+ {
+ public float GameSpeed = 2.0f;
+ private const int BoxLength = 18;
+ private readonly BallsModel _ballsModel;
+ private readonly Vector2 _startDirectionForNewBall = new Vector2(0.5f, -4.0f);
+ private readonly Rectangle _viewportRect;
+ private readonly FrameModel _frameModel;
+ private readonly PlayerModel _playerModel;
+ private int _lives = 3;
+
+ public World(int viewportWidth, int viewportHeight)
+ {
+ _viewportRect = new Rectangle(0, 0,
+ viewportWidth,
+ viewportHeight);
+ _ballsModel = new BallsModel(this, BoxLength, BoxLength, new Vector2(400f, 400f), _startDirectionForNewBall);
+ _frameModel = new FrameModel(this);
+ _playerModel = new PlayerModel(this);
+ }
+
+ public int Lives
+ {
+ get { return _lives; }
+ set { _lives = value; }
+ }
+
+ public BallsModel GetBallsModel()
+ {
+ return _ballsModel;
+ }
+
+ public FrameModel GetFrameModel()
+ {
+ return _frameModel;
+ }
+
+ public Rectangle GetViewport()
+ {
+ return _viewportRect;
+ }
+
+ public PlayerModel GetPlayerModel()
+ {
+ return _playerModel;
+ }
+
+ public void Update(float elapsedSeconds)
+ {
+ _ballsModel.Update(elapsedSeconds);
+ }
+ }
}
View
42 BallBounceMVC/BallBounceMVC/Program.cs
@@ -1,21 +1,21 @@
-using System;
-
-namespace BallBounceMVC
-{
-#if WINDOWS || XBOX
- static class Program
- {
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- static void Main(string[] args)
- {
- using (var game = new BallBounceGame())
- {
- game.Run();
- }
- }
- }
-#endif
-}
-
+using System;
+
+namespace BallBounceMVC
+{
+#if WINDOWS || XBOX
+ static class Program
+ {
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ static void Main(string[] args)
+ {
+ using (var game = new BallBounceGame())
+ {
+ game.Run();
+ }
+ }
+ }
+#endif
+}
+
View
54 BallBounceMVC/BallBounceMVC/Views/BallsViewer.cs
@@ -1,28 +1,28 @@
-using System.Collections.Generic;
-using BallBounceMVC.Entities;
-using Microsoft.Xna.Framework;
-using Microsoft.Xna.Framework.Graphics;
-
-namespace BallBounceMVC.Views
-{
- public class BallsViewer: Viewer
- {
- private readonly IList<Ball> _balls;
- private readonly Texture2D _texture;
-
- public BallsViewer(IList<Ball> balls, Texture2D texture)
- {
- _balls = balls;
- _texture = texture;
- }
-
- public override void Draw(SpriteBatch spriteBatch)
- {
- foreach (var ball in _balls)
- {
- var ballRect = new Rectangle((int)ball.Position.X, (int)ball.Position.Y, ball.Width, ball.Height);
- spriteBatch.Draw(_texture, ballRect, Color.White);
- }
- }
- }
+using System.Collections.Generic;
+using BallBounceMVC.Entities;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace BallBounceMVC.Views
+{
+ public class BallsViewer : Viewer
+ {
+ private readonly IList<Ball> _balls;
+ private readonly Texture2D _texture;
+
+ public BallsViewer(IList<Ball> balls, Texture2D texture)
+ {
+ _balls = balls;
+ _texture = texture;
+ }
+
+ public override void Draw(SpriteBatch spriteBatch)
+ {
+ foreach (var ball in _balls)
+ {
+ var ballRect = new Rectangle((int)ball.Position.X, (int)ball.Position.Y, ball.Width, ball.Height);
+ spriteBatch.Draw(_texture, ballRect, Color.White);
+ }
+ }
+ }
}
View
16 BallBounceMVC/BallBounceMVC/Views/Viewer.cs
@@ -1,9 +1,9 @@
-using Microsoft.Xna.Framework.Graphics;
-
-namespace BallBounceMVC.Views
-{
- public abstract class Viewer
- {
- public abstract void Draw(SpriteBatch spriteBatch);
- }
+using Microsoft.Xna.Framework.Graphics;
+
+namespace BallBounceMVC.Views
+{
+ public abstract class Viewer
+ {
+ public abstract void Draw(SpriteBatch spriteBatch);
+ }
}

0 comments on commit f681fe5

Please sign in to comment.
Something went wrong with that request. Please try again.