> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.YcLtkSZxduu/rev.6944
 * 
 * authors: 
 *   Benjamin Y

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



// Pressing Control-R will render this sketch.

int i = 0;

int[][] rooms = {
    {3,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,3},
    {2,2,3,3,2,3,2,2,2,3,3,3,3,2,2,2,2,4,4},
    {3,3,2,3,3,2,2,4,2,2,2,3,3,3,2,2,4,4,4},
    {4,4,4,4,4,4,4,4,4,4,2,2,3,3,3,2,4,4,4},
    {4,4,3,3,7,3,3,3,4,4,4,2,2,3,3,3,3,4,4},
    {4,3,3,3,7,6,6,3,3,4,4,4,2,2,3,3,3,2,2},
    {3,3,3,6,7,6,6,9,3,3,4,4,2,2,3,3,3,3,3},
    {3,7,9,9,7,9,9,9,9,3,4,4,4,2,2,3,3,3,3},
    {7,9,9,3,7,7,3,9,9,3,2,4,4,2,2,3,3,3,3},
    {9,9,3,3,3,7,3,3,9,3,2,4,4,4,2,3,3,3,3},
    {4,4,4,4,3,7,4,3,9,3,3,3,4,4,2,3,3,3,2}
    };
int[][] originalworld = rooms;
int[] colors = {loadImage("/static/uploaded_resources/p.18937/glass.png"),
loadImage("/static/uploaded_resources/p.18937/fire.png"),
loadImage("/static/uploaded_resources/p.18937/sand2.png"),
loadImage("/static/uploaded_resources/p.18937/grass.png"),
loadImage("/static/uploaded_resources/p.18937/water.png"),
loadImage("/static/uploaded_resources/p.18937/glass.png"),
loadImage("/static/uploaded_resources/p.18937/brownrock2.png"),
loadImage("/static/uploaded_resources/p.18937/grayrock3.png"),
loadImage("/static/uploaded_resources/p.18937/redwood2.png"),
loadImage("/static/uploaded_resources/p.18937/soil5.png"),
loadImage("/static/uploaded_resources/p.18937/bush.png"),
loadImage("/static/uploaded_resources/p.18937/obsidian.png"),
loadImage("/static/uploaded_resources/p.18937/limestone.png"),
};
int[] namelist = {"Air",
"Fire",
"Sand",
"Grass",
"Water",
"Glass",
"Brown Rock",
"Gray Rock",
"Redwood",
"Soil",
"Bush",
"Obsidian",
"Limestone",
};
int[] themecolors = {color(255,255,255),// default
color(0,128,102),// green padding
color(0,255,255),// blue padding
color(51,128,255),// sky padding
color(153,128,0),// soil padding
};
/*int[] textcolors = {color(0,0,0},// default
color(255,255,255),
color(255,255,255),
color(0,0,0),
color(255,255,255),
};*/
boolean arrowbutton = true;
float health= 100;
int maxHealth = 100;
int px = 0;
int py = 0;
int my = 10;
int mx = 18;
lastHit = -1;
lastPressed = -1;
int slc = 0;
int slt = 0;
int c = 8;

void setup() {  // this is run once.   
    
    // set the background color
    background(255);
    
    // canvas size (Variable aren't evaluated. Integers only, please.)
    size(420, 600); 
      
    // smooth edges
    smooth();
    
    // limit the number of frames per second
    frameRate(30);
    
    // set the width of the line. 
    strokeWeight(2);
} 

void draw() {  // this is run repeatedly.  
    background(themecolors[slt]);
    fill(0);
    stroke(0);
    // sorroundings
    if(px > 0) {
        image(colors[rooms[py][px-1]], 0, 100, 100, 100);
    }
    if(px > 0 && py > 0) {
        image(colors[rooms[py-1][px-1]], 0, 0, 100, 100);
    }
    if(py > 0) {
        image(colors[rooms[py-1][px]], 100, 0, 100, 100);
    }
    if(py > 0 && px < mx) {
        image(colors[rooms[py-1][px+1]], 200, 0, 100, 100);
    }
    if(px < mx) {
        image(colors[rooms[py][px+1]], 200, 100, 100, 100);
    }
    if(px < mx && py < my) {
        image(colors[rooms[py+1][px+1]], 200, 200, 100, 100);
    }
    if(py < my) {
        image(colors[rooms[py+1][px]], 100, 200, 100, 100);
    }
    if(px > 0 && py < my) {
        image(colors[rooms[py+1][px-1]], 0, 200, 100, 100);
    }
    fill(0);
    text(slc,320,(10+(colors.length*10))+20);
    text(namelist[slc],302,(40+(colors.length*10))+20);
    text("Press Arrow Keys to Move",30,335);
    text("Press Shift to choose block",30,355);
    text("Press Ctrl to change block",30,375);
    text("Press Alt to change background color",30,395);
    text("Press Space to reset",30,415);
    text("If you have numpad, set lock to number:",30,435);
    text("Press 1 to Turn On/Off Arrow Buttons",50,455);
    text("X: "+px+" Y: "+py,30,315);
    text("You are stepping on: "+namelist[rooms[py][px]],100,315);
    int az = 10;
    for (i = 0;i < colors.length;i+=1) {
        image(colors[i], 320,az,10,10);
        fill(0);
        text(namelist[i],335,az+10);
        if (mousePressed && mouseX > 320 && mouseX < 420 && mouseY > az && mouseY < az+10) {
            slc = i;
            if (mouseButton == RIGHT) {
                rooms[py][px] = slc;
            }
        }
        az += 10;
        
    }
    fill(0,255,255);
    stroke(0);
    rect(30,500,c*(mx+1),c*(my+1));
    stroke(255,0,0);
    //rect(30+(px*c),400+(py*c),3*c,3*c);
    stroke(0,0,0);
    fill(128,128,128);
    if (arrowbutton) {
        if (py != 0) {
            triangle(125,50,175,50,150,25);
        }
        if (px != 0) {
            triangle(50,125,50,175,25,150);
        }
        if (px != mx) {
            triangle(250,125,250,175,275,150);
        }
        if (py != my) {
            triangle(125,250,175,250,150,275);
        }
    }
    noFill();
    noStroke();
    for (i = 0;i < my+1;i+=1) {
        for (j = 0;j < mx+1;j+=1) {
            image(colors[rooms[i][j]], 30+(j*c), 500+(i*c),c,c);
        }
    }
    stroke(255,0,0);
    fill(255,255,255,102);
    rect(30+(px*c),500+(py*c),c,c);
    noStroke();
    fill(255,255,255,51);
    rect(30+((px-1)*c),500+((py-1)*c),3*c,3*c);
    
    stroke(255,0,0);
    rect(319,(10+(slc*10))-1,12,12);
    fill(255,0,0);
    text(namelist[slc],335,20+(slc*10));
    
    
    image(colors[rooms[py][px]], 100, 100, 100, 100);
    fill(255,0,0);
    noFill();
    rect(100,100,100,100);
    rect(0,0,300,300);
   
    if (keyPressed) {
        if (key == CODED) {
            stroke(255,0,0);
            fill(255,0,0,153);
            if(keyCode == LEFT && !(lastHit==LEFT)) {
                px -= 1;
                if(px < 0) {
                    px = 0;
                }
                if (arrowbutton && px != 0) {
                    triangle(50,125,50,175,25,150);
                }
                lastHit = LEFT;
            }
            if(keyCode == RIGHT && !(lastHit==RIGHT)) {
                px += 1;
                if(px > mx) {
                    px = mx;
                }
                if (arrowbutton && px != mx) {
                    triangle(250,125,250,175,275,150);
                }
                lastHit = RIGHT;
            }
            if(keyCode == UP && !(lastHit==UP)) {
                py -= 1;
                if(py < 0) {
                    py = 0;
                }
                if (arrowbutton && py != 0) {
                    triangle(125,50,175,50,150,25);
                }
                lastHit = UP;
            }
            if(keyCode == DOWN && !(lastHit==DOWN)) {
                py += 1;
                if(py > my) {
                    py = my;
                }
                if (arrowbutton && py != my) {
                    triangle(125,250,175,250,150,275);
                }
                lastHit = DOWN;
            }
            if(keyCode == SHIFT && !(lastHit==SHIFT)) {
                slc += 1;
                if(slc >= colors.length) {
                    slc = 0;
                }
                lastHit = SHIFT;
            }
            if(keyCode == CONTROL && !(lastHit==CONTROL)) {
                rooms[py][px] = slc;
                lastHit = CONTROL;
            }
            if(keyCode == ALT && !(lastHit==ALT)) {
                slt += 1
                if(slt >= themecolors.length) {
                    slt = 0;
                }
                lastHit = ALT;
            }

        } else {
            if(key == ' ' && !(lastHit==' ')) {
                slt = 0;
                px = 0;
                py = 0;
                slc = 0;
                lastHit = ' ';
                rooms = originalworld;
            }
            if(key == '1' && !(lastHit=='1')) {
                arrowbutton = !arrowbutton;
                lastHit = '1';
            }
                
        }
    } else {
        lastHit = -1;
    }
    if (mousePressed && arrowbutton) {
        stroke(255,0,0);
        fill(255,0,0,153);
        if (((mouseX > 125 && mouseX < 175) && (mouseY > 25 && mouseY < 50)) && !(lastPressed == UP) && py != 0) {
            py -= 1;
            if(py < 0) {
                py = 0;
            }
            if (arrowbutton) {
                triangle(125,50,175,50,150,25);
            }
            lastPressed = UP;
        }
        if (((mouseX > 125 && mouseX < 175) && (mouseY > 250 && mouseY < 275)) && !(lastPressed == DOWN) && py != my) {
            py += 1;
            if(py > my) {
                py = my;
            }
            if (arrowbutton) {
                triangle(125,250,175,250,150,275);
            }
            lastPressed = DOWN;
        }
        if (((mouseX > 250 && mouseX < 275) && (mouseY > 125 && mouseY < 175)) && !(lastPressed == RIGHT) && px != mx) {
            px += 1;
            if(px > mx) {
                px = mx;
            }
            if (arrowbutton) {
                triangle(250,125,250,175,275,150);
            }
            lastPressed = RIGHT;
        }
        if (((mouseX > 25 && mouseX < 50) && (mouseY > 125 && mouseY < 175)) && !(lastPressed == LEFT) && px != 0) {
            px -= 1;
            if(px < 0) {
                px = 0;
            }
            if (arrowbutton) {
                triangle(50,125,50,175,25,150);
            }
            lastPressed = LEFT;
        }
    } else {
        lastPressed = -1;
    }

    
    // move over a pixel
    if (i < width) {
        i++;
    } else {
        i = 0; 
    }
}