We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Map Project Help Please
Page Index Toggle Pages: 1
Map Project Help Please (Read 196 times)
Map Project Help Please
Feb 29th, 2008, 5:40pm
 
I'm trying to creat a map of custom tiles. The tile order is stored in a text file, and the tile images are jpg files in the data folder. If you need me to post those please just say so. I can't figure out how to display more than one kind of tile at a time, and I would appreciate any help.

color grassColor = color(0, 200, 0);
int tileSize = 20;
Tile grass = new Tile(tileSize, tileSize);
Map map2 = new Map(tileSize, tileSize, 10, 10, "map2");
PImage grassImage;
PImage rockImage;


void setup(){
size(800, 500);
grassImage = loadImage("grass.jpg");
rockImage = loadImage("rock.jpg");
map2.update();
}
void draw(){
 grass.create(0, 0);
 map2.create();
 //PFont fontA = loadFont("CourierNew36.vlw");
 //textFont(fontA, 36);
 //text(map1.returnMapTilesLength(), width/2, height/2);
 
}

class Tile{
String name;
float h;
float w;

 Tile(float dh, float dw){
   h = dh;
   w = dw;
 }
void create(float dx, float dy){
 if(name == "grass"){
 image(grassImage, dx, dy, w, h);
 }
 else if(name == "rock"){
 image(rockImage, dx, dy, w, h);
 }
 }
void identify(String dname){
 name = dname;
 }
void displayType(float dx, float dy){
 PFont fontA = loadFont("CourierNew36.vlw");
 textFont(fontA, 36);
 text(name, dx, dy);
}
}

class Map{
String name;
float tileW;
float tileH;
int mapW;
int mapH;
float w = tileW * mapW;
float h = tileH * mapH;
Tile[] MapTiles = new Tile[0];
String[] MapLoad;
String[] MapSave = new String[MapTiles.length];
   Map(float dtileW, float dtileH, int dmapW, int dmapH, String dname){
      tileW = dtileW;
      tileH = dtileH;
      mapH = dmapH;
      mapW = dmapW;
      name = dname;
   }
   
   void update(){
     MapTiles = (Tile[])expand(MapTiles, mapW * mapH);
     instantiate();
        MapLoad = loadStrings(name + ".txt");
      for(int i = 0; i < MapLoad.length; i++){
            if(MapLoad[i].equals("grass")){
              MapTiles[i].identify("grass");
             }
            else if(MapLoad[i].equals("rock")){
              MapTiles[i].identify("rock");
             }
       
      }
   }
       void create(){
      for(int i = 0; i < MapTiles.length; i++){
      for(int j = 0; j < mapW; j++){
      for(int k = 0; k < mapH; k++){
     
        MapTiles[i].create(j*tileSize, tileSize*k);
     }
   }  
 }
}
       void instantiate(){
         for(int i = 0; i < MapTiles.length; i++){
         MapTiles[i] = new Tile(tileSize, tileSize);
         }
   }
   int returnMapTilesLength(){
     return MapTiles.length;
   }
   int returnMapLoadLength(){
     return MapLoad.length;
   }
   int returnmapH(){
     return mapH;
   }    
   int returnmapW(){
     return mapW;
   }
}
Page Index Toggle Pages: 1