No description provided
The showcase player uses a modified version of Processing.js in combination with jsweet to let students program their apps in Java code while still allowing for browser support.
Content created by students is scaled to fit the showcase frame while maintaining aspect ratio and cursor position. This is why some projects may appear blurry in fullscreen, or why some small details may not be visible on a small screen
<iframe width='500px' height='400px' src='https://nest.ktbyte.com/nest#458091' allowfullscreen></iframe>
//Link: https://www.ktbyte.com/projects/project/458091/2d-minecraft-rpg //Global Variables int [][] world; int ROWS, COLS; int C_SIZE = 25; int seed = int(random(0, 1000000000)); //356159210, 620531678, 677250564, 390387892 // int seed = 620531678; boolean right, left, up, down; float speed = 0.1; float hp = 100; boolean gameover = false; boolean win = false; String dimension = "grass"; //Terrains int GRASS = 0; int WATER = 1; int LAVA = 2; int STONE = 3; int WOOD = 4; int COLLECT = 5; int PORTAL = 6; int NETHERRACK = 7; int ENDSTONE = 8; int ENDLAVA = 9; //player row, col int pr, pc; PImage webImg; void setup() { frameRate(60); size(800, 600); //800, 600 ROWS = height / C_SIZE; COLS = width / C_SIZE; pr = ROWS / 2; pc = COLS /2; noiseSeed(seed); //Change for different maps (like minecraft seeds) initWorld(); String url = "https://i.imgflip.com/4i12va.png?a448080"; webImg = loadImage(url, "png"); world[pr][pc] = GRASS; world[int(random(ROWS))][int(random(COLS))] = COLLECT; // world[int(random(ROWS))][int(random(COLS))] = COLLECT; // world[int(random(ROWS))][int(random(COLS))] = COLLECT; } void draw() { if(gameover == false || win == false) { drawWorld(); drawPlayer(); playerInteractions(); checkGameover(); textSize(20); fill(235, 219, 52); text("Seed: " + seed, 8, 20); text("Health: " + int(hp), 8, 40); if(hp > 100) { hp = 100; } } else { gameover(); } } void checkGameover() { if(hp <= 0) { gameover = true; } } void gameover() { background(0); fill(255); textSize(50); textAlign(CENTER, CENTER); text("Game Over :(", width/2, height/ 2); textSize(30); text("Seed: " + seed, width/2, height/2 + 40); } void playerInteractions() { if(world[pr][pc] == WATER) { hp -= 0.1; checkGameover(); } if(world[pr][pc] == GRASS) { if(hp < 100 && dimension == "grass") { hp += 0.05; } } if(world[pr][pc] == LAVA) { hp -= 0.5; checkGameover(); } if(world[pr][pc] == ENDLAVA) { hp -= 0.5; checkGameover(); } if(world[pr][pc] == COLLECT) { world[int(random(ROWS))][int(random(COLS))] = PORTAL; if(dimension == "grass") { world[pr][pc] = GRASS; } else if(dimension == "nether") { world[pr][pc] = NETHERRACK; } else if(dimension =="end") { world[pr][pc] = ENDSTONE; } } if(world[pr][pc] == PORTAL) { if(dimension == "grass") { nether(); } else if(dimension == "nether") { end(); } else if(dimension == "end") { win = true; win(); } } } void end() { dimension = "end"; world = new int[ROWS][COLS]; for(int r = 0; r < ROWS; r++) { for(int c = 0; c < COLS; c++) { float val = random(1); val = noise(c / 10.0, r / 10.0); if(val < 0.5) { world[r][c] = ENDSTONE; } else if(val > 0.5 && val < 0.7) { world[r][c] = ENDLAVA; } else if(val > 0.7 && val < 0.8) { world[r][c] = ENDLAVA; } else if(val > 0.8) { world[r][c] = STONE; } } } world[pr][pc] = ENDSTONE; world[int(random(ROWS))][int(random(COLS))] = COLLECT; checkGameover(); } void nether() { dimension = "nether"; world = new int[ROWS][COLS]; for(int r = 0; r < ROWS; r++) { for(int c = 0; c < COLS; c++) { float val = random(1); val = noise(c / 10.0, r / 10.0); if(val < 0.5) { world[r][c] = NETHERRACK; } else if(val > 0.5 && val < 0.7) { world[r][c] = LAVA; } else if(val > 0.7 && val < 0.8) { world[r][c] = LAVA; } else if(val > 0.8) { world[r][c] = STONE; } } } world[pr][pc] = NETHERRACK; world[int(random(ROWS))][int(random(COLS))] = COLLECT; checkGameover(); } void win() { background(255, 217, 92); fill(0); textSize(50); textAlign(CENTER, CENTER); text("You Win", width/2, height/ 2); textSize(30); text("Seed: " + seed, width/2, height/2 + 40); text("Health: " + int(hp), width/2, height/2 + 70); } void initWorld() { world = new int[ROWS][COLS]; for(int r = 0; r < ROWS; r++) { for(int c = 0; c < COLS; c++) { float val = random(1); val = noise(c / 10.0, r / 10.0); if(val < 0.5) { world[r][c] = GRASS; } else if(val > 0.5 && val < 0.7) { world[r][c] = WATER; } else if(val > 0.7 && val < 0.8) { world[r][c] = LAVA; } else if(val > 0.8) { world[r][c] = STONE; } } } } void drawPlayer() { float x = pc * C_SIZE; float y = pr * C_SIZE; image(webImg, x, y, C_SIZE, C_SIZE); } void drawWorld() { for(int r = 0; r < ROWS; r++) { for(int c = 0; c < COLS; c++) { if(world[r][c] == GRASS) { fill(18, 130, 10); } else if(world[r][c] == WATER) { fill(0, 0, 255); } else if(world[r][c] == LAVA) { fill(255, 72, 0); } else if(world[r][c] == STONE) { fill(89, 91, 92); } else if(world[r][c] == WOOD) { fill(179, 123, 2); } else if(world[r][c] == COLLECT) { fill(235, 219, 52); } else if(world[r][c] == PORTAL) { fill(128, 0, 201); } else if(world[r][c] == NETHERRACK) { fill(122, 21, 51); } else if(world[r][c] == ENDSTONE) { fill(255, 252, 186); } else if(world[r][c] == ENDLAVA) { fill(69, 0, 207); } rect(c * C_SIZE, r * C_SIZE, C_SIZE, C_SIZE); } } } void keyPressed() { movePlayer(); } void movePlayer() { if(win == false) { int oldR = pr; int oldC = pc; if(keyCode == RIGHT || keyCode == 'D') { pc++; } if(keyCode == LEFT || keyCode == 'A') { pc--; } if(keyCode == UP || keyCode == 'W') { pr--; } if(keyCode == DOWN || keyCode == 'S') { pr++; } if (pc >= COLS || pc < 0 || pr >= ROWS || pr < 0 || world[pr][pc] == STONE) { // ...reset back to the old position pc = oldC; pr = oldR; } } }