/// <summary> /// Draws the floor of the current view /// </summary> public void RenderFloorTiles(ref Tile[,] tiles) { DrawParameters drawParameters = default; drawParameters.AreaWithinTexture = Constants.TileRectangle; drawParameters.Centre = Vector2.Zero; for (int j = 0; j < this._viewOfWorld.Height; j++) { int y = this._viewOfWorld.TopLeft.Y + j; for (int i = 0; i < this._viewOfWorld.Width; i++) { int x = this._viewOfWorld.TopLeft.X + i; string textureName = tiles[x, y].TextureName; if (textureName == null) { continue; } var pathToTexture = textureName.Contains("/") ? textureName : "Tiles/" + textureName; drawParameters.Texture = this._spriteLibrary.GetSprite(pathToTexture); drawParameters.Position = new Vector2(x, y) * Constants.TileSize; this._spriteBatch.DrawTexture(drawParameters); } } }
private DrawParameters SetDrawParametersForFacedDirection(ISpriteLibrary spriteLibrary) { DrawParameters drawParameters = default; switch (this._player.CurrentDirectionFaced) { case Direction.Left: drawParameters.Texture = spriteLibrary.GetSprite("Sprites/Player/PlayerLeftFacing"); drawParameters.Effects = SpriteEffects.None; break; case Direction.Right: drawParameters.Texture = spriteLibrary.GetSprite("Sprites/Player/PlayerLeftFacing"); drawParameters.Effects = SpriteEffects.FlipHorizontally; break; case Direction.Up: drawParameters.Texture = spriteLibrary.GetSprite("Sprites/Player/PlayerUpFacing"); drawParameters.Effects = SpriteEffects.None; break; case Direction.Down: drawParameters.Texture = spriteLibrary.GetSprite("Sprites/Player/PlayerDownFacing"); drawParameters.Effects = SpriteEffects.None; break; default: throw new InvalidOperationException(); } drawParameters.Position = this._player.Position; return(drawParameters); }
public void Draw(ISpriteBatch spriteBatch, ISpriteLibrary spriteLibrary) { if (!this._gameObject.IsExtant) { return; } this._time %= this._lengthOfAnimation; var positionInAnimation = this._time / this._lengthOfAnimation; DrawParameters drawParameters = default; drawParameters.Texture = spriteLibrary.GetSprite(this._textureName); var frameCount = (drawParameters.Texture.Width / Constants.TileLength); int frameIndex = (int)Math.Floor(frameCount * positionInAnimation); // Calculate the source rectangle of the current frame. drawParameters.AreaWithinTexture = new Rectangle(frameIndex * Constants.TileLength, 0, Constants.TileLength, Constants.TileLength); drawParameters.Position = this._gameObject.Position; drawParameters.Rotation = this.Rotation; drawParameters.Effects = this.SpriteEffect; drawParameters.Opacity = this.Opacity; // Draw the current frame. spriteBatch.DrawTexture(drawParameters); }
private void DrawHull(ISpriteBatch spriteBatch, ISpriteLibrary spriteLibrary) { DrawParameters drawParameters = default; drawParameters.Texture = spriteLibrary.GetSprite(TextureName); // Calculate the source rectangle of the current frame. drawParameters.AreaWithinTexture = new Rectangle(0, 0, Constants.TileLength, Constants.TileLength); drawParameters.Position = this._tank.Position; drawParameters.Rotation = this._tank.HullRotation; // Draw the current frame. spriteBatch.DrawTexture(drawParameters); }
private void DrawTrack(ISpriteBatch spriteBatch, ISpriteLibrary spriteLibrary, int p2, double pctPositionInTrackAnimation) { DrawParameters drawParameters = default; drawParameters.Texture = spriteLibrary.GetSprite(TextureName); var frameCount = (drawParameters.Texture.Width / Constants.TileLength); int frameIndex = (int)Math.Floor(frameCount * pctPositionInTrackAnimation); // Calculate the source rectangle of the current frame. drawParameters.AreaWithinTexture = new Rectangle(frameIndex * Constants.TileLength, p2, Constants.TileLength, Constants.TileLength); drawParameters.Position = this._tank.Position; drawParameters.Rotation = this._tank.HullRotation; // Draw the current frame. spriteBatch.DrawTexture(drawParameters); }
private void DrawTurret(ISpriteBatch spriteBatch, ISpriteLibrary spriteLibrary) { Vector2 centreOfRotationForTurret = new Vector2(0, 3); double x = centreOfRotationForTurret.Y * Math.Sin(this._tank.HullRotation) + centreOfRotationForTurret.X * Math.Cos(this._tank.HullRotation); double y = centreOfRotationForTurret.Y * Math.Cos(this._tank.HullRotation) - centreOfRotationForTurret.X * Math.Sin(this._tank.HullRotation); Vector2 centreOfRotationForTurretAfterRotation = new Vector2((float)-x, (float)y); DrawParameters drawParameters = default; drawParameters.Texture = spriteLibrary.GetSprite(TextureName); // Calculate the source rectangle of the current frame. drawParameters.AreaWithinTexture = new Rectangle(32, 0, Constants.TileLength, Constants.TileLength); drawParameters.Position = this._tank.Position + centreOfRotationForTurretAfterRotation; drawParameters.Rotation = this._tank.TurretRotation; drawParameters.Centre = new Vector2(16, 19); // this is always the same - this is the point where we rotate the turret around in the source rectangle // Draw the current frame. spriteBatch.DrawTexture(drawParameters); }
/// <inheritdoc /> public void DrawTexture(DrawParameters drawParameters) { var absolutePosition = drawParameters.Position - this.WindowPosition; this.DrawTexture(drawParameters.Texture, absolutePosition, drawParameters.AreaWithinTexture, drawParameters.Opacity, drawParameters.Rotation, drawParameters.Centre, drawParameters.Effects); }