diff --git a/src/sig/JavaProjectTemplate.java b/src/sig/JavaProjectTemplate.java index 0ad4c62..972e46b 100644 --- a/src/sig/JavaProjectTemplate.java +++ b/src/sig/JavaProjectTemplate.java @@ -60,7 +60,7 @@ public class JavaProjectTemplate { game.Draw(100,20,Color.BLACK); game.Draw_Line(10,10,35,35,Color.BLACK); - game.Draw_Sprite(450,75,bookSpr); + game.Draw_Sprite(450,75,bookSpr,Color.GREEN); game.Draw_Sprite(450,75+bookSpr.getHeight(),bookSpr,Transform.VERTICAL); game.Draw_Animated_Sprite(pl.x,pl.y,pl.spr,pl.animationFrame); @@ -68,7 +68,7 @@ public class JavaProjectTemplate { game.Draw_Text(10,40,"Hello World!",Font.PROFONT_12); game.Draw_Text_Ext(10,52,"Hello World 2!",Font.PROFONT_36,Color.MAGENTA); - game.Fill_Triangle(160,160,190,190,50,250,Color.RED); + game.Fill_Triangle(160,160,190,190,50,250,new Color(255,0,0,150)); game.FillTexturedTriangle( List.of( @@ -83,9 +83,9 @@ public class JavaProjectTemplate { ) , List.of( - Color.BLUE, - Color.BLUE, - Color.BLUE + new Color(0,0,0,0), + Color.WHITE, + Color.RED ), bookSpr); } diff --git a/src/sig/engine/Panel.java b/src/sig/engine/Panel.java index 2f1aea3..60c3641 100644 --- a/src/sig/engine/Panel.java +++ b/src/sig/engine/Panel.java @@ -375,7 +375,11 @@ public class Panel extends JPanel implements Runnable,KeyListener { } void Draw(int index, int col) { - pixel[index]=col; + if (((col>>>24)&0xff)!=255) { + pixel[index]=ColorLerpNoAlpha(new Color(pixel[index]),new Color(col),((col>>>24)&0xff)/255f).getColor(); + } else { + pixel[index]=col; + } } @Override @@ -536,33 +540,36 @@ public class Panel extends JPanel implements Runnable,KeyListener { } public void Draw_Sprite(double x, double y, Sprite sprite){ - Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,Transform.NONE ); + Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,Color.WHITE,Transform.NONE); } public void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex){ Rectangle frameRectangle=sprite.getFrame((int)frameIndex); - Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,frameIndex,Transform.NONE); + Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,frameIndex,Color.WHITE,Transform.NONE); } + public void Draw_Sprite(double x, double y, Sprite sprite, Color col){ + Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,col,Transform.NONE); + } public void Draw_Sprite(double x, double y, Sprite sprite, Transform transform){ - Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,transform); + Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,Color.WHITE,transform); } - public void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex, Transform transform){ + public void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex, Color col, Transform transform){ Rectangle frameRectangle=sprite.getFrame((int)frameIndex); - Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,frameIndex, transform); + Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,frameIndex,col,transform); } - public void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Transform transform){ - Draw_Sprite_Partial_Ext(x,y,xOffset,yOffset,w,h,sprite,frame_index, Color.WHITE,transform); + public void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Color col, Transform transform){ + Draw_Sprite_Partial_Ext(x,y,xOffset,yOffset,w,h,sprite,frame_index, col,transform); } - public void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Transform transform){ - Draw_Sprite_Partial_Ext(x, y, xOffset, yOffset, w, h, sprite, 0, Color.WHITE, transform); + public void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Color col, Transform transform){ + Draw_Sprite_Partial_Ext(x, y, xOffset, yOffset, w, h, sprite, 0, col, transform); } - public void Draw_Animated_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, AnimatedSprite sprite, double frameIndex, Transform transform){ + public void Draw_Animated_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, AnimatedSprite sprite, double frameIndex, Color col, Transform transform){ Rectangle frameRectangle=sprite.getFrame((int)frameIndex); - Draw_Sprite_Partial_Ext(x, y, frameRectangle.getX(), frameRectangle.getY(), frameRectangle.getWidth(), frameRectangle.getHeight(), sprite, 0, Color.WHITE, transform); + Draw_Sprite_Partial_Ext(x, y, frameRectangle.getX(), frameRectangle.getY(), frameRectangle.getWidth(), frameRectangle.getHeight(), sprite, 0, col, transform); } public void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Color col, Transform transform){ @@ -585,7 +592,17 @@ public class Panel extends JPanel implements Runnable,KeyListener { if (((sprite.getImg().getRGB(X,Y)>>>24)&0xFF)==0||index<0||index>=pixel.length) { continue; } else { - Draw(index,(col==Color.WHITE)?sprite.getImg().getRGB(X,Y):col.getColor()); + if (col==Color.WHITE) { + Draw(index,sprite.getImg().getRGB(X,Y)); + } else { + Color img = new Color(sprite.getImg().getRGB(X,Y)); + Draw(index,new Color( + (int)Math.min(255.0f,Math.max(0,(float)img.r * col.r / 255.0f)), + (int)Math.min(255.0f,Math.max(0,(float)img.g * col.g / 255.0f)), + (int)Math.min(255.0f,Math.max(0,(float)img.b * col.b / 255.0f)), + (int)Math.min(255.0f,Math.max(0,(float)img.a * col.a / 255.0f))).getColor() + ); + } } } } @@ -994,6 +1011,10 @@ public class Panel extends JPanel implements Runnable,KeyListener { { return new Color((int)((c2.r * t) + c1.r * (1.0f - t)),(int)((c2.g * t) + c1.g * (1.0f - t)),(int)((c2.b * t) + c1.b * (1.0f - t)),(int)((c2.a * t) + c1.a * (1.0f - t))); } + Color ColorLerpNoAlpha(Color c1, Color c2, float t) + { return new Color((int)((c2.r * t) + c1.r * (1.0f - t)),(int)((c2.g * t) + c1.g * (1.0f - t)),(int)((c2.b * t) + c1.b * (1.0f - t))); } + + public void Clear(Color col){ for (int y=0;y