Добавил тени, масштаб, иконку
Ура, теперь всё работает. Баг с тенью был исправлен. Добавил возможность масштабировать.
This commit is contained in:
parent
8d81cf496c
commit
6297508e1f
24
Camera.pde
24
Camera.pde
@ -2,6 +2,8 @@ class Camera {
|
||||
private float x;
|
||||
private float y;
|
||||
private Render render;
|
||||
|
||||
private int w, h;
|
||||
|
||||
Camera(int x, int y, World world) {
|
||||
this.x = x;
|
||||
@ -27,14 +29,24 @@ class Camera {
|
||||
public float getY() { return y; }
|
||||
|
||||
public void showArea() {
|
||||
w = width / settings.chunkSize + 10;
|
||||
h = height / settings.chunkSize + 10;
|
||||
|
||||
w /= scale;
|
||||
h /= scale;
|
||||
push();
|
||||
translate(-x * settings.chunkSize, -y * settings.chunkSize);
|
||||
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);
|
||||
scale(scale);
|
||||
translate(-x * settings.chunkSize, -y * settings.chunkSize);
|
||||
for (int i = 0; i < w; i++) {
|
||||
for (int j = 0; j < h; j++) {
|
||||
render.renderChunk(i + (int)x, j + (int)y);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < w; i++) {
|
||||
for (int j = 0; j < h; j++) {
|
||||
render.renderShadow(i + (int)x, j + (int)y);
|
||||
}
|
||||
}
|
||||
}
|
||||
pop();
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
Boolean up = false, down = false, left = false, right = false, shift = false;
|
||||
float scale = 1;
|
||||
|
||||
void keyPressed() {
|
||||
if (key == 'r') {
|
||||
@ -35,3 +36,9 @@ void move() {
|
||||
cam.setY(cam.getY() + settings.cameraSpeed * (shift ? settings.cameraSprintCoefficient : 1)); // down
|
||||
}
|
||||
}
|
||||
|
||||
void mouseWheel(MouseEvent e) {
|
||||
scale -= e.getCount() * 0.1;
|
||||
scale = scale <= 0 ? 0.1 : scale;
|
||||
scale = scale >= 5 ? 5 : scale;
|
||||
}
|
||||
|
||||
12
DEBUG.pde
12
DEBUG.pde
@ -1,12 +1,12 @@
|
||||
void MAIN_DEBUG() {
|
||||
if (settings.MAIN_DEBUG) {
|
||||
fill(0, 0, 200);
|
||||
text(cam.getX(), 10, 10);
|
||||
text(cam.getY(), 10, 20);
|
||||
text(world.getXSize(), 10, 30);
|
||||
|
||||
|
||||
ellipse(settings.chunkSize, settings.chunkSize, sin(millis() * 0.001) * 10, sin(millis() * 0.001) * 10);
|
||||
text("Camera X: " + cam.getX(), 10, 10);
|
||||
text("Camera Y: " + cam.getY(), 10, 20);
|
||||
text("World X size:" + world.getXSize(), 10, 30);
|
||||
text("Scale: " + scale, 10, 40);
|
||||
text("FPS: " + (int)frameRate, 10, 50);
|
||||
ellipse(2, 2, sin(millis() * 0.001) * 10, sin(millis() * 0.001) * 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
6
History/07.05.md
Normal file
6
History/07.05.md
Normal file
@ -0,0 +1,6 @@
|
||||
Осталось доделать класс камеры, дальше только надеяться на рабочий прототип.
|
||||
|
||||
07.05: Ура, готов рабочий прототип. Осталось только допелить управление. В будущем будет проблема с плавной камерой, но её наверное можно будет решить с помощью translate().
|
||||
Баг, связанный с ArrayList<>. Вызывается исключение. Лечение: нужно заполнять невидимую область null или перейти на HashMap. Правда, волнует вопрос с производительностью, что быстрее ArrayList или HashMap?
|
||||
|
||||
Ура, всё работает. Бага больше нет. Камера двигается плавно.
|
||||
5
History/13.05.md
Normal file
5
History/13.05.md
Normal file
@ -0,0 +1,5 @@
|
||||
13.05: На данный момент у меня появились тени в игре и масштаб. УРА!
|
||||
|
||||
<img src=".\images\13.05.png" alt="13.05" style="zoom:67%;" />
|
||||
|
||||
<img src=".\images\13.05_2.png" alt="13.05" style="zoom:67%;" />
|
||||
BIN
History/images/13.05.png
Normal file
BIN
History/images/13.05.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 206 KiB |
BIN
History/images/13.05_2.png
Normal file
BIN
History/images/13.05_2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 368 KiB |
105
Render.pde
105
Render.pde
@ -1,4 +1,4 @@
|
||||
class Render {
|
||||
class Render { //<>// //<>// //<>// //<>// //<>//
|
||||
private Textures textures;
|
||||
private World world;
|
||||
|
||||
@ -11,53 +11,88 @@ class Render {
|
||||
Chunk chunk = world.getChunk(x, y);
|
||||
|
||||
beginShape();
|
||||
texture(textures.getTexture(chunk.getHight()));
|
||||
vertex(x * settings.chunkSize, y * settings.chunkSize, 0, 0);
|
||||
vertex((1 + x) * settings.chunkSize, y * settings.chunkSize, settings.chunkSize, 0);
|
||||
vertex((1 + x) * settings.chunkSize, (1 + y) * settings.chunkSize, settings.chunkSize, settings.chunkSize);
|
||||
vertex(x * settings.chunkSize, (1 + y) * settings.chunkSize, 0, settings.chunkSize);
|
||||
texture(textures.getTexture(chunk.getHight()));
|
||||
vertex(x * settings.chunkSize, y * settings.chunkSize, 0, 0);
|
||||
vertex((1 + x) * settings.chunkSize, y * settings.chunkSize, settings.chunkSize, 0);
|
||||
vertex((1 + x) * settings.chunkSize, (1 + y) * settings.chunkSize, settings.chunkSize, settings.chunkSize);
|
||||
vertex(x * settings.chunkSize, (1 + y) * settings.chunkSize, 0, settings.chunkSize);
|
||||
endShape();
|
||||
|
||||
CHUNK_DEBUG(chunk);
|
||||
}
|
||||
|
||||
|
||||
public void renderShadow(int x, int y) {
|
||||
if (!settings.renderShadows) return;
|
||||
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 < chunks.length; i++) {
|
||||
for (int j = 0; j < chunks[0].length; 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();}
|
||||
|
||||
boolean angle = false;
|
||||
|
||||
// | 00 01 02 | | 4 0 5 |
|
||||
// | 10 -- 12 | | 3 - 1 |
|
||||
// | 20 21 22 | | 7 2 6 |
|
||||
|
||||
if (i == 0 && j == 0) {
|
||||
shadow = textures.getShadow(4);
|
||||
angle = true;
|
||||
} else if (i == 0 && j == 1) {
|
||||
shadow = textures.getShadow(0);
|
||||
} else if (i == 0 && j == 2) {
|
||||
shadow = textures.getShadow(5);
|
||||
angle = true;
|
||||
} else if (i == 1 && j == 0) {
|
||||
shadow = textures.getShadow(3);
|
||||
} else if (i == 1 && j == 2) {
|
||||
shadow = textures.getShadow(1);
|
||||
} else if (i == 2 && j == 0) {
|
||||
shadow = textures.getShadow(7);
|
||||
angle = true;
|
||||
} else if (i == 2 && j == 1) {
|
||||
shadow = textures.getShadow(2);
|
||||
} else if (i == 2 && j == 2) {
|
||||
shadow = textures.getShadow(6);
|
||||
angle = true;
|
||||
} else {
|
||||
shadow = textures.getNoTexture();
|
||||
}
|
||||
|
||||
if (angle) {
|
||||
if (j == 0 && i == 0
|
||||
&& (chunks[i][j].getHight() < chunks[0][1].getHight()
|
||||
|| chunks[i][j].getHight() < chunks[1][0].getHight())) continue;
|
||||
else if (j == 2 && i == 0
|
||||
&& (chunks[i][j].getHight() < chunks[0][1].getHight()
|
||||
|| chunks[i][j].getHight() < chunks[1][2].getHight())) continue;
|
||||
else if (j == 0 && i == 2
|
||||
&& (chunks[i][j].getHight() < chunks[1][0].getHight()
|
||||
|| chunks[i][j].getHight() < chunks[2][1].getHight())) continue;
|
||||
else if (j == 2 && i == 2
|
||||
&& (chunks[i][j].getHight() < chunks[2][1].getHight()
|
||||
|| chunks[i][j].getHight() < chunks[1][2].getHight())) continue;
|
||||
}
|
||||
|
||||
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); //<>//
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,9 +2,13 @@ class Settings {
|
||||
public final int chunkSize = 32;
|
||||
public final int maxHight = new Textures().lengthTextures();
|
||||
|
||||
// Camera
|
||||
public final float cameraSpeed = 0.1;
|
||||
public final int cameraSprintCoefficient = 2;
|
||||
|
||||
// Render
|
||||
public final boolean renderShadows = true;
|
||||
|
||||
// Seed range
|
||||
public final long seedRange = 100;
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ Settings settings;
|
||||
|
||||
void settings() {
|
||||
size(800, 800, P2D);
|
||||
PJOGL.setIcon("textures/icon.png");
|
||||
noSmooth();
|
||||
}
|
||||
|
||||
@ -11,6 +12,7 @@ void setup() {
|
||||
settings = new Settings();
|
||||
world = new World((long)random(settings.seedRange), 0.1);
|
||||
cam = new Camera(0, 0, world);
|
||||
surface.setTitle("Minecraft 2D");
|
||||
noStroke();
|
||||
}
|
||||
|
||||
|
||||
13
readme.md
13
readme.md
@ -5,15 +5,6 @@
|
||||
В планах сделать
|
||||
- [x] Генерируемый в реальном времени мир.
|
||||
- [ ] Добавить возможность сохранять миры.
|
||||
- [ ] Сделать систему логирования.
|
||||
- [x] Сделать систему ~~логирования~~ дебаг.
|
||||
- [x] Возможность управления камерой стрелочками.
|
||||
|
||||
Осталось доделать класс камеры, дальше только надеяться на рабочий прототип.
|
||||
|
||||
Работа программы: (старое)
|
||||
<img src="D:\ivan-folder\code\Processing\minecraft2D\graph.png" alt="graph" style="zoom:80%;" />
|
||||
|
||||
07.05: Ура, готов рабочий прототип. Осталось только допелить управление. В будущем будет проблема с плавной камерой, но её наверное можно будет решить с помощью translate().
|
||||
Баг, связанный с ArrayList<>. Вызывается исключение. Лечение: нужно заполнять невидимую область null или перейти на HashMap. Правда, волнует вопрос с производительностью, что быстрее ArrayList или HashMap?
|
||||
|
||||
Ура, всё работает. Бага больше нет. Камера двигается плавно.
|
||||
- [ ] Персонажа
|
||||
|
||||
BIN
textures/icon.png
Normal file
BIN
textures/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
Loading…
Reference in New Issue
Block a user