Tile Based Map Help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Tile Based Map Help

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Posts
    8

    Tile Based Map Help

    I need help with whats wrong with this code. I pretty much quit java a long time ago because i could never get tile based maps. Today i was reading up on programming microncontrollers in c and came up with this after not coding in java for a long time and c is pretty similar to java. The array isnt quite a map but i can implement it once i get threw this part. The array used to be an array of letters but changed it to ints just to see if that was the problem. It compiles fine for me it just doesn't run.


    Code:
    // what it should do or similar
    //
    //56 <<-- i know exciting but its all i need then i could do better i 
    //78         just need a push
    
    import java.awt.*;
    import java.applet.*;
    
    public class maptest extends Applet
    {
    	int e;
    	int f;
    	int x;
    	int y;
    	int z;
    	
    	int aMap[][] = new int[2][2]; //make the array
    
    
    	public void init()
    	{
    	aMap[1][1]=5;
    	aMap[1][2]=6;  //fill it with stuff
    	aMap[2][1]=7;
    	aMap[2][2]=8;
    	}
    
    	
    	
    	public void paint(Graphics g)
    	{
    	x=1;  
    	y=10;  
    	z=10;
    
    	
    		while(x<=4) //counts to 4 then  ends
    		{
    			while(e<=2) //counts to 2 then ends and 
    			{
    			g.drawString(" "+aMap[e][f],y,z); //writes the ints
                            e=e+1;
    			y=y+10;
    			}
    			while(f<=2) same ordeal
    			{
    			g.drawString(" " +aMap[e][f],y,z);
                            f=f+1;
    			z=z+10;
    			}
    		}
    	}
    }

  2. #2
    Join Date
    Jan 2009
    Posts
    8
    fixed it and now its better than before but there has to be a better way and i dont know what to do about the int f.

    Code:
    import java.awt.*;
    import java.applet.*;
    
    public class maptest2 extends Applet
    {
    	int e=1;
    	int f=1;
    	int x;
    	int y;
    	int z;
    	int arraysize = 4;
    	int aMap[][] = new int[8][8];
    
    	public void init()
    	{
    	aMap[1][1]=1;
    	aMap[1][2]=2;
    	aMap[1][3]=3;
    	aMap[1][4]=4;
    	aMap[2][1]=5;
    	aMap[2][2]=6;
    	aMap[2][3]=7;
    	aMap[2][4]=8;
    	aMap[3][1]=9;
    	aMap[3][2]=1;
    	aMap[3][3]=2;
    	aMap[3][4]=3;
    	aMap[4][1]=4;
    	aMap[4][2]=5;
    	aMap[4][3]=6;
    	aMap[4][4]=7;
    	}
    
    	public void paint(Graphics g)
    	{
    	int e1=1;
    	int e2=1;
    	x=1;
    	y=100;
    	z=100;
    		while(x<=16)
    		{		
    			while(e2<5)
    			{
    			e=e+1;
    			g.drawString(" "+aMap[e][f],z,y);
    			z=z+10;
    			e2=e2+1;
    			x=x+1;
    			}
    			e1=1;
    			e=1;
    			z=z-arraysize*10;
    			y=y+10;
    			while(e1<5)
    			{
    			f=2;
    			e=e+1;
    			g.drawString(" "+aMap[e][f],z,y);
    			e1=e1+1;
    			z=z+10;
    			x=x+1;
    			}
    		}
    	}
    }

Similar Threads

  1. Tile Based Maps
    By Hobbles in forum Java
    Replies: 7
    Last Post: 01-13-2009, 06:25 PM
  2. Swapping a map element (a DOM question)
    By alsoares in forum AJAX
    Replies: 2
    Last Post: 12-20-2007, 08:03 PM
  3. map and memory leak
    By WXY595 in forum C++
    Replies: 3
    Last Post: 05-16-2007, 04:06 PM
  4. Replies: 3
    Last Post: 01-28-2006, 08:25 AM
  5. map areas not passing Form object to java script
    By mark hembree in forum ASP.NET
    Replies: 1
    Last Post: 01-11-2001, 11:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center