only draw ripples underwater

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent e3b84fcb3f
commit 118ec8aa61
  1. 76
      src/sig/objects/LevelRenderer.java

@ -66,45 +66,51 @@ public class LevelRenderer extends Object{
staggerOffsetX*=-1; staggerOffsetX*=-1;
staggerTimer=staggerJitterWaitTime; staggerTimer=staggerJitterWaitTime;
} }
if ((nextRipple-=updateMult)<0) { if (RabiClone.player!=null&&RabiClone.player.isUnderwater()) {
if (Math.random()*RIPPLE_CHANCE<1) { updateRipples(updateMult);
int selectedIndex=(int)(Math.random()*ripples.length); }
if (ripples[selectedIndex]==0) { }
if (Math.random()<0.5) {
ripples[selectedIndex]=(byte)(MAX_RIPPLE_SIZE|0b10000000); private void updateRipples(double updateMult) {
} else { if ((nextRipple-=updateMult)<0) {
ripples[selectedIndex]=(byte)(MAX_RIPPLE_SIZE|0b00000000); 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) { for (int i=0;i<ripples.length;i++) {
if ((byte)(ripples[i]>>>7)==-1) { if (ripples[i]!=0) {
//We are moving left. 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.
{
ripples[i]=(byte)(0b10000000|((ripples[i]&0b1111111)-1)); ripples[i]=(byte)(0b10000000|((ripples[i]&0b1111111)-1));
if ((ripples[i]&0b1111111)==0) //Flip the sign. } else
{ if ((ripples[i]&0b1111111)==MAX_RIPPLE_SIZE&&Math.random()*RIPPLE_DROP_CHANCE<1) {
ripples[i]=(byte)(((ripples[i]&0b1111111)+1)); ripples[i]=0;
} 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) {
@ -132,7 +138,13 @@ public class LevelRenderer extends Object{
} }
} }
} }
if (RabiClone.player!=null) { if (RabiClone.player!=null) {
if (RabiClone.player.isUnderwater()) {
drawRipples(p);
}
Draw_Text(4,4,new String(RabiClone.player.getYVelocity()),Font.PROFONT_12); Draw_Text(4,4,new String(RabiClone.player.getYVelocity()),Font.PROFONT_12);
Draw_Text(4,4+Font.PROFONT_12.getGlyphHeight(),new String(RabiClone.scaleTime),Font.PROFONT_12); Draw_Text(4,4+Font.PROFONT_12.getGlyphHeight(),new String(RabiClone.scaleTime),Font.PROFONT_12);
} }
@ -178,7 +190,9 @@ public class LevelRenderer extends Object{
} }
} }
} }
}
private void drawRipples(byte[] p) {
for (int i=0;i<ripples.length;i++) { for (int i=0;i<ripples.length;i++) {
if (ripples[i]!=0) { if (ripples[i]!=0) {
for (int y=-MAX_RIPPLE_SIZE/2;y<MAX_RIPPLE_SIZE/2;y++) { for (int y=-MAX_RIPPLE_SIZE/2;y<MAX_RIPPLE_SIZE/2;y++) {

Loading…
Cancel
Save