From d24f9296a546949aaa600885b876a9cca7eaf870 Mon Sep 17 00:00:00 2001 From: josua Date: Fri, 13 Mar 2020 22:01:28 +1100 Subject: [PATCH] Redid the games lighting and made it asyncronous. --- resources/texmap.xcf | Bin 231595 -> 231399 bytes settings.bdf | Bin 65 -> 87 bytes src/projectzombie/Main.java | 4 +- src/projectzombie/display/DisplayRender.java | 4 +- .../lighting/ChunkLightingCollection.java | 48 ++++ .../display/lighting/ChunkLightingTemp.java | 49 ++++ ...htingManager.java => DynamicLighting.java} | 65 ++---- .../display/lighting/TileLighting.java | 210 ++++++++++++++++++ src/projectzombie/entity/EntityBullet.java | 4 +- src/projectzombie/entity/EntityVertical.java | 5 +- src/projectzombie/entity/EntityZombie.java | 17 +- .../entity/particle/ParticleBlood.java | 6 +- .../entity/particle/ParticleBreak.java | 10 +- .../entity/particle/ParticleLava.java | 4 +- .../entity/particle/ParticleWater.java | 6 +- .../entity/player/EntityPlayer.java | 2 +- .../mainloop/MainloopHelpers.java | 83 +++++++ .../mainloop/MainloopIterator.java | 6 + src/projectzombie/menu/MenuDeath.java | 6 +- src/projectzombie/tiles/LightLevelNoise.java | 47 ---- src/projectzombie/tiles/Tile.java | 1 + src/projectzombie/tiles/TileBossPortal.java | 14 +- src/projectzombie/tiles/TileFlat.java | 2 +- src/projectzombie/tiles/TileLantern.java | 2 +- src/projectzombie/tiles/TileLava.java | 2 +- src/projectzombie/tiles/TileLavaFlow.java | 2 +- src/projectzombie/tiles/TileVertical.java | 2 +- src/projectzombie/tiles/TileWall.java | 1 + src/projectzombie/util/math/ColorRange.java | 20 ++ src/projectzombie/util/math/MathHelpers.java | 16 +- src/projectzombie/util/math/TileState.java | 5 +- src/projectzombie/world/chunk/Chunk.java | 103 ++++++++- src/projectzombie/world/chunk/ChunkEmpty.java | 39 +++- .../world/chunk/ChunkEventHandler.java | 8 +- src/projectzombie/world/layer/Layer.java | 42 +++- .../world/layer/layergen/LayerGen.java | 3 +- .../layer/layergen/LayerGenBossArena.java | 6 +- .../world/layer/layergen/LayerGenCaves.java | 6 +- .../world/layer/layergen/LayerGenEarth.java | 50 +++-- .../layer/layergen/LayerGenLavaCaves.java | 6 +- 40 files changed, 718 insertions(+), 188 deletions(-) create mode 100644 src/projectzombie/display/lighting/ChunkLightingCollection.java create mode 100644 src/projectzombie/display/lighting/ChunkLightingTemp.java rename src/projectzombie/display/lighting/{LightingManager.java => DynamicLighting.java} (61%) create mode 100644 src/projectzombie/display/lighting/TileLighting.java create mode 100644 src/projectzombie/mainloop/MainloopHelpers.java create mode 100644 src/projectzombie/mainloop/MainloopIterator.java delete mode 100644 src/projectzombie/tiles/LightLevelNoise.java create mode 100644 src/projectzombie/util/math/ColorRange.java diff --git a/resources/texmap.xcf b/resources/texmap.xcf index 2c1165ef9a0e5738ca2da5d96f624339b7f886ad..ff78e06096166ebd49d2b6c3525d9ae57fa7df0c 100644 GIT binary patch delta 2113 zcmZ2Ik?(mw-vlQ{-;K_q%z~*5$bh+(ar#7WX5q~>%#w_Pj$kQfFJCAf36c|?yqkrq z{xevJ!RZ@>4y}XGX~!UR?*a(Ddkuts!3w2C!89ZH4G67%5JJ1$gV1rp5V~j?gkGQt zq0dM_X$=Tn{}!TviGLedfXN8T5AA^P3+6-Uj_VM5=4vRt8$us`1)<-c1JlgX{1DnI z8A7|Ah0=E+w3i{6W?*3W&&ka2fAV2gDZ&3PHXe5VJ}w@;2K&2uxqAd!db{~Kr+7?$%%&&!!`aOy(9zDz-c8Hj$J5uvXR;Ez zzTh7>t7yLlJ`nq{oIhY6g1=#z!OrFD`E%-km(B0M7(Iq(8B*e$f!_R;64GtY) z=Kpu?9Rhr;d;{FvOdZ`E?A)9uOK|E7{<3v;_HYgGFmZSDbn;7Zx11cosVDf~)iEI2 z&&R{j-pR?s#oNkj^K{M{4#EE}jvjXY9xk4s0QPmZ_nWLD1PWj`CwD(D8*k5GPa9`Y z0H+A)2>x;Na0Z2%gPo&)n2U#<_vD2_un=|%cXJO;^YwD_v77u*NKf#eTd=>YkGqGr zrH{L-bBc%CWCdY8!Jn`ob~p3)arSZXog6Q0DEQmWDbYK~E7;4!IKT}Y#0!P>1;6=+ zIy-s0!-CkwZSq55eZfDVAojL%53+S~0|l|$WJM8u!9M}+CT{M2-tLb6Zf@Q#0q&C% zMf3&#+66ngc-gsmI{3TU__(^ePhJR8Yvy9>;Opvc<>VOb6JYP-Ir*UoB#6Cz-ED$` zO+tK~J^TVD%Zh@6_>`+dfSr}Mhnt(JtE;oKyYu8&QD_jm1$dacxqCbLCb(Nqo-3*^ z_}|JaAl%Q>!_nQ-*2Bfy!hiE!(F_j3!{8wHba4j-aiEjE-{dekeZd26Zcgt0;2`$0 zbpi$PG&xg(>|Yw7Fkbek-oU?8~1%hB7_-OfGG+||P=&Nakoa-f2~;GSSF6E|N!Z%;>mFE?+O zAos}=74!vn+Xs8P_&U0IIQhHT1h}}nPrj(2Be>hl#l{&C#9p40`4qJU4+jLgd-%E9 zfl{%btA}6UWG_Ws!GjJC0aivnc5ZH__U=B;ZqAcC6!isng3_>afQPB8yStM|lDoy^ z6N>tR2dq2;Lj62F>|KIwKmi=k%%RlIp~TqEp~SSELy0*=lQ9`oehN=7@Mh+aoDMEe zm|LLbOUp|r|0_t1c>Qt+*JnF~4%rN$@uPJZ7#`g^HU(==w@m2%{QmLET0OzcC#`x5z?iT_|k}rJ;32ODvS13#DtJ zbT5>i3#HdW>Ag@IQtobF=EE#y$+&;|!B%ErNl0bG+X52cHtbUBo+hSK$5x}Lec8O&gAZ->&| zP`V#VPlnRaNN=AFL zv>=4GN`=sF=b`j{2<>GIrWqI*{&O-j{GWW7RZ7ss#>39v$Hl|f-ODY|%|5_=@;g?2 zK{pR4S067MAJ1SfH+S#o0I$hP0QcM)7Qnv zZL$)(zMz{`v|o@{u&0MnfQyg2latrvBz7%9-%w{KpWrYbA3Ga+A6HMesL6BL^##2h zycgT%6-vL)?QW-(}Yq^m8(C3-$AIa`g9f^LBA_kDDyZp(kh?Z0q7};pXY+ z?{4Gc?B;GeIfg@D(9Ff!)z{6#%E3I?FTmc5?7Y1uFA#zTu~WF4dvKbsmy?g3+vEpAdV+4j z{;odm9^RHd?yk-$9&VnK<%JPp>~7}ooz$~*ig{TDbYK~E7;4!IKT}O#tVe? z1^q*voxI&)VeH}-Ir)JwB#gc7+=FbL+(2RM7BpEwL|-t#-Nen^&)eP6-_6b2CBQvq za)OAypk1(&i=zRn(g0Wp(hL_uME($yir&dS@v&CS%+)!EtI*==&PC?t&C0z6FJ+`XNA6WpzB zCeIet7qs#U2>0{!aCG;y^>FdF@VDB0TQmb2#-1+jpfC<}0)=si93+hW!C~xW>jVzt zDRR1kE*{PSF!uJh^LCqjNe&vuZc%RT!KwaUP7Zc%lZE7U1wDfOU47j>d@X&Q zot#rVoLnad$m_$?vAc!8kB6^|huh={^16aI`(jdg|VYs z=wvgijV+y4)8E_b$562NOHHZnS4x9U(m`kAk@#(!`>y> z1{A;n+RbcA?QBYn?QBX++u4+uLo^vvr$>7;OH0lK7beUt(88tVHI)AyRKSYYuY_=Y zc0%Zotq?js5JG3Zh0=c^bQUj^HigozP&yPs=S4&4;*Aix5>gm5S3(M7=1O&_xH*Kb zuXKkns-YItZHDk0Ga+<~Je1al()LgqT2ZvbL;3kox*kgRL+SZYdOeih52Yc6?)D`< z%u<%R2N@Wc7#J8BL2_V%fw>h@?J#$=g9I6vJ0?Tv`JjLkt8Zt8@Y^||G&E$|p{08} zq1-$s4Z)6LD8C#^S3_xN$aXY?_)H88(*xU?gQn}xWU82M rKa+`ryPkuAp`L@`e?14obc2~p +{ + private Map2D chunks = new Map2D(this); + + public final int RENDER_DISTANCE = Chunk.RENDER_DISTANCE; + + @Override + public ChunkLightingTemp getEmpty(Vec2i pos) { + return new ChunkLightingTemp(); + } + + private Vec2i getChunkPosFromPos(Vec2i pos) { + return this.getChunkPosFromPos(new Vec2d(pos.x, pos.y)); + } + + private Vec2i getChunkPosFromPos(Vec2d pos) { + return new Vec2i( + MathHelpers.floor(pos.x / (double)Chunk.CHUNK_SIZE.mx), + MathHelpers.floor(pos.y / (double)Chunk.CHUNK_SIZE.my)); + } + + public ChunkLightingTemp getChunkwCPos(Vec2i cpos) { + if(!chunks.contains(cpos)) { + ChunkLightingTemp chunk = new ChunkLightingTemp(); + chunks.set(cpos, chunk); + return chunk; + } else { + return chunks.get(cpos); + } + } + + public ChunkLightingTemp getChunk(Vec2i pos) { + return getChunkwCPos(getChunkPosFromPos(pos)); + } + + public ChunkLightingTemp getChunk(Vec2d pos) { + return getChunkwCPos(getChunkPosFromPos(pos)); + } +} diff --git a/src/projectzombie/display/lighting/ChunkLightingTemp.java b/src/projectzombie/display/lighting/ChunkLightingTemp.java new file mode 100644 index 0000000..c16a545 --- /dev/null +++ b/src/projectzombie/display/lighting/ChunkLightingTemp.java @@ -0,0 +1,49 @@ +package projectzombie.display.lighting; + +import projectzombie.util.math.vec.Vec2i; +import projectzombie.world.chunk.Chunk; + +public class ChunkLightingTemp +{ + private byte lighting_daylight[] = new byte[Chunk.CHUNK_INDEX]; + private byte lighting_light[] = new byte[Chunk.CHUNK_INDEX]; + + public ChunkLightingTemp() { + for(int i=0;i { + Vec4i upto = Vec4i.fromId(range, it); + + Vec2i cpos = new Vec2i( + upto.x + MathHelpers.floor(player.pos.x / 16) - chunks.RENDER_DISTANCE, + upto.y + MathHelpers.floor(player.pos.y / 16) - chunks.RENDER_DISTANCE); + + Chunk chunk = layer.chunks.get(cpos); + + Vec2i tpos = new Vec2i(cpos.x * 16 + upto.z, cpos.y * 16 + upto.m); + int tid = tpos.getId(Chunk.CHUNK_SIZE); + + TileState tile_f = chunk.getFrontTile(tid); + TileState tile_b = chunk.getBackTile(tid); + + if(tile_f.tile.passNaturalLight && tile_b.tile.passNaturalLight) { + addLightToTiles(chunks, layer, tpos, 0, 1, true); + } + + if(tile_f.tile.emitsLight || tile_b.tile.emitsLight) { + addLightToTiles(chunks, layer, tpos, 0, MathHelpers.biggest( + tile_f.tile.getLightLevel(tile_f, tpos), + tile_b.tile.getLightLevel(tile_b, tpos) + ), false); + } + }, + + () -> { + for(int cx=-chunks.RENDER_DISTANCE;cx<=chunks.RENDER_DISTANCE;cx++) { + for(int cy=-chunks.RENDER_DISTANCE;cy<=chunks.RENDER_DISTANCE;cy++) + { + Vec2i cpos = new Vec2i( + cx + MathHelpers.floor(player.pos.x / 16), + cy + MathHelpers.floor(player.pos.y / 16)); + + Chunk chunk = layer.chunks.get(cpos); + ChunkLightingTemp chunk_t = chunks.getChunkwCPos(cpos); + + for(int x=0;x<16;x++) { + for(int y=0;y<16;y++) + { + Vec2i tpos = new Vec2i(cpos.x * 16 + x, cpos.y * 16 + y); + int tid = tpos.getId(Chunk.CHUNK_SIZE); + + chunk.setDaylightLevel(chunk_t.getDaylightLevel(tid), tid); + chunk.setLightLevel(chunk_t.getLightLevel(tid), tid); + } + } + } + } + }); + } + + private static void addLightToTiles( + ChunkLightingCollection chunks, + Layer layer, Vec2i lpos, + int it, double light, + boolean daylightMode + ) { + if( + MathHelpers.floor(lpos.squareDistance(new Vec2i( + MathHelpers.floor(Main.player.pos.x), + MathHelpers.floor(Main.player.pos.y))) / 16) + > Camera.camera.renderDistance + ) { + return; + } + + if(light <= 0) { + return; + } + + Chunk chunk = layer.getChunk(lpos); + ChunkLightingTemp chunk_t = chunks.getChunk(lpos); + int lid = lpos.getId(Chunk.CHUNK_SIZE); + + // Don't calculate anything on empty chunks + if(chunk == Chunk.CHUNK_EMPTY) { + return; + } + + TileState tile_f = chunk.getFrontTile(lid); + TileState tile_b = chunk.getBackTile(lid); + + // Set the light level + if(daylightMode) { + if(tile_f.tile.passNaturalLight && tile_b.tile.passNaturalLight && it == 1) { + return; + } + if(light <= chunk_t.getDaylightLevel(lid)) return; + chunk_t.setDaylightLevel(light, lid); + } else { + if(light <= chunk_t.getLightLevel(lid)) return; + chunk_t.setLightLevel(light, lid); + } + + // Calculate the dissipation + double dissipation = MathHelpers.biggest( + tile_b.tile.getLightDissipation(tile_b), + tile_f.tile.getLightDissipation(tile_f)); + + // Get all the adjacent positions of the light tiles to flow onto + Vec2i positions[] = { + new Vec2i(lpos.x+1, lpos.y), + new Vec2i(lpos.x-1, lpos.y), + new Vec2i(lpos.x, lpos.y+1), + new Vec2i(lpos.x, lpos.y-1) + }; + + int samechunk = 0; + + for(Vec2i position : positions) { + Vec2i new_cpos = Layer.getChunkPosFromPos(position); + if(new_cpos.equal(chunk.c_pos)) { + samechunk += 1; + } + } + + if(samechunk == 4) { + double neighbour_light = 0; + for(Vec2i position : positions) { + TileState tf = chunk.getFrontTile(position); + TileState tb = chunk.getBackTile(position); + neighbour_light = MathHelpers.smallest(MathHelpers.biggest( + tb.tile.getLightLevel(tb, position), + tf.tile.getLightLevel(tf, position)), + neighbour_light); + } + if(neighbour_light > light) { + return; + } + } + + // Add the light to all the adjacent positions + for(Vec2i position : positions) { + addLightToTiles(chunks, layer, position, it + 1, light - dissipation, daylightMode); + } + } + + @Override + public boolean MainLoopDelay(long millis) { + return millis > 10000; + } + + @Override + public boolean MainLoopRepeat() { + return true; + } + + @Override + public void MainLoopUpdate() { + lighting_dirty = true; + } +} diff --git a/src/projectzombie/entity/EntityBullet.java b/src/projectzombie/entity/EntityBullet.java index 07c30ed..d526a84 100644 --- a/src/projectzombie/entity/EntityBullet.java +++ b/src/projectzombie/entity/EntityBullet.java @@ -148,9 +148,9 @@ public class EntityBullet extends EntityParticle public void render(Vec2d pos, Camera camera) { // Set the colour - double light = chunk.getLightLevel(new Vec2i( + Vec3d light = chunk.getRGBLightLevel(new Vec2i( MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); - GlHelpers.color3(1 * light, 0.8 * light, 0.3 * light); + GlHelpers.color3(1 * light.x, 0.8 * light.y, 0.3 * light.z); // Set the height this.setHeight(height); diff --git a/src/projectzombie/entity/EntityVertical.java b/src/projectzombie/entity/EntityVertical.java index cc1cace..b818e30 100644 --- a/src/projectzombie/entity/EntityVertical.java +++ b/src/projectzombie/entity/EntityVertical.java @@ -7,6 +7,7 @@ import projectzombie.util.gl.texture.TextureReference; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2i; +import projectzombie.util.math.vec.Vec3d; public class EntityVertical extends Entity { @@ -30,9 +31,9 @@ public class EntityVertical extends Entity } public void render(Vec2d pos, Camera camera, double opacity) { - double light = chunk.getLightLevel(new Vec2i( + Vec3d light = chunk.getRGBLightLevel(new Vec2i( MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); - GlHelpers.color4(light, light, light, opacity); + GlHelpers.color4(light.x, light.y, light.z, opacity); this.render(pos, camera, tex, size); GlHelpers.color4(1, 1, 1, 1); } diff --git a/src/projectzombie/entity/EntityZombie.java b/src/projectzombie/entity/EntityZombie.java index 3dc31a3..26e3844 100644 --- a/src/projectzombie/entity/EntityZombie.java +++ b/src/projectzombie/entity/EntityZombie.java @@ -12,6 +12,8 @@ public class EntityZombie extends EntityVertical implements EntityAlive protected OpenSimplexNoise noise_movement; protected OpenSimplexNoise noise_gun_fire; protected OpenSimplexNoise noise_gun_angle; + protected OpenSimplexNoise noise_target_x; + protected OpenSimplexNoise noise_target_y; protected double time; protected double health_max = 100; protected double health = health_max; @@ -23,6 +25,8 @@ public class EntityZombie extends EntityVertical implements EntityAlive noise_movement = new OpenSimplexNoise(rand.nextLong()); noise_gun_fire = new OpenSimplexNoise(rand.nextLong()); noise_gun_angle = new OpenSimplexNoise(rand.nextLong()); + noise_target_x = new OpenSimplexNoise(rand.nextLong()); + noise_target_y = new OpenSimplexNoise(rand.nextLong()); time = 0; // Set some settings @@ -36,12 +40,17 @@ public class EntityZombie extends EntityVertical implements EntityAlive public void tick(Chunk chunk, Layer layer) { super.tick(chunk, layer); + // Get the player targeted area + Vec2d target = new Vec2d( + Main.player.pos.x + noise_target_x.eval(time*5, Main.player.pos.x/10, Main.player.pos.y/10)*10, + Main.player.pos.y + noise_target_y.eval(time*5, Main.player.pos.x/10, Main.player.pos.y/10)*10); + // Get the angle between the player and the zombie - double angle = Math.atan2(pos.x - Main.player.pos.x, pos.y - Main.player.pos.y); + double angle_walk = Math.atan2(pos.x - target.x, pos.y - target.y); + double angle_fire = Math.atan2(pos.x - Main.player.pos.x, pos.y - Main.player.pos.y); // Move forward towards the player - this.angle = Math.toDegrees(angle) + 180; - this.angle += noise_movement.eval(time, 0)*80; + this.angle = Math.toDegrees(angle_walk) + 180; this.moveForward(); if(noise_gun_fire.eval(time, 0) > 0 && !Main.player.dead && !Main.player.in_animation) @@ -52,7 +61,7 @@ public class EntityZombie extends EntityVertical implements EntityAlive if(gun_interval == 0) { // Aim the gun at the player - double angle_gun = Math.toDegrees(angle) + 180; + double angle_gun = Math.toDegrees(angle_fire) + 180; angle_gun += noise_gun_angle.eval(time, 0)*20; // Fire the gun diff --git a/src/projectzombie/entity/particle/ParticleBlood.java b/src/projectzombie/entity/particle/ParticleBlood.java index 99457b8..0ff3edb 100644 --- a/src/projectzombie/entity/particle/ParticleBlood.java +++ b/src/projectzombie/entity/particle/ParticleBlood.java @@ -44,7 +44,7 @@ public class ParticleBlood extends EntityParticle height += velocity.z; velocity.x /= 1.05; velocity.y /= 1.05; - velocity.z -= 0.001; + velocity.z -= MathHelpers.FallSpeed; if(height < 0) { height = 0; velocity.z = 0; @@ -61,12 +61,12 @@ public class ParticleBlood extends EntityParticle public void render(Vec2d pos, Camera camera) { // Get the light level - double light = chunk.getLightLevel(new Vec2i( + Vec3d light = chunk.getRGBLightLevel(new Vec2i( MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); // Set some settings GlHelpers.pushMatrix(); - GlHelpers.color3(r_color * light, 0, 0); + GlHelpers.color3(r_color * light.x, 0, 0); GlHelpers.translate3(0, 0, height); // Call super diff --git a/src/projectzombie/entity/particle/ParticleBreak.java b/src/projectzombie/entity/particle/ParticleBreak.java index 711d7c4..840c755 100644 --- a/src/projectzombie/entity/particle/ParticleBreak.java +++ b/src/projectzombie/entity/particle/ParticleBreak.java @@ -59,10 +59,10 @@ public class ParticleBreak extends EntityVertical time -= 1; height += velocity.z; - velocity.z -= 0.001; + velocity.z -= MathHelpers.FallSpeed; - if(height <= 0) { - velocity.z = 0; + if(height < -1) { + kill(); } else { @@ -73,9 +73,9 @@ public class ParticleBreak extends EntityVertical @Override public void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) { - double light = chunk.getLightLevel(new Vec2i( + Vec3d light = chunk.getRGBLightLevel(new Vec2i( MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); - GlHelpers.color3(light, light, light); + GlHelpers.color3(light.x, light.y, light.z); GlHelpers.pushMatrix(); GlHelpers.translate3(0, 0, height); super.render(pos, camera, tex, size); diff --git a/src/projectzombie/entity/particle/ParticleLava.java b/src/projectzombie/entity/particle/ParticleLava.java index 2b461fa..9c5159f 100644 --- a/src/projectzombie/entity/particle/ParticleLava.java +++ b/src/projectzombie/entity/particle/ParticleLava.java @@ -31,13 +31,13 @@ public class ParticleLava extends EntityParticle super.tick(chunk, layer); // Add the velocity - velocity.z -= 0.0005; + velocity.z -= MathHelpers.FallSpeed; pos.x += velocity.x; pos.y += velocity.y; height += velocity.z; // Is the height below 0; destroy this particle - if(height < 0) { + if(height < -1) { kill(); } } diff --git a/src/projectzombie/entity/particle/ParticleWater.java b/src/projectzombie/entity/particle/ParticleWater.java index cab54f5..cf119c6 100644 --- a/src/projectzombie/entity/particle/ParticleWater.java +++ b/src/projectzombie/entity/particle/ParticleWater.java @@ -29,7 +29,7 @@ public class ParticleWater extends EntityParticle super.tick(chunk, layer); // Add the velocity - velocity.z -= 0.005; + velocity.z -= MathHelpers.FallSpeed; pos.x += velocity.x; pos.y += velocity.y; height += velocity.z; @@ -44,9 +44,9 @@ public class ParticleWater extends EntityParticle public void render(Vec2d pos, Camera camera) { GlHelpers.pushMatrix(); GlHelpers.translate3(0, 0, height); - double light = chunk.getLightLevel(new Vec2i( + Vec3d light = chunk.getRGBLightLevel(new Vec2i( MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); - GlHelpers.color4(0, 0, light, 0.4); + GlHelpers.color4(0, 0, light.z, 0.4); super.render(pos, camera); GlHelpers.color4(1, 1, 1, 1); GlHelpers.popMatrix(); diff --git a/src/projectzombie/entity/player/EntityPlayer.java b/src/projectzombie/entity/player/EntityPlayer.java index 84d4982..62b9585 100644 --- a/src/projectzombie/entity/player/EntityPlayer.java +++ b/src/projectzombie/entity/player/EntityPlayer.java @@ -177,7 +177,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI GlHelpers.translate3(0, 0, height); // Set the colour due to the lighting - double light = chunk.getLightLevel(new Vec2i( + double light = chunk.getDynamicLightLevel(new Vec2i( MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); GlHelpers.color3(light, light, light); diff --git a/src/projectzombie/mainloop/MainloopHelpers.java b/src/projectzombie/mainloop/MainloopHelpers.java new file mode 100644 index 0000000..7a0bbe0 --- /dev/null +++ b/src/projectzombie/mainloop/MainloopHelpers.java @@ -0,0 +1,83 @@ +package projectzombie.mainloop; + +import java.util.ArrayList; + +import mainloop.task.IMainloopTask; + +class AsyncTask +{ + int i, max; + MainloopEnd end; + MainloopIterator iterator; + + AsyncTask(int min, int max, MainloopIterator iterator, MainloopEnd end) { + this.i = min; + this.max = max; + this.end = end; + this.iterator = iterator; + } + + void update() { + long start = System.currentTimeMillis(); + + while(i < max && System.currentTimeMillis() - start < 2) { + iterator.iterate(i); + i += 1; + } + + if(i == max) { + end.end(); + i += 1; + } + } + + boolean done() { + return i > max; + } +} + +public class MainloopHelpers implements IMainloopTask +{ + private static ArrayList tasks = new ArrayList(); + + public static void loopAsync(int min, int max, MainloopIterator iterator, MainloopEnd end) { + tasks.add(new AsyncTask(min, max, iterator, end)); + } + + public static void loopSync(int min, int max, MainloopIterator iterator, MainloopEnd end) { + for(int i=min;i 10; + } + + @Override + public boolean MainLoopRepeat() { + return true; + } + + @Override + public void MainLoopUpdate() + { + long start = System.currentTimeMillis(); + + for(int i=0;i start + 8) { + tasks.remove(0); + } + } +} diff --git a/src/projectzombie/mainloop/MainloopIterator.java b/src/projectzombie/mainloop/MainloopIterator.java new file mode 100644 index 0000000..03657db --- /dev/null +++ b/src/projectzombie/mainloop/MainloopIterator.java @@ -0,0 +1,6 @@ +package projectzombie.mainloop; + +public interface MainloopIterator +{ + public void iterate(int i); +} diff --git a/src/projectzombie/menu/MenuDeath.java b/src/projectzombie/menu/MenuDeath.java index ecc9085..bf7bb2e 100644 --- a/src/projectzombie/menu/MenuDeath.java +++ b/src/projectzombie/menu/MenuDeath.java @@ -1,6 +1,7 @@ package projectzombie.menu; import projectzombie.input.types.InputGUI; +import projectzombie.menu.gui.ButtonGroup; import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.components.ButtonGroupPause; import projectzombie.menu.gui.components.LabelPause; @@ -20,7 +21,10 @@ public class MenuDeath extends Menu gui.add(new OverlayBackground()); gui.add(new LabelPause("You Died!")); - gui.add(new ButtonGroupPause()); + + ButtonGroup group = new ButtonGroupPause(); + gui.setSelected(group.get(0)); + gui.add(group); } @Override diff --git a/src/projectzombie/tiles/LightLevelNoise.java b/src/projectzombie/tiles/LightLevelNoise.java deleted file mode 100644 index 4644453..0000000 --- a/src/projectzombie/tiles/LightLevelNoise.java +++ /dev/null @@ -1,47 +0,0 @@ -package projectzombie.tiles; - -import java.util.Random; - -import mainloop.task.IMainloopTask; -import projectzombie.time.GameTimer; -import projectzombie.util.math.MathHelpers; -import projectzombie.util.math.random.OpenSimplexNoise; - -public class LightLevelNoise implements IMainloopTask -{ - private static final Random rand = new Random(); - private static final OpenSimplexNoise lava_noise_g = new OpenSimplexNoise(rand.nextLong()); - private static final OpenSimplexNoise lantern_noise_g = new OpenSimplexNoise(rand.nextLong()); - - private static double lava_noise = 0; - private static double lantern_noise = 0; - - static double getLightLevel(OpenSimplexNoise noise) { - return noise.eval(GameTimer.getTime() / 50.0, 0); - } - - static double getLavaLightLevel() { - return lava_noise; - } - - static double getLanternLightLevel() { - return lantern_noise; - } - - @Override - public boolean MainLoopDelay(long millis) { - return millis > 10; - } - - @Override - public boolean MainLoopRepeat() { - return true; - } - - @Override - public void MainLoopUpdate() - { - lava_noise = MathHelpers.map(getLightLevel(lava_noise_g), -1, 1, 0.6, 0.8); - lantern_noise = MathHelpers.map(getLightLevel(lantern_noise_g), -1, 1, 0.6, 1); - } -} diff --git a/src/projectzombie/tiles/Tile.java b/src/projectzombie/tiles/Tile.java index 74959e8..c4ea391 100644 --- a/src/projectzombie/tiles/Tile.java +++ b/src/projectzombie/tiles/Tile.java @@ -21,6 +21,7 @@ public class Tile implements ITransparentObject public boolean unbreakable = false; protected double light_dissipation = 1/8.0; public boolean emitsLight = true; + public boolean passNaturalLight = true; public Tile(String id) { this.id = id; diff --git a/src/projectzombie/tiles/TileBossPortal.java b/src/projectzombie/tiles/TileBossPortal.java index 2fba033..d3135b0 100644 --- a/src/projectzombie/tiles/TileBossPortal.java +++ b/src/projectzombie/tiles/TileBossPortal.java @@ -8,6 +8,7 @@ import projectzombie.entity.Entity; import projectzombie.entity.particle.ParticleBreak; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Textures; +import projectzombie.util.math.MathHelpers; import projectzombie.util.math.TileState; import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2i; @@ -42,7 +43,7 @@ public class TileBossPortal extends TileVertical { // Get the player and set some player variables EntityPlayer ep = (EntityPlayer)entity; - ep.height = 8; + ep.height = 5; // Create the boss arena LayerGenBossArena layergen = new LayerGenBossArena(); @@ -55,6 +56,7 @@ public class TileBossPortal extends TileVertical Main.mainloop.register(new IMainloopTask() { int stage = 0; + double velocity = 0; @Override public void MainLoopUpdate() @@ -64,9 +66,13 @@ public class TileBossPortal extends TileVertical // Only do this if the world is loaded if(ChunkEventHandler.loaded) { - ep.height -= 0.05; + this.velocity -= MathHelpers.FallSpeed; + ep.height += this.velocity; if(ep.height <= 0) { - ep.height = 0; + this.velocity *= -0.6; + if(this.velocity <= 0.001) { + ep.height = 0; + } } } } @@ -74,7 +80,7 @@ public class TileBossPortal extends TileVertical @Override public boolean MainLoopRepeat() { - return ep.height > 0; + return ep.height > 0 || this.velocity > 0.001; } @Override diff --git a/src/projectzombie/tiles/TileFlat.java b/src/projectzombie/tiles/TileFlat.java index fd102d9..2a73589 100644 --- a/src/projectzombie/tiles/TileFlat.java +++ b/src/projectzombie/tiles/TileFlat.java @@ -25,7 +25,7 @@ public class TileFlat extends Tile implements IHasTexture super.render(pos, camera, state); // Render the tile - GlHelpers.color3(state.light * color.x, state.light * color.y, state.light * color.z); + GlHelpers.color3(state.light.x * color.x, state.light.y * color.y, state.light.z * color.z); GlHelpers.begin(); tex.texCoord(1, 1); GlHelpers.vertex3(pos.x+0, pos.y+0, 0); tex.texCoord(0, 1); GlHelpers.vertex3(pos.x+1, pos.y+0, 0); diff --git a/src/projectzombie/tiles/TileLantern.java b/src/projectzombie/tiles/TileLantern.java index d312806..defb996 100644 --- a/src/projectzombie/tiles/TileLantern.java +++ b/src/projectzombie/tiles/TileLantern.java @@ -22,7 +22,7 @@ public class TileLantern extends TileVertical @Override public double getLightLevel(TileState state, Vec2i pos) { - return LightLevelNoise.getLanternLightLevel(); + return 0.8; } @Override diff --git a/src/projectzombie/tiles/TileLava.java b/src/projectzombie/tiles/TileLava.java index 9e200df..ed53275 100644 --- a/src/projectzombie/tiles/TileLava.java +++ b/src/projectzombie/tiles/TileLava.java @@ -34,7 +34,7 @@ public class TileLava extends TileFlat @Override public double getLightLevel(TileState state, Vec2i pos) { - return LightLevelNoise.getLavaLightLevel(); + return 0.8; } @Override diff --git a/src/projectzombie/tiles/TileLavaFlow.java b/src/projectzombie/tiles/TileLavaFlow.java index 9d529dd..0108f2a 100644 --- a/src/projectzombie/tiles/TileLavaFlow.java +++ b/src/projectzombie/tiles/TileLavaFlow.java @@ -33,7 +33,7 @@ public class TileLavaFlow extends TileFlat @Override public double getLightLevel(TileState state, Vec2i pos) { - return LightLevelNoise.getLavaLightLevel(); + return 0.6; } @Override diff --git a/src/projectzombie/tiles/TileVertical.java b/src/projectzombie/tiles/TileVertical.java index a8a2630..0051ce3 100644 --- a/src/projectzombie/tiles/TileVertical.java +++ b/src/projectzombie/tiles/TileVertical.java @@ -24,7 +24,7 @@ public class TileVertical extends Tile implements IHasTexture @Override public void render(Vec2d pos, Camera camera, TileState state) { super.render(pos, camera, state); - GlHelpers.color3(state.light, state.light, state.light); + GlHelpers.color3(state.light.x, state.light.y, state.light.z); VerticalRender.render(pos, camera, tex, size); } diff --git a/src/projectzombie/tiles/TileWall.java b/src/projectzombie/tiles/TileWall.java index f41ce2e..eda5c48 100644 --- a/src/projectzombie/tiles/TileWall.java +++ b/src/projectzombie/tiles/TileWall.java @@ -13,6 +13,7 @@ public class TileWall extends TileFlat this.tileHitbox = 1; this.light_dissipation = 1/2.0; + this.passNaturalLight = false; } } diff --git a/src/projectzombie/util/math/ColorRange.java b/src/projectzombie/util/math/ColorRange.java new file mode 100644 index 0000000..4bb4f8b --- /dev/null +++ b/src/projectzombie/util/math/ColorRange.java @@ -0,0 +1,20 @@ +package projectzombie.util.math; + +import projectzombie.util.math.vec.Vec3d; + +public class ColorRange +{ + Vec3d colorMin, colorMax; + + public ColorRange(Vec3d colorMin, Vec3d colorMax) { + this.colorMin = colorMin; + this.colorMax = colorMax; + } + + public Vec3d getColor(double v) { + return new Vec3d( + MathHelpers.map(v, 0, 1, colorMin.x, colorMax.x), + MathHelpers.map(v, 0, 1, colorMin.y, colorMax.y), + MathHelpers.map(v, 0, 1, colorMin.z, colorMax.z)); + } +} diff --git a/src/projectzombie/util/math/MathHelpers.java b/src/projectzombie/util/math/MathHelpers.java index ea9a441..2801b2d 100644 --- a/src/projectzombie/util/math/MathHelpers.java +++ b/src/projectzombie/util/math/MathHelpers.java @@ -5,6 +5,8 @@ import projectzombie.util.math.vec.Vec3d; public class MathHelpers { + public static final double FallSpeed = 0.00098; + public static double squared(double x) { return x*x; } @@ -33,7 +35,7 @@ public class MathHelpers } public static Vec2d moveTowards2(double amount, double angle) { - return new Vec2d(Math.sin(angle)*amount, Math.cos(angle)*amount); + return new Vec2d(Math.sin(angle) * amount, Math.cos(angle) * amount); } public static Vec3d moveTowards3(double amount, Vec2d angles) @@ -84,18 +86,6 @@ public class MathHelpers else return a; } - /* - - def rotate(point, angle): - angle = angle * (math.pi/180) - s = math.sin(angle) - c = math.cos(angle) - x = point[0] * c - point[1] * s - y = point[0] * s + point[1] * c - return [x, y] - - */ - public static Vec2d rotate2(Vec2d pos, double angle) { // Calculate 2 sin and cos values diff --git a/src/projectzombie/util/math/TileState.java b/src/projectzombie/util/math/TileState.java index eb5ff89..1035af1 100644 --- a/src/projectzombie/util/math/TileState.java +++ b/src/projectzombie/util/math/TileState.java @@ -2,6 +2,7 @@ package projectzombie.util.math; import projectzombie.init.Tiles; import projectzombie.tiles.Tile; +import projectzombie.util.math.vec.Vec3d; public class TileState { @@ -9,7 +10,7 @@ public class TileState public Tile tile; public byte meta; - public double light = 0; + public Vec3d light; public TileState(Tile tile, byte meta) { this.tile = tile; @@ -20,7 +21,7 @@ public class TileState this(tile, (byte)meta); } - public TileState withLightLevel(double level) { + public TileState withLightLevel(Vec3d level) { TileState ts = new TileState(tile, meta); ts.light = level; return ts; diff --git a/src/projectzombie/world/chunk/Chunk.java b/src/projectzombie/world/chunk/Chunk.java index 40e1370..c91af08 100644 --- a/src/projectzombie/world/chunk/Chunk.java +++ b/src/projectzombie/world/chunk/Chunk.java @@ -15,6 +15,7 @@ import projectzombie.util.math.random.RandomHelpers; import projectzombie.util.math.range.Range2i; import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2i; +import projectzombie.util.math.vec.Vec3d; import projectzombie.world.layer.Layer; public class Chunk @@ -32,10 +33,13 @@ public class Chunk private byte tiles_front_meta[] = new byte[CHUNK_INDEX]; private byte tiles_back_meta[] = new byte[CHUNK_INDEX]; private byte tiles_lighting[] = new byte[CHUNK_INDEX]; + private byte tiles_lighting_dynamic[] = new byte[CHUNK_INDEX]; + private byte tiles_lighting_daylight[] = new byte[CHUNK_INDEX]; public ArrayList entities = new ArrayList(); private Layer layer; - private Vec2i c_pos; + public Vec2i c_pos; public boolean dirty; + public boolean light_dirty; public Chunk(Layer layer, Vec2i c_pos, Random rand) { @@ -43,6 +47,7 @@ public class Chunk this.layer = layer; this.c_pos = c_pos; this.dirty = false; + this.light_dirty = true; // Loop over all the tiles in the chunk for(int i=0;i light.x) light.x = light_level; + if(light_level > light.y) light.y = light_level; + if(light_level > light.z) light.z = light_level; + + return light; + } + public void breakBackTile(Vec2i pos) { TileState ts = getBackTile(pos); + this.light_dirty = true; this.dirty = true; if(!ts.tile.unbreakable) { setBackTile(layer.layergen.getTileDestroyed(), pos); - for(int i=0;i<20;i++) { + for(int i=0;i<100;i++) { spawnEntity(new ParticleBreak(new Vec2d(pos.x+0.5, pos.y+0.5), ts)); } } @@ -226,11 +252,12 @@ public class Chunk public void breakFrontTile(Vec2i pos) { TileState ts = getFrontTile(pos); + this.light_dirty = true; this.dirty = true; if(!ts.tile.unbreakable) { setFrontTile(Tiles.VOID.getDefaultState(), pos); - for(int i=0;i<20;i++) { + for(int i=0;i<100;i++) { spawnEntity(new ParticleBreak(new Vec2d(pos.x+0.5, pos.y+0.5), ts)); } } @@ -251,6 +278,21 @@ public class Chunk return getLightLevel(id); } + public double getDaylightLevel(int id) { + return tiles_lighting_daylight[id] / (double)Byte.MAX_VALUE; + } + + public double getDaylightLevel(Vec2i pos) + { + // Get the id + Vec2i cpos = new Vec2i(0, 0); + cpos.x = MathHelpers.mod(pos.x, CHUNK_SIZE.mx); + cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my); + int id = cpos.getId(CHUNK_SIZE); + + return getDaylightLevel(id); + } + public void setLightLevel(double light, int id) { this.tiles_lighting[id] = (byte)(light * Byte.MAX_VALUE); } @@ -266,6 +308,51 @@ public class Chunk setLightLevel(light, id); } + public void setDaylightLevel(double light, int id) { + this.tiles_lighting_daylight[id] = (byte)(light * Byte.MAX_VALUE); + } + + public void setDaylightLevel(double light, Vec2i pos) + { + // Get the id + Vec2i cpos = new Vec2i(0, 0); + cpos.x = MathHelpers.mod(pos.x, CHUNK_SIZE.mx); + cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my); + int id = cpos.getId(CHUNK_SIZE); + + setDaylightLevel(light, id); + } + + public double getDynamicLightLevel(int id) { + return tiles_lighting_dynamic[id] / (double)Byte.MAX_VALUE; + } + + public double getDynamicLightLevel(Vec2i pos) + { + // Get the id + Vec2i cpos = new Vec2i(0, 0); + cpos.x = MathHelpers.mod(pos.x, CHUNK_SIZE.mx); + cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my); + int id = cpos.getId(CHUNK_SIZE); + + return getDynamicLightLevel(id); + } + + public void setDynamicLightLevel(double light, int id) { + this.tiles_lighting_dynamic[id] = (byte)(light * Byte.MAX_VALUE); + } + + public void setDynamicLightLevel(double light, Vec2i pos) + { + // Get the id + Vec2i cpos = new Vec2i(0, 0); + cpos.x = MathHelpers.mod(pos.x, CHUNK_SIZE.mx); + cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my); + int id = cpos.getId(CHUNK_SIZE); + + setDynamicLightLevel(light, id); + } + public void killEntity(Entity e) { entities.remove(e); } diff --git a/src/projectzombie/world/chunk/ChunkEmpty.java b/src/projectzombie/world/chunk/ChunkEmpty.java index 12f474e..1a759e5 100644 --- a/src/projectzombie/world/chunk/ChunkEmpty.java +++ b/src/projectzombie/world/chunk/ChunkEmpty.java @@ -10,8 +10,6 @@ import projectzombie.util.math.vec.Vec2i; public class ChunkEmpty extends Chunk { - - public ChunkEmpty() { super(null, null, null); } @@ -97,6 +95,43 @@ public class ChunkEmpty extends Chunk public void setFrontTile(TileState tile, int id) { } + @Override + public double getDynamicLightLevel(int id) { + return 0; + } + @Override + public double getDynamicLightLevel(Vec2i pos) { + return 0; + } + @Override + public void setDynamicLightLevel(double light, int id) { + } + + @Override + public void setDynamicLightLevel(double light, Vec2i pos) { + } + + @Override + public void tickRandomly() { + } + + @Override + public double getDaylightLevel(int id) { + return 0; + } + + @Override + public double getDaylightLevel(Vec2i pos) { + return 0; + } + + @Override + public void setDaylightLevel(double light, int id) { + } + + @Override + public void setDaylightLevel(double light, Vec2i pos) { + } } diff --git a/src/projectzombie/world/chunk/ChunkEventHandler.java b/src/projectzombie/world/chunk/ChunkEventHandler.java index 0132d55..dcc7d07 100644 --- a/src/projectzombie/world/chunk/ChunkEventHandler.java +++ b/src/projectzombie/world/chunk/ChunkEventHandler.java @@ -2,6 +2,8 @@ package projectzombie.world.chunk; import mainloop.task.IMainloopTask; import projectzombie.Main; +import projectzombie.display.lighting.TileLighting; +import projectzombie.util.math.MathHelpers; import projectzombie.util.math.map.Map2DElement; import projectzombie.util.math.vec.Vec2i; import projectzombie.world.layer.Layer; @@ -52,8 +54,8 @@ public class ChunkEventHandler implements IMainloopTask for(int y=-Chunk.SIMULATION_DISTANCE;y public abstract void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i pos); public abstract void spawnEntities(Layer layer, Random rand); public abstract TileState getTileDestroyed(); - public abstract double getLightLevel(); + public abstract ColorRange getLightLevel(); @Override public Chunk getEmpty(Vec2i pos) { diff --git a/src/projectzombie/world/layer/layergen/LayerGenBossArena.java b/src/projectzombie/world/layer/layergen/LayerGenBossArena.java index d9b85eb..85a1b29 100644 --- a/src/projectzombie/world/layer/layergen/LayerGenBossArena.java +++ b/src/projectzombie/world/layer/layergen/LayerGenBossArena.java @@ -5,11 +5,13 @@ import java.util.Random; import projectzombie.entity.EntityBoss; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Tiles; +import projectzombie.util.math.ColorRange; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.TileState; import projectzombie.util.math.random.RandomHelpers; import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2i; +import projectzombie.util.math.vec.Vec3d; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; @@ -92,8 +94,8 @@ public class LayerGenBossArena extends LayerGen implements LayerGenRememberPlaye } @Override - public double getLightLevel() { - return 0; + public ColorRange getLightLevel() { + return new ColorRange(new Vec3d(0, 0, 0), new Vec3d(0.08, 0.04, 0.02)); } @Override diff --git a/src/projectzombie/world/layer/layergen/LayerGenCaves.java b/src/projectzombie/world/layer/layergen/LayerGenCaves.java index 66e8ffd..cd04c4a 100644 --- a/src/projectzombie/world/layer/layergen/LayerGenCaves.java +++ b/src/projectzombie/world/layer/layergen/LayerGenCaves.java @@ -6,12 +6,14 @@ import projectzombie.Main; import projectzombie.entity.Entity; import projectzombie.entity.EntityZombie; import projectzombie.init.Tiles; +import projectzombie.util.math.ColorRange; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.TileState; import projectzombie.util.math.random.OpenSimplexNoise; import projectzombie.util.math.random.RandomHelpers; import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2i; +import projectzombie.util.math.vec.Vec3d; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; @@ -101,8 +103,8 @@ public class LayerGenCaves extends LayerGen } @Override - public double getLightLevel() { - return 0; + public ColorRange getLightLevel() { + return new ColorRange(new Vec3d(0, 0, 0), new Vec3d(0, 0, 0)); } } diff --git a/src/projectzombie/world/layer/layergen/LayerGenEarth.java b/src/projectzombie/world/layer/layergen/LayerGenEarth.java index b9b21b5..1189340 100644 --- a/src/projectzombie/world/layer/layergen/LayerGenEarth.java +++ b/src/projectzombie/world/layer/layergen/LayerGenEarth.java @@ -7,12 +7,13 @@ import projectzombie.entity.Entity; import projectzombie.entity.EntityZombie; import projectzombie.init.Tiles; import projectzombie.time.GameTimer; -import projectzombie.util.math.MathHelpers; +import projectzombie.util.math.ColorRange; import projectzombie.util.math.TileState; import projectzombie.util.math.random.OpenSimplexNoise; import projectzombie.util.math.random.RandomHelpers; import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2i; +import projectzombie.util.math.vec.Vec3d; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; @@ -30,7 +31,9 @@ public class LayerGenEarth extends LayerGen RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my)); // Get the noise generator - OpenSimplexNoise noisegen_n = new OpenSimplexNoise(new Random(seed + layer.id).nextLong()); + Random rand_seed = new Random(seed + layer.id); + OpenSimplexNoise noisegen_n = new OpenSimplexNoise(rand_seed.nextLong()); + OpenSimplexNoise noisegen_b = new OpenSimplexNoise(rand_seed.nextLong()); // Loop over the layer dimensions and create land for(int x=0;x 0.9) chunk.setFrontTile(new TileState(Tiles.TREE, - (short)RandomHelpers.randrange(rand, Short.MAX_VALUE)), pos); - else if(rand.nextDouble() > 0.99) chunk.setFrontTile(new TileState(Tiles.ROCK, - (short)RandomHelpers.randrange(rand, Short.MAX_VALUE)), pos); - else chunk.setFrontTile(Tiles.VOID.getDefaultState(), pos); - // Terrain generation - if(noise_n < 40) { + if(noise_n < 40 + noise_b1 * 10) { chunk.setFrontTile(Tiles.WATER.getDefaultState(), pos); chunk.setBackTile(Tiles.DIRT.getDefaultState(), pos); } - else if(noise_n < 70) chunk.setBackTile(Tiles.GRASS.getDefaultState(), pos); - else if(noise_n < 90) chunk.setBackTile(Tiles.DIRT.getDefaultState(), pos); - else chunk.setBackTile(Tiles.STONE.getDefaultState(), pos); + else if(noise_n < 70 - noise_b2 * 10) chunk.setBackTile(Tiles.GRASS.getDefaultState(), pos); + else if(noise_n < 85 - noise_b3 * 10) chunk.setBackTile(Tiles.DIRT.getDefaultState(), pos); + else chunk.setBackTile(Tiles.WALL.getDefaultState(), pos); + + // Tree and rock generation + if(!chunk.getBackTile(pos).tile.tileSolid) { + if(rand.nextDouble() > 0.9) chunk.setFrontTile(new TileState(Tiles.TREE, + (short)RandomHelpers.randrange(rand, Short.MAX_VALUE)), pos); + else if(rand.nextDouble() > 0.99) chunk.setFrontTile(new TileState(Tiles.ROCK, + (short)RandomHelpers.randrange(rand, Short.MAX_VALUE)), pos); + else chunk.setFrontTile(Tiles.VOID.getDefaultState(), pos); + } } } @@ -89,9 +98,14 @@ public class LayerGenEarth extends LayerGen } @Override - public double getLightLevel() { - return MathHelpers.map( - Math.sin(GameTimer.getTime() / 7200) - , -1, 1, 0, 0.8); + public ColorRange getLightLevel() + { + double light = Math.sin(GameTimer.getTime() / 7200.0); + + ColorRange daylightRange = new ColorRange( + new Vec3d(60/255.0, 74/255.0, 68/255.0), + new Vec3d(205/255.0, 191/255.0, 162/255.0)); + + return new ColorRange(new Vec3d(0, 0, 0), daylightRange.getColor(light)); } } diff --git a/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java b/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java index f9759ca..8615619 100644 --- a/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java +++ b/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java @@ -6,11 +6,13 @@ import projectzombie.Main; import projectzombie.entity.Entity; import projectzombie.entity.EntityZombieArmored; import projectzombie.init.Tiles; +import projectzombie.util.math.ColorRange; import projectzombie.util.math.TileState; import projectzombie.util.math.random.OpenSimplexNoise; import projectzombie.util.math.random.RandomHelpers; import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2i; +import projectzombie.util.math.vec.Vec3d; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; @@ -142,8 +144,8 @@ public class LayerGenLavaCaves extends LayerGen } @Override - public double getLightLevel() { - return 0.1; + public ColorRange getLightLevel() { + return new ColorRange(new Vec3d(0, 0, 0), new Vec3d(0.06, 0, 0)); } }