Bugfixes and corrections with the map format

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent 7b04af05d4
commit 52aa0053ae
  1. BIN
      maps/world1.map
  2. 6
      src/sig/DrawLoop.java
  3. 2
      src/sig/events/SpawnEvent.java
  4. 4
      src/sig/map/DataTile.java
  5. 18
      src/sig/map/Map.java
  6. 13
      src/sig/objects/EditorRenderer.java
  7. 1
      src/sig/objects/Erinoah.java
  8. 9
      src/sig/objects/LevelRenderer.java

Binary file not shown.

@ -122,8 +122,10 @@ public class DrawLoop {
public static void Fill_Rect(byte[] p,byte col,double x,double y,double w,double h) {
for (int xx=0;xx<w;xx++) {
for (int yy=0;yy<h;yy++) {
int index = ((int)y+yy)*RabiClone.BASE_WIDTH+(int)x+xx;
Draw(p,index,col, Alpha.ALPHA0);
if (x+xx>=0&&y+yy>=0&&x+xx<RabiClone.BASE_WIDTH&&y+yy<RabiClone.BASE_HEIGHT) {
int index = ((int)y+yy)*RabiClone.BASE_WIDTH+(int)x+xx;
Draw(p,index,col, Alpha.ALPHA0);
}
}
}
}

@ -24,7 +24,7 @@ public class SpawnEvent implements Event{
@Override
public boolean perform(int x, int y) {
try {
RabiClone.OBJ.add((Object)entity.getDeclaredConstructor(new Class<?>[]{Double.class,Double.class}).newInstance(x,y));
RabiClone.OBJ.add((Object)entity.getDeclaredConstructor(new Class<?>[]{double.class,double.class}).newInstance(x,y));
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
e.printStackTrace();

@ -15,7 +15,9 @@ public enum DataTile {
String description;
Event event;
DataTile(){}
DataTile(){
this.description=new String("");
}
DataTile(Event e) {
this.description=e.getDescription();
this.event=e;

@ -27,12 +27,14 @@ public class Map {
final public static int MAP_WIDTH=512;
final public static int MAP_HEIGHT=288;
final public static int MAP_SCREENS_X=32;
final public static int MAP_SCREENS_Y=32;
char[] tiles = new char[MAP_WIDTH*MAP_HEIGHT];
byte[] views = new byte[(MAP_WIDTH/Tile.TILE_WIDTH)*(MAP_HEIGHT/Tile.TILE_HEIGHT)];
byte[] backgrounds = new byte[(MAP_WIDTH/Tile.TILE_WIDTH)*(MAP_HEIGHT/Tile.TILE_HEIGHT)];
byte[] colors = new byte[(MAP_WIDTH/Tile.TILE_WIDTH)*(MAP_HEIGHT/Tile.TILE_HEIGHT)];
byte[] types = new byte[(MAP_WIDTH/Tile.TILE_WIDTH)*(MAP_HEIGHT/Tile.TILE_HEIGHT)];
byte[] views = new byte[MAP_SCREENS_X*MAP_SCREENS_Y];
byte[] backgrounds = new byte[MAP_SCREENS_X*MAP_SCREENS_Y];
byte[] colors = new byte[MAP_SCREENS_X*MAP_SCREENS_Y];
byte[] types = new byte[MAP_SCREENS_X*MAP_SCREENS_Y];
char[] data = new char[MAP_WIDTH*MAP_HEIGHT];
int eventTileCount=0;
@ -100,13 +102,15 @@ public class Map {
case EVENT_DATA_COUNT:
newMap.eventTileCount=stream.readInt();
readingData=EVENT_DATA;
iterationCount=newMap.eventTileCount;
iterationCount=newMap.eventTileCount+1; //It gets decreased by one after the loop.
System.out.println("Event tile count is "+(iterationCount-1));
break;
case EVENT_DATA:
int dataPacket = stream.readInt();
//First 14 bits are event info. Last 18 bits are index info.
char event = (char)(dataPacket>>>18);
int index = dataPacket&0b00000000000000111111111111111111;
System.out.println("Unpacked: "+((int)event)+" // x:"+(index%Map.MAP_WIDTH)+", y:"+(index/Map.MAP_WIDTH));
newMap.data[index]=event;
break;
}
@ -114,7 +118,7 @@ public class Map {
if (iterationCount<=0) {
readingData++;
marker=0;
iterationCount=(MAP_WIDTH/Tile.TILE_WIDTH)*(MAP_HEIGHT/Tile.TILE_HEIGHT);
iterationCount=MAP_SCREENS_X*MAP_SCREENS_Y;
}
}
stream.close();
@ -139,11 +143,13 @@ public class Map {
map.getMap().eventTileCount=stream.readInt();
int remainingCount = map.getMap().eventTileCount;
System.out.println("Found "+remainingCount+" events.");
while (remainingCount-->0) {
int dataPacket = stream.readInt();
//First 14 bits are event info. Last 18 bits are index info.
char event = (char)(dataPacket>>>18);
int index = dataPacket&0b00000000000000111111111111111111;
System.out.println("Unpacked: "+((int)event)+" // x:"+(index%Map.MAP_WIDTH)+", y:"+(index/Map.MAP_WIDTH));
map.getMap().data[index]=event;
}
stream.close();

@ -122,6 +122,9 @@ public class EditorRenderer extends LevelRenderer{
}
if (dataTileView) {
drawMapTileForDataTileMode(p,x,y);
if (RabiClone.CURRENT_MAP.getDataTile(x, y)!=DataTile.NULL) {
DrawDataTile(p,x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),RabiClone.CURRENT_MAP.getDataTile(x, y));
}
} else {
drawMapTileForEditorMode(x,y);
}
@ -196,17 +199,15 @@ public class EditorRenderer extends LevelRenderer{
double tileX = x*Tile.TILE_WIDTH-this.getX();
double tileY = y*Tile.TILE_HEIGHT-this.getY();
DrawTransparentDataTile(p,tileX,tileY,selectedDataTile,PaletteColor.GRAPE);
Draw_Text(tileX+2,tileY-Font.PROFONT_12.getGlyphHeight()-2,new String(selectedTile.toString()),Font.PROFONT_12);
Draw_Text_Ext(tileX+2,tileY+Tile.TILE_HEIGHT+2,new String(RabiClone.CURRENT_MAP.getTile(x,y).toString()),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.CRIMSON);
Draw_Text_Ext(tileX+2,tileY+Tile.TILE_HEIGHT+2,selectedDataTile.getDescription(),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.CRIMSON);
}
}
protected void DrawTransparentDataTile(byte[] p, double x, double y, DataTile tile,PaletteColor col) {
Draw_Rect(p,col,x,y,Tile.TILE_WIDTH,Tile.TILE_HEIGHT);
Draw_Text_Ext(x+2,y+2,RabiClone.CURRENT_MAP.getDataTile((int)x,(int)y).getDescription(),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.WHITE);
Draw_Text_Ext(x+2,y+2,new String(tile.toString()),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.WHITE);
}
@Override
protected void DrawDataTile(byte[] p, double x, double y, DataTile tile) {
DrawTransparentDataTile(p,x,y,tile,PaletteColor.MIDNIGHT_BLUE);
}
@ -235,5 +236,7 @@ public class EditorRenderer extends LevelRenderer{
RabiClone.CURRENT_MAP.setBackground(tileX,tileY,Background.values()[(RabiClone.CURRENT_MAP.getBackground(tileX, tileY).ordinal()+1)%Background.values().length]);
}break;
}
}
}
}

@ -21,7 +21,6 @@ public class Erinoah extends AnimatedObject implements RenderedObject{
@Override
public void draw(byte[] p) {
Draw_Animated_Sprite(16, 16, getAnimatedSpr(), getCurrentFrame());
}
@Override

@ -2,6 +2,8 @@ package sig.objects;
import java.awt.event.KeyEvent;
import javax.xml.crypto.Data;
import sig.RabiClone;
import sig.engine.Action;
import sig.engine.Alpha;
@ -60,9 +62,6 @@ public class LevelRenderer extends Object{
DrawTile(x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),RabiClone.CURRENT_MAP.getTile(x,y));
//System.out.println((x*Tile.TILE_WIDTH+(this.getX()%Tile.TILE_WIDTH) )+","+(y*Tile.TILE_HEIGHT+(this.getY()%Tile.TILE_HEIGHT)));
}
if (RabiClone.CURRENT_MAP.getDataTile(x,y)!=DataTile.NULL) {
DrawDataTile(p,x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),RabiClone.CURRENT_MAP.getDataTile(x,y));
}
}
}
for (int i=0;i<RabiClone.OBJ.size();i++) {
@ -136,9 +135,6 @@ public class LevelRenderer extends Object{
Draw_Sprite_Partial(x,y, tile.getSpriteSheetX()*tile.getTileWidth(), tile.getSpriteSheetY()*tile.getTileHeight(), tile.getTileWidth(), tile.getTileHeight(), getSprite(), 0, Transform.NONE);
}
protected void DrawDataTile(byte[] p, double x, double y, DataTile tile) {
}
protected void DrawTransparentTile(double x, double y, Tile tile, Alpha alpha) {
Draw_Sprite_Partial_Ext(x,y, tile.getSpriteSheetX()*tile.getTileWidth(), tile.getSpriteSheetY()*tile.getTileHeight(), tile.getTileWidth(), tile.getTileHeight(), getSprite(), alpha, Transform.NONE);
}
@ -150,6 +146,7 @@ public class LevelRenderer extends Object{
case LEVEL_EDITOR:{
RabiClone.OBJ.clear();
RabiClone.ResetGame();
Map.LoadMap(RabiClone.CURRENT_MAP);
RabiClone.OBJ.add(RabiClone.level_renderer = new EditorRenderer(RabiClone.p));
}break;
}

Loading…
Cancel
Save