Осталось только доделать класс с камерой. При запуске ошибок не возникает

This commit is contained in:
Ivan Zinchenko 2021-05-06 23:47:06 +05:00
parent 423e695da9
commit eb5afa5df0
14 changed files with 112 additions and 21 deletions

View File

@ -1,2 +1,16 @@
class Camera {
private int x;
private int y;
Camera(int x, int y) {
this.x = x;
this.y = y;
}
public void setX(int x) { this.x = x; }
public void setY(int y) { this.y = y; }
public PVector getXY() {
return new PVector(x, y);
}
}

View File

@ -1,23 +1,23 @@
class Chunk {
private int x;
private int y;
private int level;
private int hight;
Chunk(int _x, int _y, int _level) {
x = _x;
y = _y;
level = _level;
Chunk(int x, int y, int hight) {
this.x = x;
this.y = y;
this.hight = hight;
}
int getX() {
public int getX() {
return x;
}
int getY() {
public int getY() {
return y;
}
int getLevel() {
return level;
public int getHight() {
return hight;
}
}

View File

@ -1,3 +1,17 @@
class Generator {
private long seed;
private float noiseScale;
private int maxHight;
Generator(long seed, float noiseScale) {
this.seed = seed;
this.noiseScale = noiseScale;
}
public Chunk generateChunk(int x, int y) {
noiseSeed(seed);
int hight = (int)map(noise(x, y) * (1 / noiseScale), 0, 1, 0, maxHight);
return new Chunk(x, y, hight);
}
}

View File

@ -1,3 +1,21 @@
class Render {
private Textures textures;
private World world;
Render(World world) {
this.textures = new Textures();
this.world = world;
}
public void renderChunk(int x, int y) {
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);
endShape();
}
}

3
Settings.pde Normal file
View File

@ -0,0 +1,3 @@
static class Settings {
static public int chunkSize = 32;
}

View File

@ -1,3 +1,16 @@
class Textures {
private PImage[] textures;
Textures() {
this.textures = new PImage[] {
loadImage("textures/water.png"),
loadImage("textures/sand.png"),
loadImage("textures/grass.png"),
loadImage("textures/stone.png"),
loadImage("textures/snow.png")
};
}
public PImage getTexture(int i){
return textures[i];
}
}

View File

@ -1,3 +1,32 @@
class World {
private ArrayList<ArrayList<Chunk>> chunks;
private Generator gen;
World(long seed, float noiseScale) {
this.gen = new Generator(seed, noiseScale);
this.chunks = new ArrayList<ArrayList<Chunk>>();
}
public void setChunk(Chunk chunk, int x, int y) {
try {
chunks.get(x).add(y, chunk);
}
catch(Exception e) {
chunks.add(x, new ArrayList<Chunk>());
}
finally {
chunks.get(x).add(y, chunk);
}
}
public Chunk getChunk(int x, int y) {
try {
chunks.get(x).get(y);
}
catch(Exception e) {
Chunk newChunk = gen.generateChunk(x, y);
setChunk(newChunk, x, y);
}
return chunks.get(x).get(y);
}
}

View File

@ -1,9 +1,3 @@
Generator gen;
Render render;
Camera camera;
Textures textures;
World world;
void settings() {
size(800, 800, P2D);
}

View File

@ -2,4 +2,10 @@
Попытка сделать minecraft 2D с видом сверху на processing.
В планах сделать генерируемый в реальном времени мир. Может быть добавить возможность сохранять миры.
В планах сделать
- Генерируемый в реальном времени мир.
- Добавить возможность сохранять миры.
- Сделать систему логирования.
- Возможность управления камерой стрелочками.
Осталось доделать класс камеры, дальше только надеяться на рабочий прототип.

BIN
textures/grass.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
textures/sand.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
textures/snow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
textures/stone.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

BIN
textures/water.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB