Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8674189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:38:51+00:00 2026-06-12T19:38:51+00:00

I am trying to create a basic falling sand game in java, I have

  • 0

I am trying to create a basic falling sand game in java, I have each particle store it’s X and Y in a Point array. Each Point array is specific to it’s element, so sand and water are two different arrays, what i would like to know is how do i check my sand array against itself to see if two particles have the same position, and if so, move them?

This is my Sand Class

    package testingzone;

import java.awt.Point;
import java.util.Stack;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

public class Sand {

    public Graphics g = new Graphics();
    public float sizeX = 1;
    public float sizeY = 1;
    public int speed = 1;
    public String BaseState = "fall";
    public String state = "fall";
    public String Name = "Sand";
    public Point[] point = new Point[(600 * 800)];
    public Point[] pointcheck = new Point[(600 * 800)];
    public int num = 0;
    public boolean check = false;

    public org.newdawn.slick.Color c = org.newdawn.slick.Color.yellow;

    public void drawParticle(float x, float y) throws SlickException{
        g.setColor(c);
        g.drawRect(x, y, sizeX, sizeY);
    }

    public void createParticle() throws SlickException{
        if(state == "fall"){
            fall(point);
        } else {

        }
        if(state == "stay"){
            stay(point);
        } else {

        }
    }

    public void fall(Point[] point) throws SlickException{
        for (int index = 0; index < point.length; index++) {
            Point p = point[index];
            if (p != null) {
                if (p.y >= 598) {
                    drawParticle(point[index].x, 598);
                } else {
                    drawParticle(p.x, p.y);
                    p.y += speed;
                }
              }
            }
          }

    public void stay(Point[] point) throws SlickException{
        for (int index = 0; index < point.length; index++) {
            Point p = point[index];
            if (p != null) {
                drawParticle(p.x, p.y);
                }
              }
            }

}

And this is a simplified version of my main class

    package testingzone;
import java.awt.Point;
import org.lwjgl.input.Mouse;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class Control extends BasicGameState {
    public static final int ID = 2;

    public Sand s = new Sand();

    public Run run = new Run();
    int maxnum = (800 * 600);
    int pressedX;
    int pressedY;
    int num = 0;
    String Build = "1.4";
    String Element = "sand";
    String name;
    public boolean endgame = false;


    public void init(GameContainer container, StateBasedGame game) throws SlickException{
    }

    public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
        if(Element == "sand"){
            s.createParticle();
            name = s.Name;
        }
        g.setColor(Color.yellow);
        g.drawRect(240, 10, 15, 15);
        g.fillRect(240, 10, 15, 15);
        if(Element == "sand"){
            // g.setColor(Color.white);
            // g.drawRect(235, 5, 25, 25);
            g.drawLine(235, 35, 260, 35);
        }
        g.setColor(Color.white);
        g.drawString("Open Sand", 700, 0);
        g.drawString("Build: " + Build, 700, 15);
        g.drawString("Total Pixels: " + num, 10, 25);
        g.drawString("Current Type: " + name, 10, 40);
        g.drawString("Mouse X: " + Mouse.getX(), 10, 55);
        g.drawString("Mouse Y: " + Mouse.getY(), 10, 70);
        }


    public void update(GameContainer container, StateBasedGame game, int delta) {
        if(endgame == true){
            container.exit();
        }
    }

    public void mouseDragged(int oldx, int oldy, int newx, int newy) {
        pressedX = newx;
        pressedY = newy;
        num = num + 1;
        if(Element == "sand"){
            s.num = s.num + 1;
            s.point[s.num] = new Point(pressedX, pressedY);
            s.pointcheck[s.num] = new Point(pressedX, pressedY);
        }
    }

    public void keyPressed(int key, char c) {
        if (key == Input.KEY_ESCAPE) {
            endgame = true;
        }
        if (key == Input.KEY_1) {
            Element = "sand";
    }

    public int getID() {
        return ID;
    }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:38:52+00:00Added an answer on June 12, 2026 at 7:38 pm

    A suggestion:
    Particle class has a Point (x-y coordinates).
    Implement equals method of the particle

    boolean equals(Object o){
       if(! o instanceof Particle) return false;
       if(o.getPoint().equals(this.getPoint())) return true;
    

    Now implement equals for Point class something like:

        boolean equals(Object o){
           if(! o instanceof Point) return false;
           if(o.getXCoordinate.equals(this.getXCoordinate()) 
    && o.getYCoordinate.equals(this.getYCoordinate())) return true;
    

    You can check indexes if you want instead of having getXCoordinate and getYCoordinate methods on the Point class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a basic Pacman game in C++ (I'll use Java syntax
I am trying to create a very basic sprite image. First off i have
I'm trying to create an element in an XML where the basic content is
I'm trying to create a basic for loop which creates an array but am
I am trying to create a basic functionality in AS3. I have a class
I'm trying to create a basic video file using OpenCV (in Python). I have
I'm trying to create a basic system that will allow only specific users to
I am trying to create a basic search function. I have a text field
I am trying to create a basic WPF application that can store an encrypted
I'm trying to create a basic navigation and I'd like to have a horizontal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.