Попытка добавить тени
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
45
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
13
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; };
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
BIN
textures/shadows/shadowAngleD.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
textures/shadows/shadowAngleL.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
textures/shadows/shadowAngleR.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
textures/shadows/shadowAngleU.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
textures/shadows/shadowD.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
textures/shadows/shadowL.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
textures/shadows/shadowR.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
textures/shadows/shadowU.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |