Make selected drawn tile be transparent. Add boundary building code
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
dc048c8fd7
commit
f9b0aadd30
@ -39,7 +39,38 @@ public class DrawLoop {
|
|||||||
if (index<0||index>=p.length||p[index]==sprite.getBi_array()[Y*sprite.getWidth()+X]) {
|
if (index<0||index>=p.length||p[index]==sprite.getBi_array()[Y*sprite.getWidth()+X]) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],true);
|
Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],true);
|
||||||
|
//Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, int alpha){
|
||||||
|
int[] p = panel.pixel;
|
||||||
|
for(int X=(int)xOffset;X<(int)(w+xOffset);X++){
|
||||||
|
for(int Y=(int)yOffset;Y<(int)(h+yOffset);Y++){
|
||||||
|
if (X+x-xOffset<0||Y+y-yOffset<0||X-xOffset+x>=RabiClone.BASE_WIDTH||Y-yOffset+y>=RabiClone.BASE_HEIGHT) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
int index = (Y-(int)yOffset+(int)y)*RabiClone.BASE_WIDTH+X-(int)xOffset+(int)x;
|
||||||
|
if (index<0||index>=p.length||p[index]==sprite.getBi_array()[Y*sprite.getWidth()+X]) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
if (alpha==255) {
|
||||||
|
Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],true);
|
||||||
|
} else {
|
||||||
|
int oldAlpha = sprite.getBi_array()[Y*sprite.getWidth()+X]>>>24;
|
||||||
|
if (oldAlpha==0) {
|
||||||
|
Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],true);
|
||||||
|
} else
|
||||||
|
if (oldAlpha==255) {
|
||||||
|
Draw(p,index,(sprite.getBi_array()[Y*sprite.getWidth()+X]&0x00FFFFFF)|(alpha<<24),true);
|
||||||
|
} {
|
||||||
|
Draw(p,index,(sprite.getBi_array()[Y*sprite.getWidth()+X]&0x00FFFFFF)|((int)((alpha/255d)*oldAlpha)<<24),true);
|
||||||
|
}
|
||||||
|
}
|
||||||
//Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],false);
|
//Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,10 @@ public abstract class Object implements GameEntity{
|
|||||||
DrawLoop.Draw_Sprite_Partial(x,y,xOffset,yOffset,w,h,sprite);
|
DrawLoop.Draw_Sprite_Partial(x,y,xOffset,yOffset,w,h,sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, int alpha){
|
||||||
|
DrawLoop.Draw_Sprite_Partial_Ext(x,y,xOffset,yOffset,w,h,sprite,alpha);
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean KeyHeld(int key) {
|
protected boolean KeyHeld(int key) {
|
||||||
return panel.KEYS.getOrDefault(key,false);
|
return panel.KEYS.getOrDefault(key,false);
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import sig.engine.MouseScrollValue;
|
|||||||
import sig.engine.Object;
|
import sig.engine.Object;
|
||||||
import sig.engine.Panel;
|
import sig.engine.Panel;
|
||||||
import sig.engine.Sprite;
|
import sig.engine.Sprite;
|
||||||
|
import sig.map.Map;
|
||||||
import sig.map.Tile;
|
import sig.map.Tile;
|
||||||
|
|
||||||
public class LevelRenderer extends Object{
|
public class LevelRenderer extends Object{
|
||||||
@ -43,19 +44,25 @@ public class LevelRenderer extends Object{
|
|||||||
int tempIndex = selectedTile.ordinal()+down-up;
|
int tempIndex = selectedTile.ordinal()+down-up;
|
||||||
int selectedIndex = tempIndex<0?Tile.values().length-Math.abs(tempIndex):tempIndex%Tile.values().length;
|
int selectedIndex = tempIndex<0?Tile.values().length-Math.abs(tempIndex):tempIndex%Tile.values().length;
|
||||||
selectedTile = Tile.values()[selectedIndex];
|
selectedTile = Tile.values()[selectedIndex];
|
||||||
//System.out.println(selectedTile);
|
System.out.println(selectedTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(int[] p) {
|
public void draw(int[] p) {
|
||||||
for (int y=(int)(this.getY()/Tile.TILE_HEIGHT);y<(int)(RabiClone.BASE_HEIGHT/Tile.TILE_HEIGHT+this.getY()/Tile.TILE_HEIGHT+1);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++) {
|
||||||
|
if (y<0||y>Map.MAP_HEIGHT) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (int x=(int)(0+this.getX()/Tile.TILE_WIDTH);x<(int)(RabiClone.BASE_WIDTH/Tile.TILE_WIDTH+this.getX()/Tile.TILE_WIDTH+1);x++) {
|
for (int x=(int)(0+this.getX()/Tile.TILE_WIDTH);x<(int)(RabiClone.BASE_WIDTH/Tile.TILE_WIDTH+this.getX()/Tile.TILE_WIDTH+1);x++) {
|
||||||
|
if (x<0||x>Map.MAP_WIDTH) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (RabiClone.CURRENT_MAP.getTile(x,y)!=Tile.VOID) {
|
if (RabiClone.CURRENT_MAP.getTile(x,y)!=Tile.VOID) {
|
||||||
DrawTile(x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),RabiClone.CURRENT_MAP.getTile(x,y));
|
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)));
|
//System.out.println((x*Tile.TILE_WIDTH+(this.getX()%Tile.TILE_WIDTH) )+","+(y*Tile.TILE_HEIGHT+(this.getY()%Tile.TILE_HEIGHT)));
|
||||||
}
|
}
|
||||||
if (x==RabiClone.p.highlightedSquare.getX()&&y==RabiClone.p.highlightedSquare.getY()) {
|
if (x==RabiClone.p.highlightedSquare.getX()&&y==RabiClone.p.highlightedSquare.getY()) {
|
||||||
DrawTile(x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),Tile.HIGHLIGHTED_TILE);
|
DrawTransparentTile(x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),selectedTile,64);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,5 +71,9 @@ public class LevelRenderer extends Object{
|
|||||||
private void DrawTile(double x, double y, Tile tile) {
|
private void DrawTile(double x, double y, Tile tile) {
|
||||||
Draw_Sprite_Partial(x,y, tile.getSpriteSheetX()*tile.getTileWidth(), tile.getSpriteSheetY()*tile.getTileHeight(), tile.getTileWidth(), tile.getTileHeight(), getSprite());
|
Draw_Sprite_Partial(x,y, tile.getSpriteSheetX()*tile.getTileWidth(), tile.getSpriteSheetY()*tile.getTileHeight(), tile.getTileWidth(), tile.getTileHeight(), getSprite());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DrawTransparentTile(double x, double y, Tile tile, int alpha) {
|
||||||
|
Draw_Sprite_Partial_Ext(x,y, tile.getSpriteSheetX()*tile.getTileWidth(), tile.getSpriteSheetY()*tile.getTileHeight(), tile.getTileWidth(), tile.getTileHeight(), getSprite(), alpha);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user