diff --git a/maps/world1.map b/maps/world1.map index 8c580bb..b86a24d 100644 Binary files a/maps/world1.map and b/maps/world1.map differ diff --git a/sprites/erinoah.gif b/sprites/erinoah.gif new file mode 100644 index 0000000..023f4bd Binary files /dev/null and b/sprites/erinoah.gif differ 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