Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Cell.java
- package pw.dvd604.fsg;
- import java.util.Random;
- public class Cell extends Particle {
- public Cell(int x, int y, int r, int g, int b) {
- super(x, y, r, g, b);
- }
- @Override
- protected void doUpdates() {
- int dupeX = this.getX();
- int dupeY = this.getY();
- int dir = new Random().nextInt(4);
- if(dir == 3 || dir == 1){
- if(dir == 1){
- dupeX = dupeX + new Random().nextInt(4);
- } else {
- dupeX = dupeX - new Random().nextInt(4);
- }
- }
- if(dir == 2 || dir == 0){
- if(dir == 0){
- dupeY = dupeY+new Random().nextInt(4);
- } else {
- dupeY = dupeY-new Random().nextInt(4);
- }
- }
- Starter.canvas.listToAdd.add(new Cell(dupeX,dupeY,((int)(this.getX()/8 * new Random().nextInt(3))),((int)(this.getY()/6 * new Random().nextInt(3))),
- (int)(((new Random().nextInt(getX() + 1)+getY())/14) * 2.55)));
- this.setRequiresUpdate(false);
- }
- }
- Particle.java
- package pw.dvd604.fsg;
- import java.awt.Color;
- public abstract class Particle {
- private int red;
- private int green;
- private int blue;
- private int x;
- private int y;
- private boolean doGravity = false;
- private boolean isMoving = true;
- private boolean requiresUpdate = true;
- public Particle(int x, int y, int r, int g, int b) {
- this.setX(x);
- this.setY(y);
- setRed(r);
- setGreen(g);
- setBlue(b);
- }
- public Particle(int x, int y, int r, int g, int b, boolean grav) {
- this.setX(x);
- this.setY(y);
- setRed(r);
- setGreen(g);
- setBlue(b);
- setDoGravity(grav);
- }
- protected void updatePart() {
- if (requiresUpdate) {
- if (doGravity) {
- if (this.isMoving) {
- try{
- if ((Starter.canvas.canvas.getRGB(this.x, this.y + 2) == Color.black
- .getRGB())) {
- this.y = this.y + 2;
- } else {
- if (Starter.canvas.canvas.getRGB(this.x, this.y + 2) == Color.gray
- .getRGB()) {
- this.isMoving = false;
- }
- }} catch(Exception e){}
- }
- }
- if(this.x>=799 || this.x<=1){
- Starter.partList.remove(this);
- }
- if(this.y>=599 || this.y<=1){
- Starter.partList.remove(this);
- }
- doUpdates();
- }
- }
- protected abstract void doUpdates();
- public int getRed() {
- return red;
- }
- public void setRed(int red) {
- this.red = red;
- }
- public int getGreen() {
- return green;
- }
- public void setGreen(int green) {
- this.green = green;
- }
- public int getBlue() {
- return blue;
- }
- public void setBlue(int blue) {
- this.blue = blue;
- }
- public int getX() {
- return x;
- }
- public void setX(int x) {
- this.x = x;
- }
- public int getY() {
- return y;
- }
- public void setY(int y) {
- this.y = y;
- }
- public boolean isDoGravity() {
- return doGravity;
- }
- public void setDoGravity(boolean doGravity) {
- this.doGravity = doGravity;
- }
- public boolean isMoving() {
- return isMoving;
- }
- public void setMoving(boolean isMoving) {
- this.isMoving = isMoving;
- }
- public boolean requiresUpdate() {
- return requiresUpdate;
- }
- public void setRequiresUpdate(boolean requiresUpdate) {
- this.requiresUpdate = requiresUpdate;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement