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){
|
||||
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){
|
||||
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){
|
||||
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);
|
||||
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){
|
||||
Draw_Sprite_Partial_Ext(x,y,xOffset,yOffset,w,h,sprite,frame_index,Alpha.ALPHA128,PaletteColor.NORMAL,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,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){
|
||||
@ -172,6 +172,9 @@ public class DrawLoop {
|
||||
if (transparentRunCount++==transparentTotalCount) {
|
||||
transparentRunCount=0;
|
||||
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) {
|
||||
|
@ -18,6 +18,7 @@ import sig.engine.Transform;
|
||||
|
||||
public abstract class Object implements GameEntity{
|
||||
double x,y;
|
||||
Alpha transparency;
|
||||
Sprite spr;
|
||||
Panel panel;
|
||||
protected Rectangle collisionBox;
|
||||
@ -62,7 +63,12 @@ public abstract class Object implements GameEntity{
|
||||
public void setSprite(Sprite spr) {
|
||||
this.spr = spr;
|
||||
}
|
||||
|
||||
public Alpha getTransparency() {
|
||||
return getTransparency();
|
||||
}
|
||||
public void setTransparency(Alpha alpha) {
|
||||
this.transparency=alpha;
|
||||
}
|
||||
public void drawBackground(byte[] p) {
|
||||
}
|
||||
|
||||
@ -93,8 +99,8 @@ public abstract class Object implements GameEntity{
|
||||
DrawLoop.Draw_Animated_Sprite(x,y,sprite,frameIndex);
|
||||
}
|
||||
|
||||
protected void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex, Transform transform){
|
||||
DrawLoop.Draw_Animated_Sprite(x,y,sprite,frameIndex,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,alpha,transform);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
protected void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Transform transform){
|
||||
DrawLoop.Draw_Sprite_Partial(x,y,xOffset,yOffset,w,h,sprite,frame_index,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,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){
|
||||
|
@ -7,6 +7,7 @@ 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.Sprite;
|
||||
@ -70,46 +71,46 @@ public class LevelRenderer extends Object{
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRipples(double updateMult) {
|
||||
if ((nextRipple-=updateMult)<0) {
|
||||
if (Math.random()*RIPPLE_CHANCE<1) {
|
||||
int selectedIndex=(int)(Math.random()*ripples.length);
|
||||
if (ripples[selectedIndex]==0) {
|
||||
if (Math.random()<0.5) {
|
||||
ripples[selectedIndex]=(byte)(MAX_RIPPLE_SIZE|0b10000000);
|
||||
} else {
|
||||
ripples[selectedIndex]=(byte)(MAX_RIPPLE_SIZE|0b00000000);
|
||||
private void updateRipples(double updateMult) {
|
||||
if ((nextRipple-=updateMult)<0) {
|
||||
if (Math.random()*RIPPLE_CHANCE<1) {
|
||||
int selectedIndex=(int)(Math.random()*ripples.length);
|
||||
if (ripples[selectedIndex]==0) {
|
||||
if (Math.random()<0.5) {
|
||||
ripples[selectedIndex]=(byte)(MAX_RIPPLE_SIZE|0b10000000);
|
||||
} else {
|
||||
ripples[selectedIndex]=(byte)(MAX_RIPPLE_SIZE|0b00000000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i=0;i<ripples.length;i++) {
|
||||
if (ripples[i]!=0) {
|
||||
if ((byte)(ripples[i]>>>7)==-1) {
|
||||
//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.
|
||||
{
|
||||
for (int i=0;i<ripples.length;i++) {
|
||||
if (ripples[i]!=0) {
|
||||
if ((byte)(ripples[i]>>>7)==-1) {
|
||||
//We are moving left.
|
||||
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;
|
||||
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));
|
||||
} else
|
||||
if ((ripples[i]&0b1111111)==MAX_RIPPLE_SIZE&&Math.random()*RIPPLE_DROP_CHANCE<1) {
|
||||
ripples[i]=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nextRipple=0.2;
|
||||
}
|
||||
nextRipple=0.2;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(byte[] p) {
|
||||
@ -260,14 +261,14 @@ private void updateRipples(double updateMult) {
|
||||
protected void Draw_Animated_Object(AnimatedObject object, Transform transform){
|
||||
if (object instanceof PhysicsObject) {
|
||||
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 {
|
||||
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) {
|
||||
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) {
|
||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
import sig.RabiClone;
|
||||
import sig.engine.Action;
|
||||
import sig.engine.Alpha;
|
||||
import sig.engine.Panel;
|
||||
import sig.engine.Rectangle;
|
||||
import sig.engine.Sprite;
|
||||
@ -69,6 +70,7 @@ public class Player extends PhysicsObject{
|
||||
setJumpVelocity_UseDefaultStrategy();
|
||||
setMaxJumpCount_UseDefaultStrategy();
|
||||
setGravity_UseDefaultStrategy();
|
||||
setTransparency(Alpha.ALPHA128);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user