Draw data tiles on the grid
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
e017e02106
commit
489186c077
@ -15,4 +15,7 @@ public enum DataTile {
|
||||
DataTile(java.lang.String s) {
|
||||
this.description=new String(s);
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,15 @@ public enum Maps {
|
||||
}
|
||||
}
|
||||
|
||||
public DataTile getDataTile(int x,int y) {
|
||||
int index = y*Map.MAP_WIDTH+x;
|
||||
if (index<0||index>=this.map.data.length) {
|
||||
return DataTile.NULL;
|
||||
} else {
|
||||
return DataTile.values()[this.map.data[index]];
|
||||
}
|
||||
}
|
||||
|
||||
public View getView(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.views.length) {
|
||||
|
@ -2,18 +2,17 @@ package sig.objects;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.IOException;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import sig.RabiClone;
|
||||
import sig.engine.Action;
|
||||
import sig.engine.Alpha;
|
||||
import sig.engine.Font;
|
||||
import sig.engine.Key;
|
||||
import sig.engine.MouseScrollValue;
|
||||
import sig.engine.PaletteColor;
|
||||
import sig.engine.Panel;
|
||||
import sig.engine.String;
|
||||
import sig.map.Background;
|
||||
import sig.map.DataTile;
|
||||
import sig.map.Map;
|
||||
import sig.map.Tile;
|
||||
import sig.map.View;
|
||||
@ -22,6 +21,7 @@ import sig.map.Type;
|
||||
public class EditorRenderer extends LevelRenderer{
|
||||
|
||||
Tile selectedTile = Tile.WALL;
|
||||
DataTile selectedDataTile = DataTile.BUN1;
|
||||
|
||||
String messageLog = new String();
|
||||
final static long MESSAGE_TIME = 5000;
|
||||
@ -110,7 +110,11 @@ public class EditorRenderer extends LevelRenderer{
|
||||
if (x<0||x>Map.MAP_WIDTH) {
|
||||
continue;
|
||||
}
|
||||
drawMapTileForEditorMode(x,y);
|
||||
if (dataTileView) {
|
||||
drawMapTileForDataTileMode(p,x,y);
|
||||
} else {
|
||||
drawMapTileForEditorMode(x,y);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int y=(int)(this.getY()/Tile.TILE_HEIGHT);y<(int)(RabiClone.BASE_HEIGHT/Tile.TILE_HEIGHT+this.getY()/Tile.TILE_HEIGHT+1);y++) {
|
||||
@ -163,7 +167,6 @@ public class EditorRenderer extends LevelRenderer{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawMapTileForEditorMode(int x, int y) {
|
||||
int tilerX = (int)(RabiClone.MOUSE_POS.getX()+getX())/Tile.TILE_WIDTH;
|
||||
int tilerY = (int)(RabiClone.MOUSE_POS.getY()+getY())/Tile.TILE_HEIGHT;
|
||||
@ -176,6 +179,28 @@ public class EditorRenderer extends LevelRenderer{
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawMapTileForDataTileMode(byte[] p, int x, int y) {
|
||||
int tilerX = (int)(RabiClone.MOUSE_POS.getX()+getX())/Tile.TILE_WIDTH;
|
||||
int tilerY = (int)(RabiClone.MOUSE_POS.getY()+getY())/Tile.TILE_HEIGHT;
|
||||
if (x==tilerX&&y==tilerY) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawDataTile(byte[] p, double x, double y, DataTile tile) {
|
||||
DrawTransparentDataTile(p,x,y,tile,PaletteColor.MIDNIGHT_BLUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
public void KeyPressed(Action a) {
|
||||
|
@ -15,6 +15,7 @@ import sig.engine.objects.AnimatedObject;
|
||||
import sig.engine.objects.Object;
|
||||
import sig.engine.String;
|
||||
import sig.map.Background;
|
||||
import sig.map.DataTile;
|
||||
import sig.map.Map;
|
||||
import sig.map.Tile;
|
||||
|
||||
@ -43,6 +44,9 @@ 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (RabiClone.player!=null) {
|
||||
@ -83,8 +87,6 @@ public class LevelRenderer extends Object{
|
||||
//RenderCollisionGrid(p);
|
||||
}
|
||||
|
||||
protected void drawMapTileForEditorMode(int x, int y) {}
|
||||
|
||||
/**
|
||||
* Draws an object where its sprite is centered among its position and drawn relative to the camera position.
|
||||
* @param object
|
||||
@ -105,6 +107,9 @@ 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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user