Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • drubrkletern: be honest with me boss
      December 06, 2019, 01:31:52 AM
    • drubrkletern: now is it really that unique
      December 06, 2019, 01:31:47 AM
    • SuperNativeZ: COME PLAY THE MOST UNIQUE CUSTOM RSPS #1 [link][link][link]
      December 05, 2019, 09:22:55 PM
    • SuperNativeZ: FASTEST GROWING #1 UNIQUE CUSTOM RSPS [link][link][link]
      December 05, 2019, 09:22:42 PM
    • ragnoroker: New Server - Unique - Awesome Community - Start your adventure - 60+ online : [link]
      December 05, 2019, 02:48:39 PM
    • ragnoroker: New Server - Unique - Awesome Community - Start your adventure - 40+ online : [link]
      December 05, 2019, 02:48:31 PM
    • Cole1497: you click any of these links? those boner pills theyre selling are wicked
      December 04, 2019, 05:58:03 PM
    • Cole1497: oh shit vain whats crackin
      December 04, 2019, 05:57:49 PM
    • ArtexAdv: FASTEST GROWING #1 UNIQUE CUSTOM RSPS [link]
      December 04, 2019, 06:30:27 AM
    • Vain_: where the boys at
      December 01, 2019, 03:20:36 PM
    • black evil111: They should close this down, mostly the downloads section. The mods dont know how to do their jobs worth shit and its no excuse like "we have real life stuff going on" everyones replacable. Speaking of replacable, fix download links! Before I go to rune-server.
      December 01, 2019, 01:50:26 PM
    • ragnoroker: New Server - Unique - Awesome Community - Start your adventure - 40+ online : [link]
      November 28, 2019, 12:41:24 PM
    • ragnoroker: New Server - Unique - Awesome Community - Start your adventure - 40+ online : [link]
      November 28, 2019, 12:40:42 PM
    • 1strangler77: how do i post pictures on a post
      November 24, 2019, 05:16:18 PM
    • ragnoroker: New Server - Unique - Awesome Community - Start your adventure - 40+ online : [link]
      November 23, 2019, 08:23:51 PM
    • Freja1793: Hi
      November 22, 2019, 07:58:41 PM
    • xdarklordxx: JOIN NOW [link]
      November 22, 2019, 03:19:16 PM
    • xdarklordxx: RUNITY IS BACK AND BETTER THAN EVER VERY NICE STAFF AND TONS OF CUSTOMS!!
      November 22, 2019, 03:18:36 PM
    • xdarklordxx: >!https://dl.dropbox.com/s/9iwtazv703mpqsw/LmfaoScape.jar<!
      November 22, 2019, 03:17:04 PM
    • Shadow Monarch: where do i get a client and source
      November 19, 2019, 11:17:48 PM

    Author Topic: [317refactor] Adding dynamic snow  (Read 685 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