diff --git a/Camera.pde b/Camera.pde index 51aa70e..7d9ff0c 100644 --- a/Camera.pde +++ b/Camera.pde @@ -32,8 +32,14 @@ class Camera { for (int i = 0; i < width / settings.chunkSize + 1; i++) { for (int j = 0; j < height / settings.chunkSize + 5; j++) { render.renderChunk(i + (int)x, j + (int)y); + render.renderShadow(i + (int)x, j + (int)y); } } pop(); } + + public void showChunk(int x, int y) { + render.renderChunk(x, y); + render.renderShadow(x, y); + } } diff --git a/Controller.pde b/Controller.pde index 7c8f8ad..9de1ca7 100644 --- a/Controller.pde +++ b/Controller.pde @@ -2,22 +2,22 @@ Boolean up = false, down = false, left = false, right = false, shift = false; void keyPressed() { if (key == 'r') { - world = new World((long)random(settings.randomRange), 0.1); + world = new World((long)random(settings.seedRange), 0.1); cam = new Camera(0, 0, world); } - if (key == 'w' || key == 'W') up = true; - if (key == 'a' || key == 'A') left = true; - if (key == 's' || key == 'S') down = true; - if (key == 'd' || key == 'D') right = true; + if (key == 'w' || key == 'W' || key == 'ц' || key == 'Ц') up = true; + if (key == 'a' || key == 'A' || key == 'ф' || key == 'Ф') left = true; + if (key == 's' || key == 'S' || key == 'ы' || key == 'Ы') down = true; + if (key == 'd' || key == 'D' || key == 'в' || key == 'В') right = true; if (keyCode == SHIFT) shift = true; } void keyReleased() { - if (key == 'w' || key == 'W') up = false; - if (key == 'a' || key == 'A') left = false; - if (key == 's' || key == 'S') down = false; - if (key == 'd' || key == 'D') right = false; + if (key == 'w' || key == 'W' || key == 'ц' || key == 'Ц') up = false; + if (key == 'a' || key == 'A' || key == 'ф' || key == 'Ф') left = false; + if (key == 's' || key == 'S' || key == 'ы' || key == 'Ы') down = false; + if (key == 'd' || key == 'D' || key == 'в' || key == 'В') right = false; if (keyCode == SHIFT) shift = false; } diff --git a/DEBUG.pde b/DEBUG.pde index efc9352..4878fad 100644 --- a/DEBUG.pde +++ b/DEBUG.pde @@ -10,10 +10,11 @@ void MAIN_DEBUG() { } } -void CHUNK_DEBUG(int x, int y) { +void CHUNK_DEBUG(Chunk chunk) { if (settings.CHUNK_DEBUG) { fill(200, 0, 30); - text(x, x * settings.chunkSize, y * settings.chunkSize + 10); - text(y, x * settings.chunkSize, y * settings.chunkSize + 20); + text(chunk.getX(), chunk.getX() * settings.chunkSize, chunk.getY() * settings.chunkSize + 10); + text(chunk.getY(), chunk.getX() * settings.chunkSize, chunk.getY() * settings.chunkSize + 20); + text(chunk.getHight(), chunk.getX() * settings.chunkSize, chunk.getY() * settings.chunkSize + 30); } } diff --git a/Render.pde b/Render.pde index 1371de4..a1bb7a4 100644 --- a/Render.pde +++ b/Render.pde @@ -18,6 +18,49 @@ class Render { vertex(x * settings.chunkSize, (1 + y) * settings.chunkSize, 0, settings.chunkSize); endShape(); - CHUNK_DEBUG(x, y); + CHUNK_DEBUG(chunk); + } + + public void renderShadow(int x, int y) { + Chunk[][] chunks = new Chunk[3][3]; + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + chunks[i][j] = world.getChunk(j - 1 + x, i - 1 + y); + } + } + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (chunks[i][j] != null && chunks[i][j].getHight() < chunks[1][1].getHight()) { + PImage shadow = null; + + if (i == 0 && j == 0){ shadow = textures.getShadow(4);} // | 00 01 02 | | 4 0 5 | + else if (i == 0 && j == 1){ shadow = textures.getShadow(0);} // | 10 -- 12 | | 3 - 1 | + else if (i == 0 && j == 2){ shadow = textures.getNoTexture();} // | 20 21 22 | | 7 2 6 | + else if (i == 1 && j == 0){ shadow = textures.getShadow(3);} + else if (i == 1 && j == 2){ shadow = textures.getNoTexture();} + else if (i == 2 && j == 0){ shadow = textures.getShadow(7);} + else if (i == 2 && j == 1){ shadow = textures.getNoTexture();} //<>// + else if (i == 2 && j == 2){ shadow = textures.getNoTexture();} + else { shadow = textures.getNoTexture();} + + beginShape(); + if (mouseX > x * settings.chunkSize && mouseX < (x + 1) * settings.chunkSize + && mouseY > y * settings.chunkSize && mouseY < (y + 1) * settings.chunkSize + && settings.SHADOW_DEBUG) + { + fill(100, 50, 150); + } else { + texture(shadow); + } + vertex((j - 1 + x) * settings.chunkSize, (i - 1 + y) * settings.chunkSize, 0, 0); //<>// + vertex((j + x) * settings.chunkSize, (i - 1 + y) * settings.chunkSize, settings.chunkSize, 0); //<>// + vertex((j + x) * settings.chunkSize, (i + y) * settings.chunkSize, settings.chunkSize, settings.chunkSize); //<>// + vertex((j - 1 + x)* settings.chunkSize, (i + y) * settings.chunkSize, 0, settings.chunkSize); //<>// + endShape(); + } + } + } } } diff --git a/Settings.pde b/Settings.pde index 6fb9133..10756d0 100644 --- a/Settings.pde +++ b/Settings.pde @@ -1,11 +1,15 @@ class Settings { public final int chunkSize = 32; public final int maxHight = new Textures().lengthTextures(); + public final float cameraSpeed = 0.1; public final int cameraSprintCoefficient = 2; - public final long randomRange = 100; + + // Seed range + public final long seedRange = 100; // DEBUG public final boolean MAIN_DEBUG = false; public final boolean CHUNK_DEBUG = false; + public final boolean SHADOW_DEBUG = false; } diff --git a/Textures.pde b/Textures.pde index ec6fd3e..7587e14 100644 --- a/Textures.pde +++ b/Textures.pde @@ -1,5 +1,6 @@ class Textures { private PImage[] textures; + private PImage[] shadows; private PImage noTexture; Textures() { @@ -11,11 +12,23 @@ class Textures { loadImage("textures/snow.png") }; + this.shadows = new PImage[] { + loadImage("textures/shadows/shadowU.png"), + loadImage("textures/shadows/shadowR.png"), + loadImage("textures/shadows/shadowD.png"), + loadImage("textures/shadows/shadowL.png"), + loadImage("textures/shadows/shadowAngleU.png"), + loadImage("textures/shadows/shadowAngleR.png"), + loadImage("textures/shadows/shadowAngleD.png"), + loadImage("textures/shadows/shadowAngleL.png") + }; + noTexture = loadImage("textures/noTexture.png"); } public PImage getTexture(int i) { return textures[i]; } public PImage getNoTexture() { return noTexture; } + public PImage getShadow(int i) { return shadows[i]; } public int lengthTextures() { return textures.length; }; } diff --git a/World.pde b/World.pde index 783978b..ade734b 100644 --- a/World.pde +++ b/World.pde @@ -18,15 +18,18 @@ class World { chunks.get(x).add(i, null); } } - chunks.get(x).add(y, chunk); //<>// + chunks.get(x).add(y, chunk); } } public Chunk getChunk(int x, int y) { + if (x < 0 || y < 0) { + return null; + } try { chunks.get(x).get(y); } - catch(IndexOutOfBoundsException e) { //<>// + catch(IndexOutOfBoundsException e) { Chunk newChunk = gen.generateChunk(x, y); setChunk(newChunk, x, y); } diff --git a/minecraft2D.pde b/minecraft2D.pde index b3d5900..24d3c42 100644 --- a/minecraft2D.pde +++ b/minecraft2D.pde @@ -4,11 +4,12 @@ Settings settings; void settings() { size(800, 800, P2D); + noSmooth(); } void setup() { settings = new Settings(); - world = new World((long)random(settings.randomRange), 0.1); + world = new World((long)random(settings.seedRange), 0.1); cam = new Camera(0, 0, world); noStroke(); } diff --git a/textures/shadows/shadowAngleD.png b/textures/shadows/shadowAngleD.png new file mode 100644 index 0000000..d30a5c7 Binary files /dev/null and b/textures/shadows/shadowAngleD.png differ diff --git a/textures/shadows/shadowAngleL.png b/textures/shadows/shadowAngleL.png new file mode 100644 index 0000000..98d5aee Binary files /dev/null and b/textures/shadows/shadowAngleL.png differ diff --git a/textures/shadows/shadowAngleR.png b/textures/shadows/shadowAngleR.png new file mode 100644 index 0000000..e2c49f1 Binary files /dev/null and b/textures/shadows/shadowAngleR.png differ diff --git a/textures/shadows/shadowAngleU.png b/textures/shadows/shadowAngleU.png new file mode 100644 index 0000000..7636f48 Binary files /dev/null and b/textures/shadows/shadowAngleU.png differ diff --git a/textures/shadows/shadowD.png b/textures/shadows/shadowD.png new file mode 100644 index 0000000..95d9290 Binary files /dev/null and b/textures/shadows/shadowD.png differ diff --git a/textures/shadows/shadowL.png b/textures/shadows/shadowL.png new file mode 100644 index 0000000..a833e89 Binary files /dev/null and b/textures/shadows/shadowL.png differ diff --git a/textures/shadows/shadowR.png b/textures/shadows/shadowR.png new file mode 100644 index 0000000..91d5f20 Binary files /dev/null and b/textures/shadows/shadowR.png differ diff --git a/textures/shadows/shadowU.png b/textures/shadows/shadowU.png new file mode 100644 index 0000000..9def861 Binary files /dev/null and b/textures/shadows/shadowU.png differ