Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By gimbal2

Thread: Creating a game Map

  1. #1
    ShadowWalker is offline Senior Member
    Join Date
    Mar 2013
    Location
    Greece
    Posts
    113
    Rep Power
    0

    Default Creating a game Map

    I Hope this is the correct Section.. :\
    i am working on a mini mario project.. and i have create the mario and all of sprite sheet frames , the (moving) background but i have one question about the map..
    i search on the web and i found a very good way to represent items on the Screen using a text file using characters which will represent specific BufferedImage on the screen in a spesific place.. but all this will be only in background so i should use an background image instead of painting all this ? i have an arrayList with objects which i draw on screen and i draw every piece on background.. so should i avoid that by creating just an image? or to keep it like this?
    now one more question.. i have a Class GameMap which i have all the background staff of the game which i draw on the Screen again and again.. but all this has no effect with user Player(mario) so i should create an new class with object which has effect like boxes enemies etc? or put all this in GameMap class and then find the collision with the cords of the drawing images?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default Re: Creating a game Map

    What happened when you tried the approaches you've suggested?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: Creating a game Map

    You can't be narrated through the programming of your game dude. You need to try stuff out and see what works for yourself. Right now you don't have anything that you need help with, you just need to buckle down and go try stuff. Don't be afraid to make mistakes.

    As for the background question: either way works. And I have used either way; the reason for choosing one way or the other was very simple: whatever was more convenient.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    ShadowWalker is offline Senior Member
    Join Date
    Mar 2013
    Location
    Greece
    Posts
    113
    Rep Power
    0

    Default Re: Creating a game Map

    i aggree with you man but i am afraid of making a big map and then to have problem with my game memory... for example if i make a huge game map,is it possible to have flickering effects in my game? i am not using a new Thread in my draw method.. so is this possible? i want to avoid changing my entire project if this problem appear later .. that's why i ask if it's possible to face this kind of problem..

    to draw items on the screen i just take from file Strings and then i call this paint method inside my JPanel Class

    Java Code:
    public void paint(Graphics g){
    		for(int i = 0; i < mapHeight ; i++){
    			for(int j = 0 ; j < mapWidth ; j ++){
    				String kkk = map[i][j];
    				if(kkk.equals("-")){
    					g.drawImage(ground,x + j * 20, y + i * 20,30,30,null);
    				}
    				if(kkk.equals("1")){
    					g.drawImage(doubleMountains,x + j * 20, y + i * 20 - 200 + 32,300,200,null);
    				}
    				if(kkk.equals("2")){
    					g.drawImage(clouds,x + j * 20, y + i * 20 - 50 + 32,200,100,null);
    				}
    				if(kkk.equals("3")){
    					g.drawImage(gras, x+j*20, y+i*20 - 50 +32,50,50 ,null);
    				}if(kkk.equals("4")){
    					g.drawImage(box.get(boxCounter), x+j*20, y+i*20 ,40,40 ,null);
    				}
    				if(kkk.equals("5")){
    					g.drawImage(powerUpBox.get(powerUpBoxCounter), x+j*20, y+i*20 ,40,40 ,null);
    				}
    			}
    		}
    		powerUpBoxCounter ++ ;
    		if(powerUpBoxCounter >= powerUpBox.size()){
    			powerUpBoxCounter = 0;
    		}
    	}
    for a small game map it's just fine ..

    but you have right.. it's time for experimentations :P
    Last edited by ShadowWalker; 07-31-2013 at 04:58 PM.

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: Creating a game Map

    Its not as simple as that. The game map can be huge, you still draw only a subsection of it - you never want to draw more than what fits on the screen. So when you write the proper drawing code to only draw that part of the map which is visible, the size of the game map should never impact the drawing performance. Your memory worry is a valid one, but remember that nowadays computers have plenty of that. Assume that one pixel of your game map will take up 4 bytes, try to make an educated guess how much memory you will need on average to store a game map. It won't be as bad as you think.

    Note that whatever flickering you get is caused by you using Java2D in stead of a proper game graphics API. Java2D is optimized for being visually correct, not for performance.

    i want to avoid changing my entire project if this problem appear later
    I have bad news for you: it is likely going to happen anyway. Not entirely, but a large chunk of it probably yes. You shouldn't be afraid of that, you have to be brave enough to take what you have and radically change it to be better.

    that's why i ask if it's possible to face this kind of problem..
    Experimentation is the answer there. See for yourself what happens, and in the process of doing that understand the how and the why.
    ShadowWalker likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Creating a 2D game
    By adjit in forum New To Java
    Replies: 1
    Last Post: 03-15-2012, 05:46 AM
  2. Creating a Pac-Man Game
    By alex7841 in forum Java Applets
    Replies: 8
    Last Post: 03-01-2012, 09:21 PM
  3. Creating a game with java.
    By GameCoderKata in forum New To Java
    Replies: 1
    Last Post: 12-19-2011, 02:17 AM
  4. need help creating a shell game
    By ss1 in forum New To Java
    Replies: 0
    Last Post: 09-20-2011, 01:11 AM
  5. need help creating my Tic Tac Toe game!
    By bobmasta5 in forum New To Java
    Replies: 6
    Last Post: 12-09-2008, 06:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •