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 9191333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:39:31+00:00 2026-06-17T20:39:31+00:00

Im currently am working on a game in Java that spawns blocks on the

  • 0

Im currently am working on a game in Java that spawns blocks on the top of the screen and they fall down (you have to dodge them). Currently I have the game spawning blocks on the top of the screen from an array but I do not know how to make their y position go down by (int).

Basically I just need help making a public void that checks an object array and with every instance of a object it finds it drops the y position of it by 12.

Selected snippits from code:

static Object[][] food = new Object[7][700];

public void draw() {
    try {
        Graphics g = bufferStrategy.getDrawGraphics();
        g.clearRect(0, 0, this.getSize().width, this.getSize().height);

        // Draw to back buffer
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, this.getSize().width, this.getSize().height);
        g.setColor(Color.BLUE);
        g.fillRect(Player.getX(), Player.getY(), Player.WIDTH, Player.HEIGHT);
        g.setColor(Color.GRAY);

        for(int x = 0; x < food.length; x++) {
            for(int y = 0; y < food[x].length; y ++) {
                Object o = food[x][y];
                if(o instanceof Hamburger) {
                    new Hamburger(x * 100, y, g);           
                }
                else if(o instanceof Salad) {
                    new Salad(x * 100, y, g);
                }
            }
        }

        GUI.draw(g);

    } catch(Exception e) {
        e.printStackTrace();
    } finally {
        bufferGraphics.dispose();
    }
}

public void dropBlocks() {

}

public void addBlock() {
    if(new Random().nextInt(2) == 1) {
        food[new Random().nextInt(7)][0] = new Hamburger(0, 0);
    } else food[new Random().nextInt(7)][0] = new Salad(0, 0);
}

public  void drawBackbufferToScreen() {
    bufferStrategy.show();

    Toolkit.getDefaultToolkit().sync();
}

public void run() {
    int i = 0;
    while(running) {
        i++;
        draw();
        Player.update();
        drawBackbufferToScreen();

        if(i == 50) {
            addBlock();
            i = 0;
        }

        dropBlocks();   

        Thread.currentThread();
        try {
            Thread.sleep(10);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}

Food.java (What Hamburger and Salad extend)

public class Food {
public static int x;
public static int y;
public static int HEIGHT;
public static int WIDTH;
public int type;

private static Image blockImage;

// Default constructor
public Food() {
    Food.x = 0;
    Food.y = 0;
    Food.HEIGHT = 80;
    Food.WIDTH = 80;
}

public Food(int x, int y) {
    Food.x = x;
    Food.y = y;
    Food.HEIGHT = 80;
    Food.WIDTH = 80;
}

// Getters and setters
  • 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-17T20:39:33+00:00Added an answer on June 17, 2026 at 8:39 pm

    I would do something like this:

    Object[][] board = new Object[7][700];  //Game board.  
    //you can also switch the width and height
    //Initialization
    
    for (int x = 699; x >= 0; x--) {
        for (int y = 0; y < 7; y++) {
            if (x == 699) {
                board[y][x] = BLANK; //set spot to open if it is the bottom row
                continue;
            }
            board[y][x+1] = board[y][x]; //move row down
        }
    }
    //Generate new Objects if needed for the top row of the board.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a multiplayer card game developed and working in Java and it
I'm currently working on a java game which opens up with a start screen
I am currently working on a 2d Top-down RPG written in Java 1.6 with
I'm currently working on a game in Java and I want to calculate the
I am currently working on designing my first FPS game using JOGL. (Java bindings
Im currently working on a game that uses multi touch to apply zoom to
I'm currently working on a game and I wish to have a main menu
I am currently working on a game in c# that I want to put
i am currently working on a facebook game and i have a problem concerning
I am currently working on a space invaders style game but I have run

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.