From 118ec8aa61320e48f4c7fa7643c1c768ff66839c Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Mon, 27 Jun 2022 20:53:22 -0500 Subject: [PATCH] only draw ripples underwater Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- src/sig/objects/LevelRenderer.java | 76 ++++++++++++++++++------------ 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/src/sig/objects/LevelRenderer.java b/src/sig/objects/LevelRenderer.java index a8f6e1c..fe5f1b5 100644 --- a/src/sig/objects/LevelRenderer.java +++ b/src/sig/objects/LevelRenderer.java @@ -66,45 +66,51 @@ public class LevelRenderer extends Object{ staggerOffsetX*=-1; staggerTimer=staggerJitterWaitTime; } - 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); - } + if (RabiClone.player!=null&&RabiClone.player.isUnderwater()) { + updateRipples(updateMult); + } + } + +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>>7)==-1) { - //We are moving left. + } + for (int i=0;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)); - 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; - } + } 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) { @@ -132,7 +138,13 @@ public class LevelRenderer extends Object{ } } } + 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+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