Now it works except for one thing. When I press up 3 times it stops working how it should. Normally the tile you have selected follow the mouse. Right now it when you press up the third time the tile stops where your mouse was. You can't get control of the tile again.
This problem does not show up when running it through Processing, only through the application. Here all of the code:
Code:/*
Map Editor - by Jesse LloydDominik
*/
PImage[] animatedTiles = new PImage[33];
PImage[] floorTiles = new PImage[86];
PImage[] unpassableTiles = new PImage[108];
PImage[] trees = new PImage[29];
PImage[] houses = new PImage[51];
String[] instanceString = new String[80];
String[] typeString = new String[80];
int[] instanceInt = new int[80];
int[] typeInt = new int[80];
int[] cellPos = new int[80];
Tile[] tile = new Tile[80];
int mouseInstance;
int mouseType;
int time;
PFont font;
void setup(){
size(480,432);
font = loadFont("text-48.vlw");
textFont(font,36);
String[] instanceString = loadStrings("inProgress/instance.txt");
String[] typeString = loadStrings("inProgress/type.txt");
for(int i=0; i<80;i++){
cellPos[i] = i;
instanceInt[i] = int(instanceString[i]);
typeInt[i] = int(typeString[i]);
tile[i] = new Tile(cellPos[i],instanceInt[i],typeInt[i]);
}
frameRate(25);
loadTiles();
}
void draw(){
background(225);
rect(0,0,320,256);
text("rect",320,0);
for(int i=0;i<80;i++){
tile[i].draw();
}
text("loaded",0,0);
editorGrid();
drawMouse();
time++;
}
void editorGrid(){
fill(255);
rect(0,height-64,64,64);
rect(96,height-64,64,64);
rect(96+96,height-64,64,64);
fill(0);
textFont(font,20);
text("Load",6,height-36,64,64);
text("Save",6+96,height-36,64,64);
textFont(font,18);
text("Final",4+96+96,height-36,64,64);
for(int i = 0; i<320; i+=32){
for(int j = 0; j<256; j+=4){
point(i,j);
}
}
for(int i = 0; i<256; i+=32){
for(int j = 0; j<320; j+=4){
point(j,i);
}
}
}
void keyPressed(){
if(key==CODED){
if (keyCode == UP && mouseType<4){
if (mouseType==0){mouseInstance=0;}
if (mouseType==1 && mouseInstance>unpassableTiles.length-1){mouseInstance=0;}
if (mouseType==2 && mouseInstance>trees.length-1){mouseInstance=0;}
if (mouseType==3 && mouseInstance>houses.length-1){mouseInstance=0;}
mouseType++;
}
else if (keyCode==DOWN && mouseType>0){
if (mouseType==1 && mouseInstance>floorTiles.length-1){mouseInstance=0;}
if (mouseType==2){mouseInstance=0;}
if (mouseType==3 && mouseInstance>unpassableTiles.length-1){mouseInstance=0;}
if (mouseType==4 && mouseInstance>trees.length-1){mouseInstance=0;}
mouseType--;
}
else if (keyCode==RIGHT && mouseType==0 && mouseInstance<floorTiles.length-1){
mouseInstance++;
}
else if (keyCode==RIGHT && mouseType==1 && mouseInstance<animatedTiles.length-1){
if (mouseInstance==0){
mouseInstance=3;
}
else if (mouseInstance==3){
mouseInstance=6;
}
else if (mouseInstance==6){
mouseInstance=10;
}
else if (mouseInstance==10){
mouseInstance=14;
}
else if (mouseInstance==14){
mouseInstance=18;
}
else if (mouseInstance==18){
mouseInstance=21;
}
else if (mouseInstance==21){
mouseInstance=24;
}
else if(mouseInstance==24){
mouseInstance=27;
}
else{
mouseInstance=30;
}
}
else if (keyCode==RIGHT && mouseType==2 && mouseInstance<unpassableTiles.length-1){
mouseInstance++;
}
else if (keyCode==RIGHT && mouseType==3 && mouseInstance<trees.length-1){
mouseInstance++;
}
else if (keyCode==RIGHT && mouseType==4 && mouseInstance<houses.length-1){
mouseInstance++;
}
else if(keyCode==LEFT && mouseInstance>0){
if (mouseType==1){
if (mouseInstance==30){
mouseInstance=27;
}
else if (mouseInstance==27){
mouseInstance=24;
}
else if(mouseInstance==24){
mouseInstance=21;
}
else if(mouseInstance==21){
mouseInstance=18;
}
else if (mouseInstance==18){
mouseInstance=14;
}
else if (mouseInstance==14){
mouseInstance=10;
}
else if (mouseInstance==10){
mouseInstance=6;
}
else if (mouseInstance==6){
mouseInstance=3;
}
else{
mouseInstance=0;
}
}
else{
mouseInstance--;
}
}
}
}
void mousePressed(){
edit();
if (mouseX>96 && mouseX<96+64 && mouseY>height-64 && mouseY<height){
for(int i=0;i<80;i++){
instanceString[i] = str(instanceInt[i]);
typeString[i] = str(typeInt[i]);
}
saveStrings("inProgress/instance.txt", instanceString);
saveStrings("inProgress/type.txt", typeString);
}
if (mouseX>96+96 && mouseX<96+96+64 && mouseY>height-64 && mouseY<height){
for(int i=0;i<80;i++){
instanceString[i] = str(instanceInt[i]);
typeString[i] = str(typeInt[i]);
}
saveStrings("final/instance.txt", instanceString);
saveStrings("final/type.txt", typeString);
}
if (mouseX>0 && mouseX<64 && mouseY>height-64 && mouseY<height){
String[] instanceString = loadStrings("inProgress/instance.txt");
String[] typeString = loadStrings("inProgress/type.txt");
for(int i=0; i<80;i++){
instanceInt[i] = int(instanceString[i]);
typeInt[i] = int(typeString[i]);
tile[i].in = instanceInt[i];
tile[i].t = typeInt[i];
}
}
}
void drawMouse(){
if (mouseType==0){
image(floorTiles[mouseInstance],mouseX,mouseY,32,32);
}
else if (mouseType==1){
image(animatedTiles[mouseInstance],mouseX,mouseY,32,32);
}
else if(mouseType==2){
image(unpassableTiles[mouseInstance],mouseX,mouseY,32,32);
}
else if(mouseType==3){
image(trees[mouseInstance],mouseX,mouseY,32,32);
}
else if(mouseType==4){
image(houses[mouseInstance],mouseX,mouseY,32,32);
}
else{
image(floorTiles[mouseInstance],mouseX,mouseY,32,32);
}
}
Code finished in next post