Per-Object Transparency implemented
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
ed4df8be84
commit
5cd9d4fde7
Binary file not shown.
@ -131,24 +131,24 @@ public class DrawLoop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Draw_Sprite(double x, double y, Sprite sprite){
|
public static 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,Alpha.ALPHA0,Transform.NONE );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex){
|
public static void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex){
|
||||||
Rectangle frameRectangle=sprite.getFrame((int)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,Alpha.ALPHA0,Transform.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Draw_Sprite(double x, double y, Sprite sprite, Transform transform){
|
public static 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,Alpha.ALPHA0,transform);
|
||||||
}
|
}
|
||||||
public static void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex,Transform transform){
|
public static void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex,Alpha alpha,Transform transform){
|
||||||
Rectangle frameRectangle=sprite.getFrame((int)frameIndex);
|
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, alpha, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Transform transform){
|
public static void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Alpha alpha, Transform transform){
|
||||||
Draw_Sprite_Partial_Ext(x,y,xOffset,yOffset,w,h,sprite,frame_index,Alpha.ALPHA128,PaletteColor.NORMAL,transform);
|
Draw_Sprite_Partial_Ext(x,y,xOffset,yOffset,w,h,sprite,frame_index,alpha,PaletteColor.NORMAL,transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Alpha alpha, Transform transform){
|
public static void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Alpha alpha, Transform transform){
|
||||||
@ -172,6 +172,9 @@ public class DrawLoop {
|
|||||||
if (transparentRunCount++==transparentTotalCount) {
|
if (transparentRunCount++==transparentTotalCount) {
|
||||||
transparentRunCount=0;
|
transparentRunCount=0;
|
||||||
continue;
|
continue;
|
||||||
|
} else
|
||||||
|
if (transparentRunCount>alpha.getA()) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (X+x-xOffset<0||Y+y-yOffset<0||X-xOffset+x>=RabiClone.BASE_WIDTH||Y-yOffset+y>=RabiClone.BASE_HEIGHT) {
|
if (X+x-xOffset<0||Y+y-yOffset<0||X-xOffset+x>=RabiClone.BASE_WIDTH||Y-yOffset+y>=RabiClone.BASE_HEIGHT) {
|
||||||
|
@ -18,6 +18,7 @@ import sig.engine.Transform;
|
|||||||
|
|
||||||
public abstract class Object implements GameEntity{
|
public abstract class Object implements GameEntity{
|
||||||
double x,y;
|
double x,y;
|
||||||
|
Alpha transparency;
|
||||||
Sprite spr;
|
Sprite spr;
|
||||||
Panel panel;
|
Panel panel;
|
||||||
protected Rectangle collisionBox;
|
protected Rectangle collisionBox;
|
||||||
@ -62,7 +63,12 @@ public abstract class Object implements GameEntity{
|
|||||||
public void setSprite(Sprite spr) {
|
public void setSprite(Sprite spr) {
|
||||||
this.spr = spr;
|
this.spr = spr;
|
||||||
}
|
}
|
||||||
|
public Alpha getTransparency() {
|
||||||
|
return getTransparency();
|
||||||
|
}
|
||||||
|
public void setTransparency(Alpha alpha) {
|
||||||
|
this.transparency=alpha;
|
||||||
|
}
|
||||||
public void drawBackground(byte[] p) {
|
public void drawBackground(byte[] p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,8 +99,8 @@ public abstract class Object implements GameEntity{
|
|||||||
DrawLoop.Draw_Animated_Sprite(x,y,sprite,frameIndex);
|
DrawLoop.Draw_Animated_Sprite(x,y,sprite,frameIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex, Transform transform){
|
protected void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex, Alpha alpha, Transform transform){
|
||||||
DrawLoop.Draw_Animated_Sprite(x,y,sprite,frameIndex,transform);
|
DrawLoop.Draw_Animated_Sprite(x,y,sprite,frameIndex,alpha,transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void Draw_Text(double x, double y, String string, Font font){
|
protected void Draw_Text(double x, double y, String string, Font font){
|
||||||
@ -105,8 +111,8 @@ public abstract class Object implements GameEntity{
|
|||||||
DrawLoop.Draw_Text_Ext(x,y,string,font,alpha,col);
|
DrawLoop.Draw_Text_Ext(x,y,string,font,alpha,col);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Transform transform){
|
protected void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index,Alpha alpha, Transform transform){
|
||||||
DrawLoop.Draw_Sprite_Partial(x,y,xOffset,yOffset,w,h,sprite,frame_index,transform);
|
DrawLoop.Draw_Sprite_Partial(x,y,xOffset,yOffset,w,h,sprite,frame_index,alpha,transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Alpha alpha,Transform transform){
|
protected void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Alpha alpha,Transform transform){
|
||||||
|
@ -7,6 +7,7 @@ import sig.engine.Action;
|
|||||||
import sig.engine.Alpha;
|
import sig.engine.Alpha;
|
||||||
import sig.engine.Font;
|
import sig.engine.Font;
|
||||||
import sig.engine.Key;
|
import sig.engine.Key;
|
||||||
|
import sig.engine.MouseScrollValue;
|
||||||
import sig.engine.PaletteColor;
|
import sig.engine.PaletteColor;
|
||||||
import sig.engine.Panel;
|
import sig.engine.Panel;
|
||||||
import sig.engine.Sprite;
|
import sig.engine.Sprite;
|
||||||
@ -70,46 +71,46 @@ public class LevelRenderer extends Object{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRipples(double updateMult) {
|
private void updateRipples(double updateMult) {
|
||||||
if ((nextRipple-=updateMult)<0) {
|
if ((nextRipple-=updateMult)<0) {
|
||||||
if (Math.random()*RIPPLE_CHANCE<1) {
|
if (Math.random()*RIPPLE_CHANCE<1) {
|
||||||
int selectedIndex=(int)(Math.random()*ripples.length);
|
int selectedIndex=(int)(Math.random()*ripples.length);
|
||||||
if (ripples[selectedIndex]==0) {
|
if (ripples[selectedIndex]==0) {
|
||||||
if (Math.random()<0.5) {
|
if (Math.random()<0.5) {
|
||||||
ripples[selectedIndex]=(byte)(MAX_RIPPLE_SIZE|0b10000000);
|
ripples[selectedIndex]=(byte)(MAX_RIPPLE_SIZE|0b10000000);
|
||||||
} else {
|
} else {
|
||||||
ripples[selectedIndex]=(byte)(MAX_RIPPLE_SIZE|0b00000000);
|
ripples[selectedIndex]=(byte)(MAX_RIPPLE_SIZE|0b00000000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
for (int i=0;i<ripples.length;i++) {
|
||||||
for (int i=0;i<ripples.length;i++) {
|
if (ripples[i]!=0) {
|
||||||
if (ripples[i]!=0) {
|
if ((byte)(ripples[i]>>>7)==-1) {
|
||||||
if ((byte)(ripples[i]>>>7)==-1) {
|
//We are moving left.
|
||||||
//We are moving left.
|
|
||||||
ripples[i]=(byte)(0b10000000|((ripples[i]&0b1111111)-1));
|
|
||||||
if ((ripples[i]&0b1111111)==0) //Flip the sign.
|
|
||||||
{
|
|
||||||
ripples[i]=(byte)(((ripples[i]&0b1111111)+1));
|
|
||||||
} else
|
|
||||||
if ((ripples[i]&0b1111111)==MAX_RIPPLE_SIZE&&Math.random()*RIPPLE_DROP_CHANCE<1) {
|
|
||||||
ripples[i]=0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//We are moving right.
|
|
||||||
ripples[i]=(byte)((ripples[i]&0b1111111)+1);
|
|
||||||
if ((ripples[i]&0b1111111)==MAX_RIPPLE_SIZE*2) //Flip the sign.
|
|
||||||
{
|
|
||||||
ripples[i]=(byte)(0b10000000|((ripples[i]&0b1111111)-1));
|
ripples[i]=(byte)(0b10000000|((ripples[i]&0b1111111)-1));
|
||||||
} else
|
if ((ripples[i]&0b1111111)==0) //Flip the sign.
|
||||||
if ((ripples[i]&0b1111111)==MAX_RIPPLE_SIZE&&Math.random()*RIPPLE_DROP_CHANCE<1) {
|
{
|
||||||
ripples[i]=0;
|
ripples[i]=(byte)(((ripples[i]&0b1111111)+1));
|
||||||
|
} else
|
||||||
|
if ((ripples[i]&0b1111111)==MAX_RIPPLE_SIZE&&Math.random()*RIPPLE_DROP_CHANCE<1) {
|
||||||
|
ripples[i]=0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//We are moving right.
|
||||||
|
ripples[i]=(byte)((ripples[i]&0b1111111)+1);
|
||||||
|
if ((ripples[i]&0b1111111)==MAX_RIPPLE_SIZE*2) //Flip the sign.
|
||||||
|
{
|
||||||
|
ripples[i]=(byte)(0b10000000|((ripples[i]&0b1111111)-1));
|
||||||
|
} else
|
||||||
|
if ((ripples[i]&0b1111111)==MAX_RIPPLE_SIZE&&Math.random()*RIPPLE_DROP_CHANCE<1) {
|
||||||
|
ripples[i]=0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
nextRipple=0.2;
|
||||||
}
|
}
|
||||||
nextRipple=0.2;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(byte[] p) {
|
public void draw(byte[] p) {
|
||||||
@ -260,14 +261,14 @@ private void updateRipples(double updateMult) {
|
|||||||
protected void Draw_Animated_Object(AnimatedObject object, Transform transform){
|
protected void Draw_Animated_Object(AnimatedObject object, Transform transform){
|
||||||
if (object instanceof PhysicsObject) {
|
if (object instanceof PhysicsObject) {
|
||||||
PhysicsObject po = (PhysicsObject)object;
|
PhysicsObject po = (PhysicsObject)object;
|
||||||
super.Draw_Animated_Sprite(object.getX()-this.getX()-object.getAnimatedSpr().getWidth()/2+(po.state==State.STAGGER?staggerOffsetX:0), Math.round(object.getY()-this.getY()-object.getAnimatedSpr().getHeight()/2), object.getAnimatedSpr(), object.getCurrentFrame(), transform);
|
super.Draw_Animated_Sprite(object.getX()-this.getX()-object.getAnimatedSpr().getWidth()/2+(po.state==State.STAGGER?staggerOffsetX:0), Math.round(object.getY()-this.getY()-object.getAnimatedSpr().getHeight()/2), object.getAnimatedSpr(), object.getCurrentFrame(), object.getTransparency(), transform);
|
||||||
} else {
|
} else {
|
||||||
super.Draw_Animated_Sprite(object.getX()-this.getX()-object.getAnimatedSpr().getWidth()/2, Math.round(object.getY()-this.getY()-object.getAnimatedSpr().getHeight()/2), object.getAnimatedSpr(), object.getCurrentFrame(), transform);
|
super.Draw_Animated_Sprite(object.getX()-this.getX()-object.getAnimatedSpr().getWidth()/2, Math.round(object.getY()-this.getY()-object.getAnimatedSpr().getHeight()/2), object.getAnimatedSpr(), object.getCurrentFrame(), object.getTransparency(), transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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(), 0, Transform.NONE);
|
Draw_Sprite_Partial(x,y, tile.getSpriteSheetX()*tile.getTileWidth(), tile.getSpriteSheetY()*tile.getTileHeight(), tile.getTileWidth(), tile.getTileHeight(), getSprite(), 0, Alpha.ALPHA0, Transform.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void DrawTransparentTile(double x, double y, Tile tile, Alpha alpha) {
|
protected void DrawTransparentTile(double x, double y, Tile tile, Alpha alpha) {
|
||||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import sig.RabiClone;
|
import sig.RabiClone;
|
||||||
import sig.engine.Action;
|
import sig.engine.Action;
|
||||||
|
import sig.engine.Alpha;
|
||||||
import sig.engine.Panel;
|
import sig.engine.Panel;
|
||||||
import sig.engine.Rectangle;
|
import sig.engine.Rectangle;
|
||||||
import sig.engine.Sprite;
|
import sig.engine.Sprite;
|
||||||
@ -69,6 +70,7 @@ public class Player extends PhysicsObject{
|
|||||||
setJumpVelocity_UseDefaultStrategy();
|
setJumpVelocity_UseDefaultStrategy();
|
||||||
setMaxJumpCount_UseDefaultStrategy();
|
setMaxJumpCount_UseDefaultStrategy();
|
||||||
setGravity_UseDefaultStrategy();
|
setGravity_UseDefaultStrategy();
|
||||||
|
setTransparency(Alpha.ALPHA128);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user