From 8ba9307465ccf025ce7b9c3d2e297bc18bc5b068 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 4 Jun 2022 02:51:12 -0500 Subject: [PATCH] Implement Animated Sprites Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- maps/world1.map | Bin 295488 -> 295488 bytes sprites/erinoah.gif | Bin 0 -> 1462 bytes src/sig/DrawLoop.java | 23 +++++++++++---- src/sig/RabiClone.java | 2 ++ src/sig/engine/AnimatedObject.java | 44 ++++++++++++++++++++++++++++ src/sig/engine/AnimatedSprite.java | 35 ++++++++++++++++++++++ src/sig/engine/Object.java | 12 +++++--- src/sig/engine/Rectangle.java | 8 +++++ src/sig/engine/Sprite.java | 1 + src/sig/objects/EditorRenderer.java | 4 +-- src/sig/objects/Erinoah.java | 23 +++++++++++++++ src/sig/objects/LevelRenderer.java | 2 +- 12 files changed, 141 insertions(+), 13 deletions(-) create mode 100644 sprites/erinoah.gif create mode 100644 src/sig/engine/AnimatedObject.java create mode 100644 src/sig/engine/AnimatedSprite.java create mode 100644 src/sig/objects/Erinoah.java diff --git a/maps/world1.map b/maps/world1.map index 8c580bb9b08c73838a3e5bba0da4a11c5aebf213..b86a24de59b907788291a7065456bd3a77d67446 100644 GIT binary patch delta 99 zcmX@mB6OfdXhWh3HxmOKZWP?iJXv1D30ELb2vS-#*s M6BEO9;Rcpo09V5jsQ>@~ diff --git a/sprites/erinoah.gif b/sprites/erinoah.gif new file mode 100644 index 0000000000000000000000000000000000000000..023f4bd9a65f3f4c4005c33c83f3fcd12b1abe43 GIT binary patch literal 1462 zcmcJK=RX?=06?SEs+t|KYW1#0QLQ~1XVae=J+mqzBB4f%2of%65_^Xg=~ zP1Q)OQma}kMoVk7XH{~&KjPl+eS4ptrL~2w9;6F!15gSC+%H2t91N&l@cH>Ijolpe z+1s0L;z?C>MO}8*^WlrG1u&}-7WOnb~*NoxGpa$aYM>4|7Ha8r9S%#;~ zwhyq`?B~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HcmV?d00001 diff --git a/src/sig/DrawLoop.java b/src/sig/DrawLoop.java index a7e5880..8c79738 100644 --- a/src/sig/DrawLoop.java +++ b/src/sig/DrawLoop.java @@ -3,9 +3,11 @@ package sig; import java.util.regex.Pattern; import sig.engine.Alpha; +import sig.engine.AnimatedSprite; import sig.engine.Font; import sig.engine.PaletteColor; import sig.engine.Panel; +import sig.engine.Rectangle; import sig.engine.Sprite; public class DrawLoop { @@ -59,17 +61,22 @@ public class DrawLoop { yOffset+=f.getGlyphHeight(); charCount=0; } else { - Draw_Sprite_Partial_Ext(x+i*f.getGlyphWidth()-xOffset, y+yOffset, f.getCharInfo(finalS.charAt(i)).getX(), f.getCharInfo(finalS.charAt(i)).getY(), f.getCharInfo(finalS.charAt(i)).getWidth(), f.getCharInfo(finalS.charAt(i)).getHeight(), f.getSprite(),alpha,currentCol); + Draw_Sprite_Partial_Ext(x+i*f.getGlyphWidth()-xOffset, y+yOffset, f.getCharInfo(finalS.charAt(i)).getX(), f.getCharInfo(finalS.charAt(i)).getY(), f.getCharInfo(finalS.charAt(i)).getWidth(), f.getCharInfo(finalS.charAt(i)).getHeight(), f.getSprite(), 0,alpha,currentCol); charCount++; } } } public static void Draw_Sprite(double x, double y, Sprite sprite){ - Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite); + Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0); } - public static void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite){ + public static void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex){ + Rectangle frameRectangle=sprite.getFrame((int)frameIndex); + Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,frameIndex); + } + + public static void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index){ byte[] p = panel.pixel; for(int X=(int)xOffset;X<(int)(w+xOffset);X++){ for(int Y=(int)yOffset;Y<(int)(h+yOffset);Y++){ @@ -81,7 +88,6 @@ public class DrawLoop { continue; } else { Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],Alpha.ALPHA0); - //Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],false); } } } @@ -89,10 +95,15 @@ public class DrawLoop { } public static void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Alpha alpha){ - Draw_Sprite_Partial_Ext(x, y, xOffset, yOffset, w, h, sprite, alpha, PaletteColor.NORMAL); + Draw_Sprite_Partial_Ext(x, y, xOffset, yOffset, w, h, sprite, 0, alpha, PaletteColor.NORMAL); + } + + public static void Draw_Animated_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, AnimatedSprite sprite, double frameIndex, Alpha alpha){ + Rectangle frameRectangle=sprite.getFrame((int)frameIndex); + Draw_Sprite_Partial_Ext(x, y, frameRectangle.getX(), frameRectangle.getY(), frameRectangle.getWidth(), frameRectangle.getHeight(), sprite, 0, alpha, PaletteColor.NORMAL); } - public static void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Alpha alpha, PaletteColor col){ + public static void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Alpha alpha, PaletteColor col){ byte[] p = panel.pixel; for(int X=(int)xOffset;X<(int)(w+xOffset);X++){ for(int Y=(int)yOffset;Y<(int)(h+yOffset);Y++){ diff --git a/src/sig/RabiClone.java b/src/sig/RabiClone.java index f939663..83f45c2 100644 --- a/src/sig/RabiClone.java +++ b/src/sig/RabiClone.java @@ -9,6 +9,7 @@ import sig.engine.Panel; import sig.engine.Point; import sig.map.Maps; import sig.objects.EditorRenderer; +import sig.objects.Erinoah; import sig.objects.LevelRenderer; import sig.objects.Player; import sig.engine.Object; @@ -94,6 +95,7 @@ public class RabiClone{ private static void StartGame() { OBJ.add(player = new Player(p)); + OBJ.add(new Erinoah(p)); } private static void ChooseBestRatio() { diff --git a/src/sig/engine/AnimatedObject.java b/src/sig/engine/AnimatedObject.java new file mode 100644 index 0000000..679234b --- /dev/null +++ b/src/sig/engine/AnimatedObject.java @@ -0,0 +1,44 @@ +package sig.engine; + +public abstract class AnimatedObject extends Object{ + + double currentFrame; + double animationSpd; + AnimatedSprite animatedSpr; + + protected AnimatedObject(AnimatedSprite spr, double animationSpd, Panel panel) { + super(panel); + this.spr=this.animatedSpr=spr; + this.animationSpd=animationSpd; + this.currentFrame=0; + } + + public void update(double updateMult) { + this.currentFrame+=this.animationSpd*updateMult; + } + + public double getCurrentFrame() { + return currentFrame; + } + + public void setCurrentFrame(double currentFrame) { + this.currentFrame = currentFrame; + } + + public double getAnimationSpd() { + return animationSpd; + } + + public void setAnimationSpd(double animationSpd) { + this.animationSpd = animationSpd; + } + + public AnimatedSprite getAnimatedSpr() { + return animatedSpr; + } + + public void setAnimatedSpr(AnimatedSprite animatedSpr) { + this.animatedSpr = animatedSpr; + } + +} diff --git a/src/sig/engine/AnimatedSprite.java b/src/sig/engine/AnimatedSprite.java new file mode 100644 index 0000000..d1cf540 --- /dev/null +++ b/src/sig/engine/AnimatedSprite.java @@ -0,0 +1,35 @@ +package sig.engine; + +import java.io.File; + +public class AnimatedSprite extends Sprite{ + int frameWidth; + int frameHeight; + int frames; + Rectangle[] frames_to_Rectangle; + + AnimatedSprite(File filename, int width, int height){ + super(filename); + this.frameWidth = width; + this.frameHeight = height; + frames = (this.width/width)*(this.height/height); + frames_to_Rectangle = new Rectangle[frames]; + for(int i=0;i