Skip to content

Commit

Permalink
feature: Added basic asset loading (Texture2D only for now). (#21)
Browse files Browse the repository at this point in the history
* Added basic asset loading (Texture2D only for now).

* Fixed null graphics setup.

* Updated example.
  • Loading branch information
jimbuck authored Jan 16, 2024
1 parent 7f92117 commit 2397ded
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Ion.Examples/Ion.Examples.Breakout/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ public class BreakoutSystems
private readonly Vector2 _paddleBounceMin = Vector2.Normalize(new Vector2(-1, -0.75f));
private readonly Vector2 _paddleBounceMax = Vector2.Normalize(new Vector2(+1, -0.75f));

private Texture2D _blockTexture;
private Texture2D _ballTexture;
private Texture2D _blockTexture = default!;
private Texture2D _ballTexture = default!;
private readonly RectangleF _ballSprite = new RectangleF(1, 1, 14, 14);

public BreakoutSystems(IWindow window, IInputState input, ISpriteBatch spriteBatch, IEventListener events, IAssetManager assets)
{
Expand Down Expand Up @@ -154,7 +155,7 @@ public void Update(GameTime dt, GameLoopDelegate next)

if (intersection.IsEmpty is false)
{
_ballSpeed += 1f;
_ballSpeed += 5f;
_handlePlayerCollision(ref intersection);
}
}
Expand All @@ -167,7 +168,7 @@ public void Update(GameTime dt, GameLoopDelegate next)
RectangleF.Intersect(ref _ballRect, ref _blockRects[i], out var intersection);
if (intersection.IsEmpty) continue;

_ballSpeed += 3f;
_ballSpeed += 10f;
_blockStates[i] = false;
_ballVelocity *= _getReboundDirection(ref intersection);
_ballVelocity = Vector2.Normalize(_ballVelocity);
Expand Down Expand Up @@ -211,12 +212,12 @@ public void Render(GameTime dt, GameLoopDelegate next)
for (var col = 0; col < COLS; col++)
{
var i = (row * COLS) + col;
if (_blockStates[i]) _spriteBatch.Draw(_blockTexture, _blockRects[i], color: _blockColors[i], options: (SpriteEffect)(i % 3));
if (_blockStates[i]) _spriteBatch.Draw(_blockTexture, _blockRects[i], color: _blockColors[i]);
}
}

_spriteBatch.Draw(_blockTexture, _playerRect, color: Color.DarkBlue);
_spriteBatch.Draw(_ballTexture, _ballRect, color: Color.DarkRed);
_spriteBatch.Draw(_ballTexture, _ballRect, color: Color.DarkRed, sourceRectangle: _ballSprite);

next(dt);
}
Expand Down

0 comments on commit 2397ded

Please sign in to comment.