From 0f94b0396d032f554dedbbc37d9193ed31ad0708 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Fri, 3 Jun 2022 16:44:55 -0500 Subject: [PATCH] Background drawing implemented Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- maps/world1.map | Bin 295488 -> 295488 bytes src/sig/engine/Background.java | 18 ----------------- src/sig/engine/Sprite.java | 3 +++ src/sig/map/Background.java | 30 ++++++++++++++++++++++++++++- src/sig/map/Maps.java | 2 +- src/sig/objects/LevelRenderer.java | 9 ++++++++- src/sig/objects/Player.java | 4 ++-- 7 files changed, 43 insertions(+), 23 deletions(-) delete mode 100644 src/sig/engine/Background.java diff --git a/maps/world1.map b/maps/world1.map index ac61973defe19f2c9133de4c715c87ec6018a015..8c580bb9b08c73838a3e5bba0da4a11c5aebf213 100644 GIT binary patch delta 33 pcmX@mB6OfdsG)_ig{g&k3(LX=CPt>of(7!EFG<^aB8irwP^o diff --git a/src/sig/engine/Background.java b/src/sig/engine/Background.java deleted file mode 100644 index 5ac6bdc..0000000 --- a/src/sig/engine/Background.java +++ /dev/null @@ -1,18 +0,0 @@ -package sig.engine; - -import java.io.File; - -public class Background extends Sprite{ - - public static Sprite BACKGROUND_1 = new Background(0.02,new File(new File("..","backgrounds"),"back1.gif")); - public static Sprite BACKGROUND_2 = new Background(0.02,new File(new File("..","backgrounds"),"back2.gif")); - public static Sprite BACKGROUND_3 = new Background(0.05,new File(new File("..","backgrounds"),"back3.gif")); - - double scrollAmt; //How many pixels to scroll the background per pixel of offset provided. - - Background(double scrollAmt,File filename) { - super(filename); - this.scrollAmt=scrollAmt; - } - -} diff --git a/src/sig/engine/Sprite.java b/src/sig/engine/Sprite.java index 860acd9..b6442a5 100644 --- a/src/sig/engine/Sprite.java +++ b/src/sig/engine/Sprite.java @@ -14,6 +14,9 @@ public class Sprite{ public static Sprite TILE_SHEET = new Sprite(new File(new File("..","sprites"),"tiles.gif")); public static Sprite MAP_TILE_INFO = new Sprite(new File(new File("..","sprites"),"maptileinfo.gif")); public static Sprite PROFONT = new Sprite(new File(new File("..","sprites"),"Profont.gif")); + public static Sprite BACKGROUND1 = new Sprite(new File(new File("..","backgrounds"),"back1.gif")); + public static Sprite BACKGROUND2 = new Sprite(new File(new File("..","backgrounds"),"back2.gif")); + public static Sprite BACKGROUND3 = new Sprite(new File(new File("..","backgrounds"),"back3.gif")); diff --git a/src/sig/map/Background.java b/src/sig/map/Background.java index 2dca341..b5d7e55 100644 --- a/src/sig/map/Background.java +++ b/src/sig/map/Background.java @@ -1,5 +1,33 @@ package sig.map; +import sig.engine.Sprite; + public enum Background { - DEFAULT + BACKGROUND1(Sprite.BACKGROUND1,0.02), + BACKGROUND2(Sprite.BACKGROUND2,0.02), + BACKGROUND3(Sprite.BACKGROUND3,0.05); + + Sprite background; + double scrollSpd; //Amount of pixels to move the background based on pixel offset provided. + + Background(Sprite background,double scrollSpd) { + this.background=background; + this.scrollSpd=scrollSpd; + } + + public byte[] getPixels() { + return background.getBi_array(); + } + + public int getWidth() { + return background.getWidth(); + } + + public int getHeight() { + return background.getHeight(); + } + + public double getScrollSpeed() { + return scrollSpd; + } } diff --git a/src/sig/map/Maps.java b/src/sig/map/Maps.java index 47a63ad..35555be 100644 --- a/src/sig/map/Maps.java +++ b/src/sig/map/Maps.java @@ -73,7 +73,7 @@ public enum Maps { public Background getBackground(int x,int y) { int index = (y/Tile.TILE_SCREEN_COUNT_Y)*(Map.MAP_WIDTH/Tile.TILE_WIDTH)+x/Tile.TILE_SCREEN_COUNT_X; if (index<0||index>=this.map.backgrounds.length) { - return Background.DEFAULT; + return Background.BACKGROUND1; } else { return Background.values()[this.map.backgrounds[index]]; } diff --git a/src/sig/objects/LevelRenderer.java b/src/sig/objects/LevelRenderer.java index 43617c4..6519257 100644 --- a/src/sig/objects/LevelRenderer.java +++ b/src/sig/objects/LevelRenderer.java @@ -5,6 +5,7 @@ import sig.engine.Alpha; import sig.engine.Object; import sig.engine.Panel; import sig.engine.Sprite; +import sig.map.Background; import sig.map.Map; import sig.map.Tile; @@ -41,9 +42,15 @@ public class LevelRenderer extends Object{ @Override public void drawBackground(byte[] p) { + int screenX = (int)(getX())/Tile.TILE_WIDTH; + int screenY = (int)(getY())/Tile.TILE_HEIGHT; + Background targetBackground = RabiClone.CURRENT_MAP.getBackground(screenX, screenY); for (int y=0;y