1
0
Fork 0
This commit is contained in:
MrDev023 2015-07-20 20:52:45 +02:00
parent e53b56f460
commit d6b9d09d50
6 changed files with 263 additions and 161 deletions

View file

@ -22,20 +22,28 @@ public class Camera {
}
public static void renderCamera() {
if (position.getY() < (int)((new Noise(Main.getGame().getWorld().seed, Main
.getGame().getWorld().octave,
Main.getGame().getWorld().amplitude).getNoise(position.getX(),
position.getZ())) + 1)) {
position.setY((int)((new Noise(Main.getGame().getWorld().seed, Main
.getGame().getWorld().octave,
Main.getGame().getWorld().amplitude).getNoise(position.getX(),
position.getZ())) + 2));
}
glLoadIdentity();
glRotatef(rotation.getX(), 1, 0, 0);
glRotatef(rotation.getY(), 0, 1, 0);
glTranslatef(-position.getX(), -(position.getY()+getHeight()), -position.getZ());
glTranslatef(-position.getX(), -(position.getY() + getHeight()),
-position.getZ());
}
public static void move(float xa, float ya, float za) {
if(true){
gravityFactor += World.GRAVITY * 0.01f;
if(grounded) gravityFactor = 0;
ya -= gravityFactor;
}else{
if (grounded)
gravityFactor = 0;
}
ya -= gravityFactor;
int xStep = (int) Math.abs(xa * 100);
for (int i = 0; i < xStep; i++) {
if (!isColliding(xa / xStep, 0, 0) || noClip) {
@ -126,54 +134,143 @@ public class Camera {
int yb = (int) (position.y + ya - r - 0.01f);
int zmid = (int) (position.z + za);
if(xmid < 0)nx = true;else nx = false;
if(yb < 0)ny = true;else ny = false;
if(zmid < 0)nz = true;else nz = false;
if (xmid < 0)
nx = true;
else
nx = false;
if (yb < 0)
ny = true;
else
ny = false;
if (zmid < 0)
nz = true;
else
nz = false;
if (world.getBlock(xmid, yb, zmid, nx, ny, nz) != null) {
grounded = true;
} else {
grounded = false;
}
if(x0 < 0)nx = true;else nx = false;
if(y0 < 0)ny = true;else ny = false;
if(z0 < 0)nz = true;else nz = false;
if(world.getBlock(x0, y0, z0,nx,ny,nz) != null) return true;
if (x0 < 0)
nx = true;
else
nx = false;
if (y0 < 0)
ny = true;
else
ny = false;
if (z0 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x0, y0, z0, nx, ny, nz) != null)
return true;
if(x1 < 0)nx = true;else nx = false;
if(y0 < 0)ny = true;else ny = false;
if(z0 < 0)nz = true;else nz = false;
if(world.getBlock(x1, y0, z0,nx,ny,nz) != null) return true;
if (x1 < 0)
nx = true;
else
nx = false;
if (y0 < 0)
ny = true;
else
ny = false;
if (z0 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x1, y0, z0, nx, ny, nz) != null)
return true;
if(x1 < 0)nx = true;else nx = false;
if(y1 < 0)ny = true;else ny = false;
if(z0 < 0)nz = true;else nz = false;
if(world.getBlock(x1, y1, z0,nx,ny,nz) != null) return true;
if (x1 < 0)
nx = true;
else
nx = false;
if (y1 < 0)
ny = true;
else
ny = false;
if (z0 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x1, y1, z0, nx, ny, nz) != null)
return true;
if(x0 < 0)nx = true;else nx = false;
if(y1 < 0)ny = true;else ny = false;
if(z0 < 0)nz = true;else nz = false;
if(world.getBlock(x0, y1, z0,nx,ny,nz) != null) return true;
if (x0 < 0)
nx = true;
else
nx = false;
if (y1 < 0)
ny = true;
else
ny = false;
if (z0 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x0, y1, z0, nx, ny, nz) != null)
return true;
if(x0 < 0)nx = true;else nx = false;
if(y0 < 0)ny = true;else ny = false;
if(z1 < 0)nz = true;else nz = false;
if(world.getBlock(x0, y0, z1,nx,ny,nz) != null) return true;
if (x0 < 0)
nx = true;
else
nx = false;
if (y0 < 0)
ny = true;
else
ny = false;
if (z1 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x0, y0, z1, nx, ny, nz) != null)
return true;
if(x1 < 0)nx = true;else nx = false;
if(y0 < 0)ny = true;else ny = false;
if(z1 < 0)nz = true;else nz = false;
if(world.getBlock(x1, y0, z1,nx,ny,nz) != null) return true;
if (x1 < 0)
nx = true;
else
nx = false;
if (y0 < 0)
ny = true;
else
ny = false;
if (z1 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x1, y0, z1, nx, ny, nz) != null)
return true;
if(x1 < 0)nx = true;else nx = false;
if(y1 < 0)ny = true;else ny = false;
if(z1 < 0)nz = true;else nz = false;
if(world.getBlock(x1, y1, z1,nx,ny,nz) != null) return true;
if (x1 < 0)
nx = true;
else
nx = false;
if (y1 < 0)
ny = true;
else
ny = false;
if (z1 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x1, y1, z1, nx, ny, nz) != null)
return true;
if(x0 < 0)nx = true;else nx = false;
if(y1 < 0)ny = true;else ny = false;
if(z1 < 0)nz = true;else nz = false;
if(world.getBlock(x0, y1, z1,nx,ny,nz) != null) return true;
if (x0 < 0)
nx = true;
else
nx = false;
if (y1 < 0)
ny = true;
else
ny = false;
if (z1 < 0)
nz = true;
else
nz = false;
if (world.getBlock(x0, y1, z1, nx, ny, nz) != null)
return true;
// if(world.getBlock(x0, y0+1, z0) != null) return true;
// if(world.getBlock(x1, y0+1, z0) != null) return true;

View file

@ -8,7 +8,7 @@ public class Game {
private int update = 0;
public Game(){
world= new World(0);
world= new World(0,120,50);
}
public void update(){

View file

@ -1,6 +1,5 @@
package main;
import rendering.*;
import game.*;
import java.util.concurrent.*;
@ -8,9 +7,6 @@ import java.util.concurrent.*;
import org.lwjgl.input.*;
import org.lwjgl.opengl.*;
import rendering.*;
import vanilla.java.affinity.*;
import vanilla.java.affinity.impl.*;
import world.*;
public class Main {
@ -100,10 +96,6 @@ public class Main {
if (elapsedInfo >= 1000) {
LAST_FPS = FPS;
LAST_TICKS = TICKS;
boolean nx = false, ny = false, nz = false;
if(Camera.getPosition().getX() < 0)nx = true;
if(Camera.getPosition().getY() < 0)ny = true;
if(Camera.getPosition().getZ() < 0)nz = true;
Display.setTitle(TITLE + " | FPS:" + (int)(1000000000.0f/timeFps) + " TICKS:"
+ LAST_TICKS + " timeFps:" + timeFps + "ns timeTicks:"
+ timeTicks + "ns" + " | PX:"

View file

@ -22,14 +22,12 @@ public class Chunk {
private boolean IsGenerated = false;
private boolean IsCurrentGenerate = false;
private boolean IsDestroy = false;
private WorldNoise worldNoise;
public Chunk(int x, int y, int z, World world,WorldNoise worldNoise) {
public Chunk(int x, int y, int z, World world) {
this.x = x;
this.y = y;
this.z = z;
this.world = world;
this.worldNoise = worldNoise;
this.blocks = new Block[SIZE][SIZE][SIZE];
vbo = new VBO();
}
@ -298,14 +296,6 @@ public class Chunk {
return IsDestroy;
}
public WorldNoise getWorldNoise() {
return worldNoise;
}
public void setWorldNoise(WorldNoise worldNoise) {
this.worldNoise = worldNoise;
}
}
@ -336,9 +326,9 @@ class Generate implements Runnable {
long current = System.currentTimeMillis();
long elapsed1 = 0;
boolean IsError = true;
Noise noise = new Noise(world.seed, 50, 16);
Noise noise = new Noise(world.seed, world.octave, world.amplitude);;
Random random = new Random(world.seed);
Noise colorVariationNoise = new Noise(world.seed,50,2);
Noise colorVariationNoise = new Noise(world.seed,world.octave,2);
for (int x = 0; x < chunk.SIZE; x++) {
for (int z = 0; z < chunk.SIZE; z++) {
int xa = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - World.VIEW_CHUNK;

View file

@ -5,27 +5,27 @@ import game.*;
import java.util.*;
import main.*;
import math.*;
import blocks.*;
public class World {
public long seed;
public int octave,amplitude;
public final int SIZE = 1,HEIGHT = 1;
public static final float GRAVITY = 1;
public static final int VIEW_CHUNK = 2;
public static WorldNoise worldNoise;
public ArrayList<Chunk> chunks = new ArrayList<Chunk>();
public World(long seed){
public World(long seed,int octave,int amplitude){
this.seed= seed;
this.worldNoise = new WorldNoise(seed);
this.octave = octave;
this.amplitude = amplitude;
for(int x = 0;x < SIZE;x++){
for(int y = 0;y < HEIGHT;y++){
for(int z = 0;z < SIZE;z++){
Chunk ch = new Chunk(x,y,z,this,worldNoise);
Chunk ch = new Chunk(x,y,z,this);
chunks.add(ch);
}
}
@ -47,7 +47,7 @@ public class World {
for(int k = 0;k <= delta_z;k++){
// for(int j = 0; j < HEIGHT; j++){
if(getChunk((xa + i), 0, (za + k)) != null)continue;
Chunk ch = new Chunk((xa + i),0,(za + k),this,worldNoise);
Chunk ch = new Chunk((xa + i),0,(za + k),this);
chunks.add(ch);
// }
}
@ -173,6 +173,46 @@ public class World {
return chunk.getBlock(xb, yb, zb);
}
public long getSeed() {
return seed;
}
public void setSeed(long seed) {
this.seed = seed;
}
public ArrayList<Chunk> getChunks() {
return chunks;
}
public void setChunks(ArrayList<Chunk> chunks) {
this.chunks = chunks;
}
public static long getUpdateWorldTime() {
return updateWorldTime;
}
public static void setUpdateWorldTime(long updateWorldTime) {
World.updateWorldTime = updateWorldTime;
}
public int getSIZE() {
return SIZE;
}
public int getHEIGHT() {
return HEIGHT;
}
public static float getGravity() {
return GRAVITY;
}
public static int getViewChunk() {
return VIEW_CHUNK;
}
}

View file

@ -1,17 +0,0 @@
package world;
import java.util.*;
public class WorldNoise {
public Noise noise;
public Noise colorVariationNoise;
public Random random;
public WorldNoise(long seed){
noise = new Noise(seed, 20, 5);
colorVariationNoise = new Noise(seed, 40, 2);
random = new Random(seed);
}
}