Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • ragnoroker: New Server - Unique - Awesome Community - Start your adventure : [link]
      Today at 12:52:54 PM
    • ragnoroker: New Server - Unique - Awesome Community - Start your adventure : [link]
      Today at 12:52:50 PM
    • U Go Home: hey does anyone have allstarscape v2 i want to make it better something to do and try and bring back the good old days
      Today at 09:22:14 AM
    • ArtexAdv:[link] come check out the most
      November 18, 2019, 11:39:14 AM
    • ArtexAdv: Www.galaxy-rsps.net come check out the most unique custom rsps
      November 18, 2019, 11:38:50 AM
    • ragnoroker: New Server - Unique - Awesome Community - Start your adventure : [link]
      November 17, 2019, 10:14:59 PM
    • ragnoroker: New Server - Unique - Awesome Community - Start your adventure : [link]
      November 17, 2019, 10:14:50 PM
    • Mazeingmaze: last logged in 2008
      November 17, 2019, 06:46:52 PM
    • Mazeingmaze: Ayy BRO
      November 17, 2019, 06:46:46 PM
    • SuperNativeZ: WANT TO BE APART OF THE BEST RSPS? [link]
      November 17, 2019, 12:22:53 AM
    • SuperNativeZ: WHY CHOOSE GALAXY RSPS?  WE HAVE THE BEST UNIQUE GAMEPLAY [link]
      November 17, 2019, 12:22:42 AM
    • SuperNativeZ: WHY CHOOSE GALAXY RSPS?  WE HAVE THE BEST UNIQUE GAMEPLAY [link]
      November 17, 2019, 12:22:39 AM
    • ragnoroker: Brand new server, come join the fun - unique server - RuneGuild -[link]
      November 15, 2019, 12:46:05 PM
    • ragnoroker: Brand new server, come join the fun - unique server - RuneGuild -[link]
      November 15, 2019, 12:46:01 PM
    • Cole1497: join horney scape we are horney all the time and have a sex emote
      November 09, 2019, 05:14:33 PM
    • thewraith500: try autoscape,0rg brand new osrs CUSTOMS server! fight caves for flaming fire cape, upgrade them to infernal wings + more!
      November 09, 2019, 01:37:29 AM
    • SuperNativeZ: Come play brand new server [link]
      November 08, 2019, 02:13:24 PM
    • SuperNativeZ: Come play brand new server [link]
      November 08, 2019, 02:13:17 PM
    • SuperNativeZ: Come play brand new server [link]
      November 08, 2019, 02:13:14 PM
    • ragnoroker: Brand new server, come join the fun - unique server - RuneGuild - [link]
      November 07, 2019, 11:55:44 AM

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