Jhurd23
YaBB Newbies
Offline
Posts: 8
Fill() Mystery
Feb 26th , 2008, 4:52pm
I'm trying to load a text file as an array of Strings, then use those Strings to identify the indeividual tiles in MapTiles. I've tried changing the fill() according to the identity of the tile, but fill() won't accept variables! Please help color grassColor = color(0, 200, 0); int tileSize = 20; Tile grass = new Tile(tileSize, tileSize); Map map1 = new Map(tileSize, tileSize, 20, 5, "map1"); void setup(){ size(800, 500); } void draw(){ background(255); grass.create(0, 200, 0, 0, 0); map1.update(); map1.create(); //fill(255); //PFont fontA = loadFont("CourierNew36.vlw"); //textFont(fontA, 36); //text(map1.MapTiles[0].Green, width/2, height/2); } class Tile{ String name; float h; float w; float Red; float Blue; float Green; Tile(float dh, float dw){ h = dh; w = dw; } void create(float Red, float Green, float Blue, float dx, float dy){ fill(Red, Green, Blue); rect(dx, dy, w, h); } void identify(String dname, int dRed, int dGreen, int dBlue){ Red = dRed; Green = dGreen; Blue = dBlue; name = dname; } float Red(){ return Red; } float Green(){ return Green; } float Blue(){ return Blue; } 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(); // MapSave = (String[])expand(MapSave, mapW * mapH); // for(int i = 0; i < MapTiles.length; i++){ // MapSave[i] = "grass"; // } //saveStrings( name + ".txt", MapSave); MapLoad = loadStrings(name + ".txt"); for(int i = 0; i < MapLoad.length; i++){ MapTiles[i].identify("grass", 0, 200, 0); } } void create(){ for(int i = 0; i < MapTiles.length; i++){ for(int j = 0; j < mapW; j++){ for(int k = 0; k < mapH; k++){ if(i < MapLoad.length){ if(MapLoad[i].equals("grass")){ MapTiles[i].create(grass.Red(), grass.Green(), grass.Blue(), 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; } }