aboutsummaryrefslogtreecommitdiff
path: root/source/resources/sprites
diff options
context:
space:
mode:
authorhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
committerhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
commit567c422f8cd42eba2437f9a8c2522716a1649be7 (patch)
tree93c5b296f3b7c14b626d0aadf5cad37764c41c74 /source/resources/sprites
downloadcelesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.gz
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.bz2
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.zip
celesteia archive, last updated april 9th 2024
Signed-off-by: hazel <hazel@hazelthats.me>
Diffstat (limited to 'source/resources/sprites')
-rw-r--r--source/resources/sprites/BlockFrames.cs53
-rw-r--r--source/resources/sprites/EntityFrames.cs32
-rw-r--r--source/resources/sprites/SkyboxPortionFrames.cs51
3 files changed, 136 insertions, 0 deletions
diff --git a/source/resources/sprites/BlockFrames.cs b/source/resources/sprites/BlockFrames.cs
new file mode 100644
index 0000000..33db3e8
--- /dev/null
+++ b/source/resources/sprites/BlockFrames.cs
@@ -0,0 +1,53 @@
+using System;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using MonoGame.Extended.TextureAtlases;
+
+namespace Celesteia.Resources.Sprites {
+ public class BlockFrames {
+ private readonly Vector2 _scaling;
+
+ private BlockFrame[] _frames;
+
+ private bool _doDraw;
+ public bool DoDraw => _doDraw;
+
+ public BlockFrames(TextureAtlas atlas, int startIndex, int frameCount, Vector2? origin = null) {
+ _doDraw = frameCount > 0;
+
+ _scaling = new Vector2(ResourceManager.SPRITE_SCALING);
+
+ _frames = new BlockFrame[frameCount];
+ for (int i = 0; i < frameCount; i++) {
+ _frames[i] = new BlockFrame(atlas.GetRegion(startIndex + i), _scaling, origin);
+ }
+ }
+
+ public BlockFrame GetFrame(int index) {
+ if (!_doDraw) return null;
+
+ return _frames[index % _frames.Length];
+ }
+
+ public BlockFrame GetProgressFrame(float progress) {
+ return GetFrame((int)MathF.Round(progress * (_frames.Length - 1)));
+ }
+ }
+
+ public class BlockFrame {
+ private TextureRegion2D _region;
+ private Vector2 _scaling;
+ private Vector2 _origin;
+
+ public BlockFrame(TextureRegion2D region, Vector2 scaling, Vector2? origin = null) {
+ _region = region;
+ _scaling = scaling;
+ _origin = origin.HasValue ? origin.Value : Vector2.Zero;
+ }
+
+ public void Draw(int index, SpriteBatch spriteBatch, Vector2 position, Color color, float depth = 0f)
+ => spriteBatch.Draw(_region, position, color, 0f, _origin, _scaling, SpriteEffects.None, depth);
+
+ public TextureRegion2D GetRegion() => _region;
+ }
+} \ No newline at end of file
diff --git a/source/resources/sprites/EntityFrames.cs b/source/resources/sprites/EntityFrames.cs
new file mode 100644
index 0000000..65e31ee
--- /dev/null
+++ b/source/resources/sprites/EntityFrames.cs
@@ -0,0 +1,32 @@
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using MonoGame.Extended.TextureAtlases;
+
+namespace Celesteia.Resources.Sprites {
+ public class EntityFrames {
+ public SpriteEffects Effects;
+
+ public int Frame;
+
+ private readonly Vector2 _scaling;
+
+ private TextureRegion2D[] _frames;
+
+ public EntityFrames(TextureAtlas atlas, int startIndex, int frameCount, float scaling) {
+ _scaling = new Vector2(scaling);
+
+ _frames = new TextureRegion2D[frameCount];
+ for (int i = 0; i < frameCount; i++) {
+ _frames[i] = atlas.GetRegion(startIndex + i);
+ }
+ }
+
+ private Vector2 GetOrigin(TextureRegion2D frame) {
+ return new Vector2(0.5f * frame.Width, 0.5f * frame.Height);
+ }
+
+ public void Draw(int index, SpriteBatch spriteBatch, Vector2 position, Vector2 scale, Color color) {
+ spriteBatch.Draw(_frames[Frame % _frames.Length], position, color, 0f, GetOrigin(_frames[index % _frames.Length]), _scaling * scale, Effects, 0f, null);
+ }
+ }
+} \ No newline at end of file
diff --git a/source/resources/sprites/SkyboxPortionFrames.cs b/source/resources/sprites/SkyboxPortionFrames.cs
new file mode 100644
index 0000000..dc26156
--- /dev/null
+++ b/source/resources/sprites/SkyboxPortionFrames.cs
@@ -0,0 +1,51 @@
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using MonoGame.Extended.TextureAtlases;
+
+namespace Celesteia.Resources.Sprites {
+ public class SkyboxPortionFrames {
+ private readonly Vector2 _scaling;
+
+ private TextureAtlas _atlas;
+ private int _start;
+ private int _count;
+
+ private TextureRegion2D[] _frames;
+ private Color _color;
+ private float _depth;
+
+ public SkyboxPortionFrames(TextureAtlas atlas, int size, int startIndex, int frameCount) {
+ _atlas = atlas;
+ _start = startIndex;
+ _count = frameCount;
+ _scaling = new Vector2(ResourceManager.SPRITE_SCALING) / 2f;
+
+ _frames = new TextureRegion2D[frameCount];
+ for (int i = 0; i < frameCount; i++) {
+ _frames[i] = atlas.GetRegion(startIndex + i);
+ }
+ }
+
+ public SkyboxPortionFrames SetColor(Color color) {
+ _color = color;
+ return this;
+ }
+
+ public SkyboxPortionFrames SetDepth(float depth) {
+ _depth = depth;
+ return this;
+ }
+
+ private Vector2 GetOrigin(TextureRegion2D frame) {
+ return new Vector2(0.5f * frame.Width, 0.5f * frame.Height);
+ }
+
+ public void Draw(int index, SpriteBatch spriteBatch, Vector2 position, float rotation, Vector2 scale) {
+ spriteBatch.Draw(_frames[index % _frames.Length], position, _color, rotation, GetOrigin(_frames[index % _frames.Length]), scale * _scaling, SpriteEffects.None, _depth, null);
+ }
+
+ public SkyboxPortionFrames Clone() {
+ return new SkyboxPortionFrames(_atlas, 0, _start, _count).SetColor(_color).SetDepth(_depth);
+ }
+ }
+} \ No newline at end of file