atm959

Clouds.java

Apr 27th, 2016
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. package com.atm959.sourceCode;
  2.  
  3. import java.awt.Graphics;
  4. import java.awt.image.BufferedImage;
  5. import java.io.File;
  6. import java.io.IOException;
  7. import java.util.Random;
  8.  
  9. import javax.imageio.ImageIO;
  10.  
  11. public class Clouds {
  12.    
  13.     public static Random random = new Random();
  14.     public static int[] cloudXPositions = {random.nextInt(Component.PIXEL.width - 32), random.nextInt(Component.PIXEL.width - 32), random.nextInt(Component.PIXEL.width - 32), random.nextInt(Component.PIXEL.width - 32), random.nextInt(Component.PIXEL.width - 32), random.nextInt(Component.PIXEL.width - 32), random.nextInt(Component.PIXEL.width - 32), random.nextInt(Component.PIXEL.width - 32), random.nextInt(Component.PIXEL.width - 32), random.nextInt(Component.PIXEL.width - 32)};
  15.     public static int[] cloudYPositions = {random.nextInt(Component.PIXEL.height - 16), random.nextInt(Component.PIXEL.height - 16), random.nextInt(Component.PIXEL.height - 16), random.nextInt(Component.PIXEL.height - 16), random.nextInt(Component.PIXEL.height - 16), random.nextInt(Component.PIXEL.height - 16), random.nextInt(Component.PIXEL.height - 16), random.nextInt(Component.PIXEL.height - 16), random.nextInt(Component.PIXEL.height - 16), random.nextInt(Component.PIXEL.height - 16)};
  16.     public static double cloudOffset;
  17.     BufferedImage cloud;
  18.     public static int i;
  19.    
  20.     public Clouds() throws IOException{
  21.        
  22.         System.out.println("Loaded Clouds.java");
  23.         cloud = ImageIO.read(new File("res/images/cloud.png"));
  24.        
  25.     }
  26.    
  27.     public void tick(){
  28.        
  29.         cloudOffset += 0.5;
  30.         if(cloudOffset > Component.PIXEL.width){
  31.             for(i = 0; i <= 9; i++){
  32.                 cloudXPositions[i] = random.nextInt(random.nextInt(Component.PIXEL.width - 32));
  33.                 cloudYPositions[i] = random.nextInt(random.nextInt(Component.PIXEL.height - 16));
  34.             }
  35.             cloudOffset = (-Component.PIXEL.width);
  36.         }
  37.        
  38.     }
  39.    
  40.     public void render(Graphics g){
  41.        
  42.         for(i = 0; i <= 9; i++){
  43.             g.drawImage(cloud, cloudXPositions[i] + (int)cloudOffset, cloudYPositions[i], null);
  44.         }
  45.        
  46.     }
  47.    
  48. }
Advertisement
Add Comment
Please, Sign In to add comment