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

  • Home
  • SEARCH
  • 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 9201475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:01:02+00:00 2026-06-17T23:01:02+00:00

I am wanting to make a game that has each level loaded from an

  • 0

I am wanting to make a game that has each level loaded from an image.
I want to draw up the whole level in Photoshop, and then set it as the background and allow the player to walk over it.
I want another invisible image to go over top which will be black in all places that I want to collide with.

The reason I don’t want to use tiles, which are much easier with rectangle collision and such, is because there will be complex corners and not everything will be rectangle.

Is this a good idea, and is it possible to do easily?
Would this be a big CPU hog or is there a better way to do this?

Level image

Level image

Obstacles shown in red

Obstacle in Red

  • 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-17T23:01:04+00:00Added an answer on June 17, 2026 at 11:01 pm

    ..there will be complex corners and not everything will be rectangle.

    This could be achieved by drawing and dealing with Shape and Area instances. E.G.

    • Yellow is a little animated ‘player’.
    • The bounds of the image represent walls that contain the path of the player (it bounces off them).
    • Obstacles are painted green when not in collision, red otherwise.

    ShapeCollision

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import javax.swing.*;
    
    class ShapeCollision {
    
        private BufferedImage img;
        private Area[] obstacles = new Area[4];
        private Area walls;
    
        int x; 
        int y;
        int xDelta = 3;
        int yDelta = 2;
    
        /** A method to determine if two instances of Area intersect */
        public boolean doAreasCollide(Area area1, Area area2) {
            boolean collide = false;
    
            Area collide1 = new Area(area1);
            collide1.subtract(area2);
            if (!collide1.equals(area1)) {
                collide = true;
            }
    
            Area collide2 = new Area(area2);
            collide2.subtract(area1);
            if (!collide2.equals(area2)) {
                collide = true;
            }
    
            return collide;
        }
    
        ShapeCollision() {
            int w = 400;
            int h = 200;
            img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            final JLabel imageLabel = new JLabel(new ImageIcon(img));
            x = w/2;
            y = h/2;
    
            //circle 
            obstacles[0] = new Area(new Ellipse2D.Double(40, 40, 30, 30));
    
            int[] xTriangle = {330,360,345};
            int[] yTriangle = {60,60,40};
            //triangle 
            obstacles[1] = new Area(new Polygon(xTriangle, yTriangle, 3));
    
            int[] xDiamond = {60,80,60,40};
            int[] yDiamond = {120,140,160,140};
            //diamond 
            obstacles[2] = new Area(new Polygon(xDiamond, yDiamond, 4));
    
            int[] xOther = {360,340,360,340};
            int[] yOther = {130,110,170,150};
            // other 
            obstacles[3] = new Area(new Polygon(xOther, yOther, 4));
    
            walls = new Area(new Rectangle(0,0,w,h));
    
            ActionListener animate = new ActionListener() {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                    animate();
                    imageLabel.repaint();
                }
            };
            Timer timer = new Timer(50, animate);
    
            timer.start();
            JOptionPane.showMessageDialog(null, imageLabel);
            timer.stop();
        }
    
        public void animate() {
            Graphics2D g = img.createGraphics();
            g.setRenderingHint(
                    RenderingHints.KEY_ANTIALIASING, 
                    RenderingHints.VALUE_ANTIALIAS_ON);
    
            g.setColor(Color.BLUE);
            g.fillRect(0, 0, img.getWidth(), img.getHeight());
            x+=xDelta;
            y+=yDelta;
            int s = 15;
            Area player = new Area(new Ellipse2D.Double(x, y, s, s));
    
            // Acid test of edge collision;
            if (doAreasCollide(player,walls)) {
                if ( x+s>img.getWidth() || x<0 ) {
                    xDelta *= -1;
                } 
                if(y+s>img.getHeight() || y<0 ) {
                    yDelta *= -1;
                }
            }
            g.setColor(Color.ORANGE);
            for (Area obstacle : obstacles) {
                if (doAreasCollide(obstacle, player)) {
                    g.setColor(Color.RED);
                } else {
                    g.setColor(Color.GREEN);
                }
                g.fill(obstacle);
            }
    
            g.setColor(Color.YELLOW);
            g.fill(player);
    
    
            g.dispose();
        }
    
        public static void main(String[] args) {
            Runnable r = new Runnable() {
    
                @Override
                public void run() {
                    new ShapeCollision();
                }
            };
            // Swing GUIs should be created and updated on the EDT
            // http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html
            SwingUtilities.invokeLater(r);
        }
    }
    

    Edit

    make it detect all the red color and set that as the collision bounds

    At start-up, use the source seen in the Smoothing a jagged path question to get an outline of the red pixels (see the getOutline(Color target, BufferedImage bi) method). Store that Area as the single obstacle on start-up.

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

Sidebar

Related Questions

I'm wanting to make a component that inherits from rotate canvas using a storyboard.
Wanting to make sure I'm using classes properly. The main script accepts this from
I'm wanting to write a management game that utilizes Core data heavily. The game
I've been wanting to make the switch from PHP. Anyone care to highlight the
I am wanting to make a colorful cartoon style custom dialog for a game.
i want to make a game with 2 players .i will use udp server
I am wanting to make a TCP server that listens on port 443 so
Found some nice Open Source code of a snake game, but wanting to make
I am creating a website that stores recipes. I am wanting to make a
I am wanting to make a progress-bar-type-thing which goes from green-orange-red as it moves

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.