Advertisement
DavidFoxfire

Particle Script

Feb 28th, 2020
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. package CastleOfDreams;
  2.  
  3. import java.awt.AlphaComposite;
  4. import java.awt.Color;
  5. import java.awt.Graphics;
  6. import java.awt.Graphics2D;
  7. import java.util.Random;
  8.  
  9. public class Particle {
  10.  
  11.     int a, mode, life;
  12.     double x, y, dx, dy;
  13.     int[][] Octarine = {
  14.             {118, 28, 236},
  15.             {148, 35, 190},
  16.             {189, 62, 127},
  17.             {224, 94, 54},
  18.             {253, 133, 3},
  19.     };
  20.     int tempA, tempB;
  21.     int redColor, greenColor, blueColor;
  22.     float alpha;
  23.     Color particleColor;
  24.     Game game;
  25.    
  26.     Random r = new Random();
  27.    
  28.     Particle (double inX, double inY, int inMode, Game game){
  29.         x = inX - 2;
  30.         y = inY - 2;
  31.         mode = inMode;
  32.         dx = (double) (r.nextInt(10+1)-5);
  33.         dy = (double) (r.nextInt(10+1)-5);
  34.         life = r.nextInt(15)+1;
  35.         if (mode == 1) {
  36.             tempA = r.nextInt(5);
  37.             redColor = Octarine[tempA][0];
  38.             greenColor = Octarine[tempA][1];
  39.             blueColor = Octarine[tempA][2];
  40.         } else if (mode == 2) {
  41.             redColor = 129;
  42.             greenColor = 250;
  43.             blueColor = 255;
  44.         } else if (mode == 3) {
  45.             redColor = 255;
  46.             greenColor = 215;
  47.             blueColor = 20;
  48.         }
  49.  
  50.     }
  51.    
  52.     public void tick() {
  53.         x += dx;
  54.         y += dy;
  55.         life -= 1;
  56.         //alpha = (float) life / 256;
  57.     }
  58.    
  59.     public void render (Graphics g) {
  60.         Graphics2D g2d = (Graphics2D) g;
  61.         //g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
  62.         particleColor = new Color (redColor, greenColor, blueColor);
  63.         g2d.setPaint(particleColor);
  64.         g2d.fillRect((int) x, (int) y, 5, 5);
  65.         //g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1));
  66.     }
  67.    
  68.     boolean hasDied () {
  69.         boolean tempB = false;
  70.         if (life <= 0) tempB = true;
  71.         return tempB;
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement