This site requires JavaScript, please enable it in your browser!
Greenfoot back
fittirc
fittirc wrote ...

2018/11/30

Maze w/ clipped out overlay

fittirc fittirc

2018/11/30

#
Hi guys, I'm creating a maze but am having issues with the walls. What I've done is set a world background with an image of a maze. Then I made a copy of that maze image and clipped out (using photo editing software) the path so that I could make an actor out of that clipped out image. I created an actor (MazeWalls1) for the clipped out image and used addObject to overlay it on top of the world background. Prior to using collision code, the player will walk underneath the wall actor. However, when I use the getOneIntersectingObject code, it is acting as if the player actor is touching the MazeWalls1 actor no matter where the player moves. Instead, will I need to crop out a piece of the wall and use addObject to place the walls (like 50 placements) in the world class? Here is the code for the World class:
private void prepare(){
        Player player = new Player(mazeSong);
        addObject(player, 200, 300);     
        Dragon dragon = new Dragon();
        addObject(dragon, 500, 200);
        MazeWalls1 walls1 = new MazeWalls1();
        addObject(walls1, 358, 303);
}
Here is the code to check collision:
public void collision(){
      MazeWalls1 walls = (MazeWalls1) getOneIntersectingObject(MazeWalls1.class);  
      if (walls != null)      
      {      
          getWorld().removeObject(this);  
      }
}
danpost danpost

2018/11/30

#
Transparency in an image is still part of the image and (supplied) collision methods only checks for intersecting images (regardless of transparency). Provided your maze walls image is transparent at the path ways, or if all path ways are of the same flat color, you can still make use of that image. Draw it onto the world background image and have the player check the background color to determine if on a path or not.
fittirc fittirc

2018/12/4

#
Hey dan, thanks for replying. Unfortunaly, the path isn’t a solid color. I’m using this maze image: https://www.deviantart.com/neyjour/art/Razorcrush-Maze-298486546 If the pathways are transparent with the maze wall image, is your suggestion still viable despite the lack of one solid color on the paths?
danpost danpost

2018/12/4

#
fittirc wrote...
Hey dan, thanks for replying. Unfortunaly, the path isn’t a solid color. I’m using this maze image: https://www.deviantart.com/neyjour/art/Razorcrush-Maze-298486546 If the pathways are transparent with the maze wall image, is your suggestion still viable despite the lack of one solid color on the paths?
No. My suggestion is to use a 2-D array to map out the maze. An array of int values is sufficient. use -1 for walls, 0 for pathways and different positive values to mark out any special location (for example, where different actors are to be spawned at; the value can be made 0 after spawning the actors).
You need to login to post a reply.