Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • SuperNativeZ: 2009SCAPE - Perfect Realistic Emulation. Play Runescape like it was in 2009. [link]
      February 18, 2020, 01:04:45 PM
    • SuperNativeZ: 2009SCAPE - Perfect Realistic Emulation. Play Runescape like it was in 2009. [link]
      February 18, 2020, 01:04:39 PM
    • SuperNativeZ: 2009SCAPE - Perfect Realistic Emulation. Play Runescape like it was in 2009. [link]
      February 18, 2020, 01:04:35 PM
    • ragnoroker: Join RuneGuild Today! BIG DROP PARTY IN 1 HOUR JOIN NOW - Newish Server 30+ Online all the time - Very Unique - Play now : [link]
      February 15, 2020, 04:16:38 PM
    • ragnoroker: Join RuneGuild Today! BIG DROP PARTY IN 1 HOUR JOIN NOW - Discord : [link]
      February 15, 2020, 04:15:41 PM
    • ragnoroker: Join RuneGuild Today! BIG DROP PARTY IN 1 HOUR JOIN NOW :) - [link]
      February 15, 2020, 04:14:50 PM
    • friendlyhelper: Meet up with old and new friends and explore what Runescape Classic could have been had development continued [link]
      February 15, 2020, 03:55:17 PM
    • friendlyhelper: Meet up with old and new friends and explore what Runescape Classic could have been had development continued [link]
      February 15, 2020, 03:49:34 PM
    • friendlyhelper: After well over 6 years of continuous runtime, RSCR still most actively developed RSC server  [link]
      February 15, 2020, 03:49:29 PM
    • SnowRSPS: Checkout Snowrsps.com - Snow317.org - Snowscape.net Open 24.7 [link] !Do not join Galaxy!
      February 15, 2020, 08:15:39 AM
    • SnowRSPS: Checkout Snowrsps.com - Snow317.org - Snowscape.net Open 24.7 [link] !Do not join Galaxy!
      February 15, 2020, 08:15:32 AM
    • SuperNativeZ: GALAXY #1 UNIQUE CUSTOM RSPS [link][link]
      February 14, 2020, 12:27:16 PM
    • SuperNativeZ: GALAXY #1 UNIQUE CUSTOM RSPS [link][link]
      February 14, 2020, 12:27:11 PM
    • SuperNativeZ: GALAXY #1 UNIQUE CUSTOM RSPS [link][link]
      February 14, 2020, 12:27:00 PM
    • ragnoroker: Looking for a new server? Join RuneGuild : [link] You won't be disappointed.
      February 14, 2020, 07:49:42 AM
    • ragnoroker: Looking for a new server? Join RuneGuild : [link] You won't be disappointed.
      February 14, 2020, 07:49:37 AM
    • ragnoroker: Looking for a new server? Join RuneGuild : [link] You won't be disappointed.
      February 14, 2020, 07:49:33 AM
    • Tonystark2830: https: //discord .gg /AHeVSMQ
      February 13, 2020, 11:35:21 AM
    • Tonystark2830:[link]
      February 13, 2020, 11:35:06 AM
    • Tonystark2830:[link] who ever has the most invites will be given money weekly! whats the catch? you must have over 15 invites for the week!  if you are tied with someone else at the end of the week you will both be awarded the same amount "no it will not be split"
      February 13, 2020, 11:34:42 AM

    Author Topic: [317refactor] Adding dynamic snow  (Read 712 times)

    0 Members and 1 Guest are viewing this topic.

    OfflineAmbokile

    • Member
    • ****
    • Posts: 3,009
    • Thanks: +0/-0
      • View Profile
    [317refactor] Adding dynamic snow
    « on: February 08, 2015, 06:42:12 PM »
    Hi guys. Quick snippet on how to add this:


    First, add the Snowflake class to your client:
    Code: Java
    1. packagecom.jagex.runescape.display;
    2.  
    3. importjava.util.Arrays;
    4. importjava.util.Collections;
    5. importjava.util.List;
    6. importjava.util.Random;
    7.  
    8. importcom.jagex.runescape.DrawingArea;
    9.  
    10. publicclass Snowflake {
    11.        
    12.         staticfinalint BOTTOM_OF_SCREEN =329;
    13.        
    14.         publicenum FallSpeed {
    15.                 SLOW(1),
    16.                 MEDIUM(2),
    17.                 FAST(3);
    18.                
    19.                 privateint speed;
    20.                
    21.                 FallSpeed(int speed){
    22.                         this.speed= speed;
    23.                 }
    24.                
    25.                 publicint getSpeed(){
    26.                         returnthis.speed;
    27.                 }
    28.                
    29.                 privatestaticfinal List<FallSpeed> VALUES
    30.                                                 =Collections.unmodifiableList(Arrays.asList(values()));
    31.                 privatestaticfinalint SIZE = VALUES.size();
    32.                 privatestaticfinalRandom RANDOM =newRandom();
    33.  
    34.                 publicstatic FallSpeed randomSpeed()  {
    35.                     return VALUES.get(RANDOM.nextInt(SIZE));
    36.                 }
    37.         }
    38.  
    39.         int y;
    40.         int x;
    41.         int size;
    42.         int lastTick;
    43.         int colour;
    44.         int alpha;
    45.         FallSpeed speed;
    46.         boolean awaitingRemoval;
    47.        
    48.         public Snowflake(int x, int y, int size, int startTick, int colour, int alpha, FallSpeed speed){
    49.                 this.y= x;
    50.                 this.x= y;
    51.                 this.size= size;
    52.                 this.lastTick= startTick;
    53.                 this.colour= colour;
    54.                 this.alpha= alpha;
    55.                 this.speed= speed;
    56.         }
    57.        
    58.         publicvoid move(){
    59.                 if(this.atBottom())
    60.                         return;
    61.                
    62.                 Random r =newRandom();
    63.                 int changeDirection = r.nextInt(9);
    64.                
    65.                 if(changeDirection ==1)
    66.                         this.x--;
    67.                
    68.                 if(changeDirection ==2)
    69.                         this.x++;
    70.         }
    71.        
    72.         publicvoid fall(int delta){
    73.                 if(this.atBottom())
    74.                         return;
    75.                
    76.                 y +=(delta * speed.getSpeed());
    77.         }
    78.        
    79.         publicvoid melt(int delta){
    80.                 this.setAlpha(this.alpha-(delta *5));
    81.                 if(this.getAlpha()==0)
    82.                         this.awaitingRemoval=true;
    83.         }
    84.        
    85.         publicvoid draw(int currentTick){            
    86.                 int delta =(currentTick -this.lastTick);
    87.                 this.lastTick= currentTick;
    88.                
    89.                 this.move();
    90.                 this.fall(delta);
    91.                
    92.                 if(this.atBottom())
    93.                         this.melt(delta);
    94.                
    95.                 DrawingArea.drawFilledCircleAlpha(
    96.                                 this.y,
    97.                                 this.x,
    98.                                 this.size,
    99.                                 this.colour,
    100.                                 this.alpha);
    101.         }
    102.        
    103.         publicint getY(){
    104.                 returnthis.y;
    105.         }
    106.        
    107.         publicvoid setY(int y){
    108.                 this.y= y;
    109.         }
    110.        
    111.         publicint getAlpha(){
    112.                 returnthis.alpha;
    113.         }
    114.        
    115.         publicvoid setAlpha(int alpha){
    116.                 if(alpha <0)
    117.                         alpha =0;
    118.                        
    119.                 this.alpha= alpha;
    120.         }
    121.        
    122.         publicboolean atBottom(){
    123.                 if(this.getY()>= BOTTOM_OF_SCREEN +this.size){
    124.                         this.setY(BOTTOM_OF_SCREEN +this.size);
    125.                         returntrue;
    126.                 }
    127.                 returnfalse;
    128.         }
    129.        
    130.         publicboolean awaitingRemoval(){
    131.                 returnthis.awaitingRemoval;
    132.         }
    133. }

    Now head to the renderGameView method in your Client class, and add this above it:
    Code: Java
    1. ArrayList<Snowflake> snowflakes;
    2. int SNOWFLAKE_FALL_DENSITY =30;

    You can change SNOWFLAKE_FALL_DENSITY to change the density of the snow fall, the lower the number the denser the snow.

    Inbetween animateTexture(textureId); and draw3dScreen();, add the following:
    Code: Java
    1. if(snowflakes ==null)
    2.         snowflakes =new ArrayList<Snowflake>();
    3.  
    4. Random r =newRandom();
    5. if(r.nextInt(SNOWFLAKE_FALL_DENSITY)==1){
    6.         int size =0;
    7.         int alpha =0;
    8.         int distance = r.nextInt(3);
    9.         Snowflake.FallSpeed speed =null;
    10.         switch(distance){
    11.                 case0:
    12.                         size =3;
    13.                         alpha =100;
    14.                         speed = Snowflake.FallSpeed.SLOW;
    15.                         break;
    16.                 case1:
    17.                         size =4;
    18.                         alpha =150;
    19.                         speed = Snowflake.FallSpeed.MEDIUM;
    20.                         break;
    21.                 case2:
    22.                         size =5;
    23.                         alpha =200;
    24.                         speed = Snowflake.FallSpeed.MEDIUM;
    25.                         break;
    26.                 case3:
    27.                         size =6;
    28.                         alpha =250;
    29.                         speed = Snowflake.FallSpeed.FAST;
    30.                         break;
    31.         }
    32.                        
    33.         int horizontalposition = r.nextInt(515);
    34.                        
    35.         Snowflake s =new Snowflake(-size *2,  horizontalposition, size,
    36.                                 renderCount, 0xFFFFFF, alpha, speed);
    37.                        
    38.         snowflakes.add(s);
    39. }
    40.                
    41. Iterator<Snowflake> s_i = snowflakes.iterator();
    42. while(s_i.hasNext()){
    43.         Snowflake s = s_i.next();
    44.                
    45.         if(s.awaitingRemoval())
    46.                 s_i.remove();
    47.                                
    48.         s.draw(renderCount);
    49. }

    Done! All feedback appreciated.
    Runescape Gambling

    OfflineRyley

    • Member
    • ****
    • *
    • Posts: 7,315
    • Thanks: +0/-0
      • View Profile
    Re: [317refactor] Adding dynamic snow
    « Reply #1 on: February 08, 2015, 11:46:29 PM »
    Code: Java
    1. Arrays.asList(values())

    What

    Code: Java
    1. EnumSet.allOf(FallSpeed.class);
    2.  

     

    Copyright © 2017 MoparScape. All rights reserved.
    Powered by SMFPacks SEO Pro Mod |
    SimplePortal 2.3.5 © 2008-2012, SimplePortal