Background drawing implemented

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent 5a5eb5f2fb
commit 0f94b0396d
  1. BIN
      maps/world1.map
  2. 18
      src/sig/engine/Background.java
  3. 3
      src/sig/engine/Sprite.java
  4. 30
      src/sig/map/Background.java
  5. 2
      src/sig/map/Maps.java
  6. 9
      src/sig/objects/LevelRenderer.java
  7. 4
      src/sig/objects/Player.java

Binary file not shown.

@ -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;
}
}

@ -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"));

@ -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;
}
}

@ -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]];
}

@ -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<RabiClone.BASE_HEIGHT;y++) {
for (int x=0;x<RabiClone.BASE_WIDTH;x++) {
int index = y*RabiClone.BASE_WIDTH+x;
p[index] = targetBackground.getPixels()[
((y+(int)(getY()*targetBackground.getScrollSpeed()))%targetBackground.getHeight())*targetBackground.getWidth()+((x+(int)(getX()*targetBackground.getScrollSpeed()))%targetBackground.getWidth())
];
}
}
}

@ -133,8 +133,8 @@ public class Player extends Object{
}
break;
}
RabiClone.level_renderer.setX(newX);
RabiClone.level_renderer.setY(newY);
RabiClone.level_renderer.setX(newX<0?0:newX);
RabiClone.level_renderer.setY(newY<0?0:newY);
}

Loading…
Cancel
Save