Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 42 of 42

Thread: Help with an object based level format

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with an object based level format

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
    at stringtest.main.Main.readHeader(Main.java:70)
    Look at line 70 in your program for the error. The error message says you are trying to index the second element in an array that does not have 2 elements.

    How are you using the split() method? Do you want to split the parts of the String at spaces between the numbers?
    If so, use a single space in quotes: " " as the arg to the split() method.

    For debug, print out the contents of the array created by split(). Use the Arrays class's toString() method to format the array for printing.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Help with an object based level format

    Changing "s1" to a space fixes the out of bounds error, but when I try to run now, I get these errors

    Exception in thread "main" java.lang.NumberFormatException: For input string: "2 1 1"
    at java.lang.NumberFormatException.forInputString(Unk nown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at stringtest.main.Main.<init>(Main.java:29)
    at stringtest.main.Jframe.main(Jframe.java:15)
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with an object based level format

    What is the arg to parseInt() where the error occurs? (line 29)
    The error message says it is the String: "2 1 1"
    A String with non-digits in it can NOT be parsed to an int.

    For debug:
    print out the value of the line after you read it in
    and also print out the contents of the array that the split() method returns.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Help with an object based level format

    The problem must be with the split into the array. I tried using " " as the split like was said, but its not working. The arg for parse int is the array to which the string should be splitting.
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)

  5. #30
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help with an object based level format

    Why aren't you using hasNextInt() for safely getting nextInt()? You are already using the scanner class...

  6. #31
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Help with an object based level format

    Well, changing hasNextLine and nextLine to hasNextInt and nextInt respectively doesn't work and still gives me an error. Removing the lines that set the string and array and setting the ints in the file to integers directly will at least run, but my draw method I'm using to test doesn't show (apparantly the ints don't equal what they're supposed to...) anyway to show what each int has directly on screen?
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)

  7. #32
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help with an object based level format

    weeeeeelllllllll my friend I think you are getting twisted with all of the changes and all of the things you are not quite familiar with. Go at it fresh.

    Here is a text file with a number of lines. Each line has a number of integers separated by some delimiter.
    You set up a scanner which will tool along reading for you:

    While...
    hasNext
    if hasNextInteger
    getAndUseNextInteger
    else throwAwayDelimiterAndTryAgain

  8. #33
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help with an object based level format

    If your project is overwhelming your brain, press pause on it. Jump over to the side and bust out a new class that will just read a text file and print it back to the screen. Only a few lines involved there.

    Modify that to pick out integers and delimiters, and print just the integers. Then you know you have successfully taken the data needed from the file in question.

    Only thing left is to do something with that acquired data besides print it out...

    By time you get that functional you should have absorbed enough of the idea to copy/paste and/or rewrite a cleaner version for your current project

  9. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with an object based level format

    Can you post the code that you are having problems with?
    Also post the full text of the error message and the contents of the file that you are trying to read.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #35
    Member
    Join Date
    Jul 2012
    Posts
    69
    My Mood
    Relaxed
    Thanks
    1
    Thanked 6 Times in 6 Posts

    Default Re: Help with an object based level format

    I like to learn from examples, this is a nice example on how to use split, try to play with just a split function and an integer.parseint. Next add so it will read line by line:
    Java String Split Example | Java Examples - Java Program Sample Source Code

  11. #36
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Help with an object based level format

    Alright, I think its best if we go at this completely fresh. Alright, so I've changed my code up a bit so the file is actually read though the main JPanel. Here is the ENTIRE code for it:

    package scorpioengine.main;
     
    import java.awt.*;
    import java.awt.event.*;
    import java.io.File;
    import java.util.*;
     
    import javax.swing.*;
    //These import lines assure that all needed Java files are imported into the game.
    //The "*"s tell the game to import the entire package of files.
     
    import scorpioengine.main.intro.IntroJpanel;
     
    public class MainJPanel extends JPanel implements ActionListener, Runnable{
     
    	private int OW;
    	private int character=1;
    	private int characters=2;
    	private int cutscene;
    	private int forcedcharacter;
    	private boolean downpressed=false;
    	public boolean running=true;
    	private int keyDown=KeyEvent.VK_DOWN;
    	private int keyLeft=KeyEvent.VK_LEFT;
    	private int keyRight=KeyEvent.VK_RIGHT;
    	private boolean uppressed=false;
    	private int keyUp=KeyEvent.VK_UP;
    	public boolean selectpressed=false;
    	public int keySelect=KeyEvent.VK_Z;
    	private Image A,B,C,D,E,F,G,H,I,K,L,M,N,O,P,Q,R,S,T,U,V,Y,Point,ChompTilesBG,PointerL,PointerR,ChompPortrait,chomppointer,eggplantpointer;
    	public int menuoption=1;
    	public int optionsoption=1;
    	public int quikplay=0;
    	public int gamestate=8;
    	public String GroundTileATop = "GroundTileATop";
     
    	private Map m;
    	private MapPointer mp;
    	private Level l;
    	private Collection<Tile> elements = new ArrayList<Tile>();
    	private Scanner s;
    	private String currenttile;
    	public Thread game;
     
    	public MainJPanel(){
    		//game controls
    		l = new Level();
    		m = new Map();
    		mp = new MapPointer();
     
    		File();
    		game = new Thread(this);
    		game.start();
     
    		addKeyListener(new KeyAdapter(){
     
    			public void keyPressed(KeyEvent e){
    				int keycode=e.getKeyCode();
     
    				if(keycode==keyDown){
    					if(gamestate==1){
    					if (menuoption<4){
    						downpressed=true;
    						menuoption+=1;
    					}
    					else{
    						menuoption=1;
    						downpressed=true;
    					}
    					}
    					if(gamestate==7){
    						if(m.getMap(mp.getTileX(),mp.getTileY()+1).equals("1")){
    						mp.movement(0, 1);
    						}
    					}
    				}
    				if(keycode==keyUp){
    					if(gamestate==1){
    					if (menuoption>1){
    					    uppressed=true;
    						menuoption-=1;
    					}
    					else{
    						menuoption=4;
    						uppressed=true;
    					}
    					}
    					if(gamestate==7){
    						if(m.getMap(mp.getTileX(),mp.getTileY()-1).equals("1")){
    						mp.movement(0, -1);
    						}
    					}
    				}
    				if(keycode==keyLeft){
    					if(gamestate==2){
    						if (character>=1){
    							character-=1;
    						}
    						if (character<1){
    							character=characters;
    						}
    					}
    					if(gamestate==7){
    						if(m.getMap(mp.getTileX()-1,mp.getTileY()).equals("1")){
    						mp.movement(-1, 0);
    						}
    					}
    				}
    	if(keycode==keyRight){
    		if(gamestate==2){
    			if (character<=characters){
    				character+=1;
    			}
    			if (character>characters){
    				character=1;
    			}
    		}
    		if(gamestate==7){
    			if(m.getMap(mp.getTileX()+1,mp.getTileY()).equals("1") || m.getMap(mp.getTileX()+1,mp.getTileY()).equals("2")){
    			mp.movement(1, 0);
    			}
    		}
    				}
    				if(keycode==keySelect && !selectpressed){
    	if(gamestate==1){
    					if(menuoption==1){
    						selectpressed=true;
    					gamestate=2;
    					}
    					if(menuoption==2){
    						selectpressed=true;
    						gamestate=3;
    					}
    					if(menuoption==3){
    						selectpressed=true;
    						gamestate=4;
    					}
    					if(menuoption==4){
    						selectpressed=true;
    						gamestate=5;
    					}
    				}
    	if(gamestate==2 && !selectpressed){
    		selectpressed=true;
    		cutscene=0;
    		gamestate=6;
    				}
    if(gamestate==6 && !selectpressed){
    	gamestate=7;
    	selectpressed=true;
    }
    if(gamestate==7 && !selectpressed){
    	if(m.getMap(mp.getTileX(),mp.getTileY()).equals("1")){   //this controls which tiles act as stage tiles so the game will switch to level mode
    		gamestate=8;
    		selectpressed=true;
    }
    }
     
    		}
    			}
    			public void keyReleased(KeyEvent e){
    	if(e.getKeyCode()==keyDown){
    					downpressed=false;
    				}
    				if(e.getKeyCode()==keyUp){
    					uppressed=false;
    				}
    				if(e.getKeyCode()==keySelect){
    					selectpressed=false;
    				}
    			}
     
    			public void keyTyped(KeyEvent e){
    				int keycode=e.getKeyCode();
     
    			}
     
    			});
     
     
    		setFocusable(true);
     
    		ImageIcon img = new ImageIcon("C://CWWGFX//8x8ALarge.PNG");    //Filepath to the "A" of the main font
    		A=img.getImage();
    		img = new ImageIcon("C://CWWGFX//8x8BLarge.PNG");    //Filepath to the "B" of the main font
    		B=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8CLarge.PNG");    //Filepath to the "C" of the main font
    		C=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8DLarge.PNG");    //Filepath to the "D" of the main font
    		D=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8ELarge.PNG");    //Filepath to the "E" of the main font
    		E=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8FLarge.PNG");    //Filepath to the "F" of the main font
    		F=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8GLarge.PNG");    //Filepath to the "F" of the main font
    		G=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8HLarge.PNG");    //Filepath to the "H" of the main font
    		H=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8ILarge.PNG");    //Filepath to the "I" of the main font
    		I=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8KLarge.PNG");    //Filepath to the "K" of the main font
    		K=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8LLarge.PNG");    //Filepath to the "L" of the main font
    		L=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8MLarge.PNG");    //Filepath to the "M" of the main font
    		M=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8NLarge.PNG");    //Filepath to the "N" of the main font
    		N=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8OLarge.PNG");    //Filepath to the "O" of the main font
    		O=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8PLarge.PNG");    //Filepath to the "P" of the main font
    		P=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8QLarge.PNG");    //Filepath to the "Q" of the main font
    		Q=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8RLarge.PNG");    //Filepath to the "R" of the main font
    		R=img.getImage();
    		img = new ImageIcon("C://CWWGFX//8x8SLarge.PNG");    //Filepath to the "S" of the main font
    		S=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8TLarge.PNG");    //Filepath to the "T" of the main font
    		T=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8ULarge.PNG");    //Filepath to the "U" of the main font
    		U=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8VLarge.PNG");    //Filepath to the "V" of the main font
    		V=img.getImage();
    		img=new ImageIcon("C://CWWGFX//8x8YLarge.PNG");    //Filepath to the "Y" of the main font
    		Y=img.getImage();
    		img=new ImageIcon("C://CWWGFX//OptionTriangleLarge.PNG");    //Filepath to the option triangle of the main menu
    		Point=img.getImage();
    		img=new ImageIcon("C://CWWGFX//ChompTilesBG.PNG");    //Filepath to the Chomp portrait of the character select
    		ChompTilesBG=img.getImage();
    		img=new ImageIcon("C://CWWGFX//Pointertriangleleft.PNG");    //Filepath to the left arrow of the character select
    		PointerL=img.getImage();
    		img=new ImageIcon("C://CWWGFX//Pointertriangleright.PNG");    //Filepath to the right arrow of the character select
    		PointerR=img.getImage();
    		img=new ImageIcon("C://CWWGFX//ChompPortraitLarge.PNG");    //Filepath to the Chomp portrait of the character select
    		ChompPortrait=img.getImage();
    		img = new ImageIcon("C://CWWGFX//ChompPointerLarge.png");
    		chomppointer=img.getImage();
    		img = new ImageIcon("C://CWWGFX//EggplantPointerLarge.png");
    		eggplantpointer=img.getImage();
     
    	}
     
    	public void actionPerformed(ActionEvent e) {
    		repaint();
    	}
     
    	public void paint(Graphics g){ //this is the graphics subroutine
    		super.paint(g);
     
    		Iterator iterator = elements.iterator();
     
    		if(gamestate==1){
    		if(menuoption==1){
    		g.drawImage(Point,14,32,null);
    		}
    		if(menuoption==2){
    			g.drawImage(Point,14,64,null);
    		}
    		if(menuoption==3){
    			g.drawImage(Point,14,96,null);
    		}
    		if(menuoption==4){
    			g.drawImage(Point,14,128,null);
    		}
     
    		g.drawImage(S,32,32,null);
    		g.drawImage(T,48,32,null);
    		g.drawImage(A,64,32,null);
    		g.drawImage(R,80,32,null);
    		g.drawImage(T,96,32,null);
     
    		g.drawImage(L,32,64,null);
    		g.drawImage(O,48,64,null);
    		g.drawImage(A,64,64,null);
    		g.drawImage(D,80,64,null);
     
    		g.drawImage(O,32,96,null);
    		g.drawImage(P,48,96,null);
    		g.drawImage(T,64,96,null);
    		g.drawImage(I,80,96,null);
    		g.drawImage(O,96,96,null);
    		g.drawImage(N,112,96,null);
    		g.drawImage(S,128,96,null);
     
    		g.drawImage(E,32,128,null);
    		g.drawImage(D,48,128,null);
    		g.drawImage(I,64,128,null);
    		g.drawImage(T,80,128,null);
    		g.drawImage(O,96,128,null);
    		g.drawImage(R,112,128,null);
    		}
    		if (gamestate==2){
    			g.drawImage(PointerL,132,224,null);
    			g.drawImage(PointerR,398,224,null);
    			if(character==1){
    			g.drawImage(ChompPortrait,220,150,null);
    			g.drawImage(C,246,280,null);
    			g.drawImage(H,262,280,null);
    			g.drawImage(O,278,280,null);
    			g.drawImage(M,294,280,null);
    			g.drawImage(P,310,280,null);
    			}		
    			if(character==2){
    				g.drawImage(M,220,150,null);
    				g.drawImage(N,246,280,null);
    				g.drawImage(O,262,280,null);
    				g.drawImage(L,278,280,null);
    				g.drawImage(L,294,280,null);
    				g.drawImage(L,310,280,null);
    				}		
    		}
    		if (gamestate==4){
    			g.drawImage(ChompTilesBG,0,0,null);
    			if (optionsoption==1){
    			g.drawImage(Point,14,32,null);
    			}
    			g.drawImage(Q,32,32,null);
    			g.drawImage(U,48,32,null);
    			g.drawImage(I,64,32,null);
    			g.drawImage(K,80,32,null);
    			g.drawImage(P,112,32,null);
    			g.drawImage(L,128,32,null);
    			g.drawImage(A,144,32,null);
    			g.drawImage(Y,160,32,null);
    			if (quikplay==0){
    				g.drawImage(O,192,32,null);
    				g.drawImage(F,208,32,null);
    				g.drawImage(F,224,32,null);
    			}
    			if (quikplay==1){
    				g.drawImage(O,192,32,null);
    				g.drawImage(N,208,32,null);
    			}
    			g.drawImage(K,32,64,null);
    			g.drawImage(E,48,64,null);
    			g.drawImage(Y,64,64,null);
    			g.drawImage(C,96,64,null);
    			g.drawImage(O,112,64,null);
    			g.drawImage(N,128,64,null);
    			g.drawImage(F,144,64,null);
    			g.drawImage(I,160,64,null);
    			g.drawImage(G,176,64,null);
     
    			g.drawImage(L,32,96,null);
    			g.drawImage(I,48,96,null);
    			g.drawImage(V,64,96,null);
    			g.drawImage(E,80,96,null);
    			g.drawImage(S,96,96,null);
     
    			g.drawImage(B,32,128,null);
    			g.drawImage(O,48,128,null);
    			g.drawImage(S,64,128,null);
    			g.drawImage(S,80,128,null);
    			g.drawImage(I,112,128,null);
    			g.drawImage(N,128,128,null);
    			g.drawImage(T,144,128,null);
    			g.drawImage(R,160,128,null);
    			g.drawImage(O,176,128,null);
    		}
    		if (gamestate==6){
    			g.drawImage(L,310,280,null);
    		}
    		if (gamestate==7){
    			for(int y = 0; y < (m.getmapsizey()); y++){
    				for(int x = 0; x < m.getmapsizex(); x++){
    					if(m.getMap(x,y).equals("g")){
    						g.drawImage(m.getGrassEK(),x*32,y*32,null);
    					}
    					if(m.getMap(x,y).equals("t")){
    						g.drawImage(m.getGrassEKTop(),x*32,y*32,null);
    					}
    					if(m.getMap(x,y).equals("w")){
    						g.drawImage(m.getWaterEK(),x*32,y*32,null);
    					}
    				}
    			}
    			for(int y = (m.getmapsizey()+1); y < (m.getmapsizey()*2); y++){
    				for(int x = 0; x < m.getmapsizex(); x++){
    					if(m.getMap(x,y).equals("1")){
    						g.drawImage(m.getPath1(),x*32,(y-14)*32,null);
    					}
    					if(m.getMap(x,y).equals("2")){
    						g.drawImage(m.getPath2(),x*32,(y-14)*32,null);
    					}
    				}
    			}
    			if (character==1){
    			g.drawImage(chomppointer,mp.getTileX()*32,(mp.getTileY()-15)*32,null);
    			}
    			if (character==2){
    				g.drawImage(eggplantpointer,mp.getTileX()*32,(mp.getTileY()-15)*32,null);
    				}
    		}
    		if (gamestate==8){
    			while(iterator.hasNext())
    	            ((Tile) iterator.next()).draw(g);
    		}
    	}
     
    public void File(){
     
    		try{
    		s = new Scanner(new File("C://CWWLEVELS//world1stage1.txt"));
    		while(s.hasNext()){
    			currenttile=s.nextLine();	
    			elements.add(currenttile);  //This is where my problem is.
                            \\I can't seem to get the elements.add to use the string as a command even though my txt file clearly reads "new GroundTileATop (10,40)"
     
    		}
    		s.close();
    		}catch(Exception e){
    			System.out.println("error loading map2");
    		}
     
    	}
    public void fpsSetter() {
    	try{game.sleep(16);
    	} catch(Exception e){
    		e.printStackTrace();
    	}
    }
     
    public void run() {
    	while (running){
    	fpsSetter();
    	repaint();
    	}
    }
    }

    ...and just in case, my txt:

    new GroundTileATop (10,40)
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)

  12. #37
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with an object based level format

    What is the status of the program now?
    Any errors? Please post the full text of any error messages.
    The code execute but gives wrong results. Show results and explain what is wrong with it.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #38
    Member
    Join Date
    Jul 2012
    Posts
    69
    My Mood
    Relaxed
    Thanks
    1
    Thanked 6 Times in 6 Posts

    Default Re: Help with an object based level format

    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.util.Scanner;
     
    public class MapLoader {
    	File file;
     
    	public MapLoader() {
    		/*	 My map */
    		file = new File("map.txt");
    	}
     
    	/*
    	 * Reads the file line by line and passes it to addElements
    	 */
    	public void printMap() {
    		Scanner scanner = null;
    		try {
    			scanner = new Scanner(new FileReader(file));
    			while (scanner.hasNextLine()) {
    				addElements(scanner.nextLine());
    			}
    		} catch (FileNotFoundException e) {
    			e.printStackTrace();
    		} finally {
    			scanner.close();
    		}
    	}
     
    	/*
    	 * This function handles single lines.
    	 */
    	public void addElements(String line) {
    		Scanner scanner = new Scanner(line);
    		int objectId = scanner.nextInt();
    		int x = scanner.nextInt();
    		int y = scanner.nextInt();
    		System.out.println("Object: " + objectId + " At: " + x + "," + y);
    		/* You dont need to close scanner here since it scanns from a String */
    	}
     
    	public static void main(String[] args) {
    		MapLoader map = new MapLoader();
    		map.printMap();
    	}
    }

    Look closely to this code. This code is a very simple implementation of how i would do it.
    1 20 40
    2 40 30
    First is the object id, second and third position. Now you need to change the object id to read the first 2 strings and check if it is a groundTileAtTop or something else, And try adding dynamic arguments.
    Last edited by elamre; July 31st, 2012 at 06:45 PM. Reason: Added some comments

  14. The Following User Says Thank You to elamre For This Useful Post:

    Gravity Games (August 2nd, 2012)

  15. #39
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help with an object based level format

    Take the pseudocode from post#32 and the code from post#38 and give it some thought

  16. #40
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Help with an object based level format

    Thanks elamre! Now I have the game reading from the file! (Sorry for the late reply, my internet was down for a couple of days...) If I have any trouble getting the game to spawn the appropriate objects, I'll let you know.
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)

  17. #41
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Help with an object based level format

    Yep, I'm having trouble again. I can only get the game to draw the last object of the file.
    Last edited by Gravity Games; August 3rd, 2012 at 01:48 AM. Reason: Fixed the first problem and ran into another
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)

  18. #42
    Member
    Join Date
    Jul 2012
    Posts
    69
    My Mood
    Relaxed
    Thanks
    1
    Thanked 6 Times in 6 Posts

    Default Re: Help with an object based level format

    Make a new thread about that, and post the code. I'll try to help you then.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. A level format problem
    By Gravity Games in forum Object Oriented Programming
    Replies: 8
    Last Post: June 4th, 2012, 02:20 PM
  2. [SOLVED] Help Generating a level
    By Montario in forum AWT / Java Swing
    Replies: 22
    Last Post: April 12th, 2012, 07:22 AM
  3. Attempting to get to next level in API
    By meathead in forum The Cafe
    Replies: 8
    Last Post: October 12th, 2011, 11:17 AM
  4. Custom Log level help
    By seanman in forum Java SE APIs
    Replies: 1
    Last Post: September 25th, 2011, 08:55 PM
  5. Reading from ResultSet to Object and from object Object Array
    By anmaston in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 7th, 2011, 06:11 AM