Results 1 to 7 of 7
- 11-13-2011, 03:36 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
Making a 2d game, need help with border around the screen
Ok, so I and a friend is making a small java game. Currently it' sonly a little man moving across whole the screen(up, down, left and right).
I won’t to know what the best way to have the character not moving outside some borders will be? So he couldn't like walk over a house.
Currently I check if the player is outside the screen when i update the position, what will be the easiest way to have like boxes on the screen that he couldn’t go inside?
Thanks
EDIT: Corrected typos.Last edited by tobial; 11-13-2011 at 03:43 PM.
-
Re: Making a 2d game, need help with border around the screen
Hello and welcome to the forum.
Please if you get a chance, edit your original post to correct typos and spelling mistakes. I've found that if posts are easier to read, more folks will read them -- which is what you want, right?
Regarding your problem, this is a problem of your program logic. You'll need to have a non-gui representation of boundaries and obstacles and a non-GUI representation of the little man's position, and use this to determine where the man can and can't go. The specifics will depend on your program's structure.
- 11-13-2011, 03:48 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
Re: Making a 2d game, need help with border around the screen
Ok, fixed typos =).
For the problem; How would the best way to save the obstacles be?
currently for the screenborders i have:
s is my screen, Busthus is the little man,m and Main is my mainclass.Java Code:if(Main.Busthus.getX() + Main.Busthus.getWidth()+1 >= s.getWidth() && m.right){ Main.Busthus.setMoving(false); m.right = false; } if(Main.Busthus.getX()-1 <= 0 && m.left){ Main.Busthus.setMoving(false); m.left = false; } if(Main.Busthus.getY()-1 <= 0 && m.up){ Main.Busthus.setMoving(false); m.up = false; } if(Main.Busthus.getY() + Main.Busthus.getHeight()+1 >= s.getHeight() && m.down){ Main.Busthus.setMoving(false); m.down = false; }Last edited by tobial; 11-13-2011 at 04:00 PM.
-
Re: Making a 2d game, need help with border around the screen
I don't know of any "best way", but when I've done something like this before, I've used a simple text file with letters to represent the grid such as g for grass and h for house, and then have the program read this into an array. Then when moving the man, check his position relative to my data array to see if he's trying to go somewhere there's an obstacle, and if so, not allow it.
- 11-13-2011, 03:58 PM #5
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
Re: Making a 2d game, need help with border around the screen
aha, so putting every pixle of the obstacle in a array? And checking if the mans position is in the array?
-
Re: Making a 2d game, need help with border around the screen
Again, this is just one way. You also could have an ArrayList of Obstacle type, a class that describes where an obstacle is located and that has a method boolean contains(Point p), or something similar, and then simply iterate through this list when moving your man. There are many ways to skin this cat.
- 11-13-2011, 04:02 PM #7
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
Re: Making a 2d game, need help with border around the screen
Ok, i'll try that
I will try to have a class for House. and in the class iwill have a arraylist with points, but it it any way to automaticly fintd the points between 10:10 and let say 30:45?Last edited by tobial; 11-13-2011 at 04:05 PM.
Similar Threads
-
Making a screen to draw on
By sgthale in forum New To JavaReplies: 9Last Post: 09-29-2011, 03:51 AM -
Loading Game Screen.
By Alerhau in forum New To JavaReplies: 3Last Post: 09-04-2011, 03:02 PM -
Chess game selection screen
By gruffyddd in forum AWT / SwingReplies: 1Last Post: 03-19-2011, 03:27 AM -
Making more than one reports to screen with list
By aborgeld in forum Advanced JavaReplies: 2Last Post: 01-16-2011, 11:22 PM -
Game making help
By Mrkantaloupe in forum New To JavaReplies: 2Last Post: 07-13-2010, 10:15 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks