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

Report as inappropriate.

morningsun93
morningsun93 presents ...

2012/3/21

mze

need: how use traverse, walls to block ways, random mazes.

2799 views / 11 in the last 7 days

Tags: game with-source korea hehe haha hoho

open in greenfoot
Your browser does not support the canvas tag.
danpostdanpost

2012/3/21

Is this a school project? I have seen a couple of these that look strikingly similar.
morningsun93morningsun93

2012/3/22

Yes, it is. And i have seen you giving strikingly helpful advice. Could you also give me some advice please? Okay, I have loads of questions. First, how can I make the traverse method work? it's suppose to tell you that the maze is done when the Player reaches the end. I just have no idea about this. Second, how can I make the trees work as obstacles that would prevent the Player from walking over it? Lastly, the hardest question, how can I make random mazes to appear every time? thank you
matt.milanmatt.milan

2012/3/22

oh boy, collision is a fun topic. i'm still uncertain of the best approach to collision, myself. from what i've heard, you want to take your "if downpressed, move down" method and add another check to it "if downpressed and objectAtTargetLocation != obstacle" does this help? if not i can go into detail
matt.milanmatt.milan

2012/3/22

also please make ur world smaller :)
danpostdanpost

2012/3/22

matt.milan is right! You need to do something about the size of your world -- get it to match your maze somehow. maybe a cell size of about 40; but all your references and values to locations in the world would have to be adjusted to match.
matt.milanmatt.milan

2012/3/23

i think the way it works is getObjectsAtOffset or getOneObjectAtOffset, not sure which one then the parameters would be (x,y,Class) xy have to be different depending on if you're pushing up down left or right. class would have to be Obstacle.class or Tree.class or whatever you're using tip: if you want multiple types of obstacles, make them (ie tree, rock, river) subclasses of the superclass obstacle. maybe. i dunno
danpostdanpost

2012/3/23

The traverse method appears to solve the maze by itself. In it you will find the coordinates that it looks for, and its parameters are the coordinates that you are starting from. You probably want to call that method AFTER the player solves it, and add an object to the cells that are in the path to show the true path. I created a maze program that (after solved by player) shows each step of the solving process by colors -- yellow for working on that cell, red for cell not in path, and green for true path. It uses a recursive method, but not the traverse you would use. I slowed down the speed, so you could see each step clearly, and it started at the finish, and worked back to the starting point. I will be working on random maze creation soon.
morningsun93morningsun93

2012/3/24

wow thnk you you guys are awesome! I'll work on with your advices but how can I adjust the world size with cells instead of precise numbers??
morningsun93morningsun93

2012/3/24

wow thnk you you guys are awesome! I'll work on with your advices but how can I adjust the world size with cells instead of precise numbers??
danpostdanpost

2012/3/24

You world is already sized with cells; however, with a cell-size of 1 pixel by 1 pixel. The 'super(int, int, int)' command in the constructor of your world determined this. This command is basically: super(int 'cells across', int 'cells down', int 'height and width of one cell') With the 'height and width of one cell' being set to one (1), each pixel becomes a cell in itself. You will still use precise numbers, just modified to suit your needs. The width of your world will be 'cells across' * 'width of one cell', and the height of your world will be 'cells down' * 'height of one cell'. Objects will only be placed at the center of any cell, and moves and offsets are based on cells (not pixels). Ex: super (30, 20, 20) = 600 cells: 30 across by 20 down, each 20 x 20 pixels in size. addObject(new Obj(), 30, 20) would place the object passed the edge of the world, even though the world is 600 by 400 pixels in size; move(1) would move the object 20 pixels in the direction it is facing (up, down, left, or right), or one cell in that direction. Hope this helps.

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.